Content
# MCP Server
An automation server for Xiaohongshu based on Model Context Protocol (MCP) and Selenium web automation technology. It provides functionalities such as searching articles, viewing content, reading comments, and posting comments. This server can assist with tasks like Xiaohongshu traffic diversion, popular article analysis, and comment sentiment analysis.
## Features
- 🔐 **Auto Login Management**: Persistent session storage to save login state
- 🔍 **Article Search**: Search for articles by keyword
- 📖 **Content Viewing**: Read article content and comments
- 💬 **Comment Interaction**: Post comments under articles
- 🗂️ **Session Persistence**: Automatically save and load login state
- 🌐 **Web Automation**: Based on Selenium browser automation
## Future Development Plans
- Implement note sending functionality
- Implement note collection and liking functionality
- Implement follow functionality
## Environment Requirements
- Python 3.8+
- Chrome browser
- ChromeDriver
## Installation Steps
1. **Clone the Project**:
```bash
git clone git@github.com:cjpnice/xiaohongshu_mcp.git
```
2. **Download and Unzip ChromeDriver**:
- Download the ChromeDriver corresponding to your Chrome version from the [official website](https://chromedriver.chromium.org/)
- Unzip it to the project root directory
3. **Install Python Environment**:
- Create a virtual environment, recommended to use uv for management, and install dependencies
```bash
cd xiaohongshu_mcp
uv python pin 3.12
uv init --bare
uv venv
.venv\Scripts\activate # Windows activation method
source .venv/bin/activate # MacOS/Linux activation method
uv pip install -r requirements.txt
```
## Usage Instructions
### MCP Server Configuration
Set `CHROME_DRIVER_PATH` to the location of the ChromeDriver executable
```json
{
"mcpServers": {
"xiaohongshu_mcp": {
"command": "uv",
"args": [
"--directory",
"/PATH/TO/PARENT/FOLDER/xiaohongshu_mcp",
"run",
"mcp_server.py"
],
"env": {
"CHROME_DRIVER_PATH": "/PATH/TO/PARENT/FOLDER/chromedriver/chromedriver.exe"
}
}
}
}
```
The server uses the stdio transport protocol by default.
### Available Tools
#### 1. **login()**
Initiate the Xiaohongshu manual login process. Open the browser and wait for the user to complete the login.
**Return Value:**
- `success`: Boolean indicating whether the login was successful
- `message`: Status message
#### 2. **search_articles(keyword: str)**
Search for articles by keyword.
**Parameters:**
- `keyword`: Search keyword
**Return Value:**
- `success`: Boolean indicating whether the operation was successful
- `keyword`: Used search keyword
- `articles`: List of article objects, containing:
- `title`: Article title
- `author`: Author name
- `link`: Article link
- `like`: Number of likes
- `count`: Number of articles found
#### 3. **get_current_page_articles()**
Get the list of articles on the current page. Can be used in conjunction with the page scrolling function.
**Return Value:**
- Same format as `search_articles`
#### 4. **get_article_content(article_url: str)**
Get the content of a specified article.
**Parameters:**
- `article_url`: Article link
**Return Value:**
- `success`: Boolean indicating whether the operation was successful
- `content`: Article text content
#### 5. **view_article_comments(article_url: str, limit: int = 20)**
Get the list of comments for an article.
**Parameters:**
- `article_url`: Article link
- `limit`: Maximum number of comments to retrieve (default: 20)
**Return Value:**
- `success`: Boolean indicating whether the operation was successful
- `article_url`: Article link
- `comments`: List of comment objects, containing:
- `username`: Commenter's username
- `content`: Comment content
- `count`: Number of comments retrieved
#### 6. **post_comment(article_url: str, comment_text: str)**
Post a comment under an article.
**Parameters:**
- `article_url`: Article link
- `comment_text`: Comment content
**Return Value:**
- `success`: Boolean indicating whether the operation was successful
- `message`: Status message
- `comment`: Posted comment content
#### 7. **scroll()**
Scroll the current page to load more content.
**Return Value:**
- `success`: Boolean indicating whether the operation was successful
- `message`: Status message
#### 8. **close_browser()**
Close the browser instance.
**Return Value:**
- `success`: Boolean indicating whether the operation was successful
- `message`: Status message
## Important Reminders
1. **Manual Login Required**: The first time the server is run, manual login is required in the opened browser window.
2. **Frequency Limit Awareness**: Be aware of Xiaohongshu's frequency limits, and include reasonable delays between server operations.
3. **Session Persistence**: The login session will be saved locally and automatically restored in subsequent runs.
## Technical Support
If you encounter issues, please:
1. Check the troubleshooting section
2. Verify environment configuration
3. Submit an issue on GitHub
**Note: Please use this tool responsibly and comply with platform rules and relevant laws and regulations.**