Content
Content Agent — Xiaohongshu AI Content Assistant
A Xiaohongshu content mining and automatic generation system built with FastAPI, LangChain, and OpenAI. Supports a complete closed loop from crawling competitor data, analyzing popular content patterns, AI-generated content and images, to publishing with one click on Xiaohongshu.
## Tool List
| Module | Description |
|------|------|
| Data Crawling | Crawl Xiaohongshu search results using Playwright, supporting filtering by keywords, comments, likes, and collections, and automatically skipping videos and ads |
| Data Analysis | Extract high-frequency keywords, popular tags,, and user insights output structured analysis reports Topic Generation | Based on analysis results, call LLM to generate several high-quality topic suggestions (including titles) |
| Content Generation | Generate multiple complete texts for each topic: title, topic tags, interactive image suggestions, and content type Image Generation | Call OpenAI-image-1` to that fit Xiaohongshu and save them locally |
| | Support MCP protocol (recommended REST API to publish content toongshu |
| Feishu Sync | Synchronize crawled data-generated content to Feishu multi-dimensional tables for team collaboration and review |
Server | Encapsulate the complete pipeline as an MCP tool, directly called in AI tools like Claude Desktop/Cursor |
| Web-in static front-end, graphical operation interface for crawling, and publishing |
## Getting### 1. Install Dependenciesbash
python -m venv
.venv\Scripts\ Windows
pip install -.txt
playwright install chromium
```
###. Configure
Copy the `.env` file and fill in the necessary fields:
```env
# OpenAI
_API_KEY=sk-...
_MODEL=gpt-4o-mini
OPENAI_BASE_URL= # Optional, proxy address
# Image Generation
IMAGE_MODEL=gpt-image-1
# Fe-Dimensional Table (Optional)
U_APP_ID=
FEISHU_APP_SECRET=
FEISHU=
FEISHU= # Crawler data tableISHU_PUBLISH_TABLE # AI-generated note table
# Xiaohong Service (Local)
XCP_URL=http://localhost:18060
XHS_MCP_ENDPOINT=http://localhost:18060
```
### Start the Service
```bash
uvicorn app.main:app --reload --host 127.0.0.1 --port 8000
```
Access `http://127.0.0.1:8000` in your browser to enter the Web UI.
FastAPI interactive documentation: `http://127.0.0.1:8000/docs`
## Main API Route | Description------|------|
POST /analysis` | Analyze note return keywords, tags, title patterns, and insights |
POST /topics/generate Generate topic suggestions based on |
| `content/generate Generate text and based on| `POST /agent/run` | Run the complete content generation pipeline (analysis → topic → content) with |
| `POST /crawl/search` | Crawl Xiaohongshu text notes by keyword |
| /publish/prepare` | Assemble publish payload (REST/M) |
| `POST /publish/send Publish to Xiaohongshu |
| `POST //sync` | Synchronize generated content to Feishu |
| `POST /feishu/sync-craw | Synchronize crawled data to Fe| /health` | Health check |
## Using MCP Server
Encapsulate this project as an MCP Server, which can be registered and used in AI tools that support the MCP protocol (Claude Desktop, Cursor, etc.).
python mcp_server.py
```
Provide the following MCP| Tool | Description |
|------|------|
| `run_content_pipeline` | Run the generation pipeline |
| `generate_xhs_images` | based on| `_xhs` | Generate images and publish to Xiaohongshu with one click |
| `check_xhs_login` Xiaohongshu |
## Project Structure
```
xhs_content_agent/
├── app/
│ ├── api/ # FastAPI routing layer
│ ├── core # Configuration (Settings)
│ models/ # P data models
├── prompts/ LLM Prompt templates
└── services/ # Business logic layer
│ agent_service.py # Main pipeline orchest│ ├── analysis_service.py data analysis
│ ├── topic_service.py # Topic generation
│ content_service.py # Content generation
│ ├── image_service.py Image generation
│ publish_service.py Xiaohong
│ ├── feishu_service.py # Feishu synchronization ├── localrawler_service.py # Xiaohongshu crawler
│ └── mcp_client_service.py # MCP client
├── static/ # Web front-end pages
├── data/
│ ├── raw/ # Crawled data/sample data
│ └── output/images # Generated images
├── mcp_server.py Server entry
.txt
.env # Environment variable configuration
Technology Stack
Backend Framework**: FastAPI + Uvicorn **LLM Call**: LangChain +-OpenAI (GPT-4o-mini **Image Generation**: OpenAI gpt-image-1
- **Crawler**: Playwrightromium)
- **MCP Protocol**: `mcp` SDK (FastMCP)
- **Feishu API**: Feishu Multi-Dimensional Table Open API
- **Chinese Processing**: word segmentation
- **Data Validation**: Pydantic v2
## Precautions
- The crawling function needs to complete Xiaoh login in advance and save Cookies to `data/raw/xhs_cookies.json`.
- The publishing function relies on the local Xiaohongshu MCP service (default port `18060`), which requires completing the scan code login.
- Image generation requires an OpenAI API Key with `gpt-image-1` access permissions.
- Feishu synchronization is an optional If not configured, related interfaces will return prompt information without errors.
MCP Config
Below is the configuration for this MCP Server. You can copy it directly to Cursor or other MCP clients.
mcp.json
Connection Info
You Might Also Like
markitdown
Python tool for converting files and office documents to Markdown.
OpenAI Whisper
OpenAI Whisper MCP Server - 基于本地 Whisper CLI 的离线语音识别与翻译,无需 API Key,支持...
oh-my-opencode
Background agents · Curated agents like oracle, librarians, frontend...
claude-flow
Claude-Flow v2.7.0 is an enterprise AI orchestration platform.
chatbox
User-friendly Desktop Client App for AI Models/LLMs (GPT, Claude, Gemini, Ollama...)
ai-engineering-from-scratch
Learn it. Build it. Ship it for others. The most comprehensive open-source...