Content
# Tool List
<div align="right">
[English](README_EN.md) | English
</div>
> This project is based on [JonaFly/RednoteMCP](https://github.com/JonaFly/RednoteMCP.git) and has been comprehensively optimized and expanded with multiple practical experiences (by windsurf). Sincere thanks to the original author for their contribution!
This is an automated search and comment tool for Xiaohongshu (Little Red Book) developed based on Playwright, functioning as an MCP Server that can be integrated with MCP Clients (like Claude for Desktop) through specific configurations. It helps users automate tasks such as logging into Xiaohongshu, searching for keywords, retrieving note content, and publishing AI-generated comments.
## Key Features and Advantages
- **Deep Integration of AI Capabilities**: Utilizes the large model capabilities of MCP clients (like Claude) to generate more natural and relevant comment content.
- **Modular Design**: The functionality is divided into three independent modules: note analysis, comment generation, and comment publishing, improving code maintainability.
- **Powerful Content Retrieval Capability**: Integrates multiple methods to retrieve note content, ensuring complete retrieval of titles, authors, and content of various notes.
- **Persistent Login**: Uses a persistent browser context, eliminating the need for repeated logins after the first login.
- **Two-Step Comment Process**: First, obtain note analysis results, then generate and publish comments by the MCP client.
## Major Optimizations in Version 2.0
- **Enhanced Content Retrieval**: Reconstructed the note content retrieval module, increased page loading wait times and scrolling operations, and implemented four different content retrieval methods.
- **AI Comment Generation**: Reconstructed the comment function, returning note analysis results to the MCP client, which generates more natural and relevant comments using the client's AI capabilities.
- **Functional Modularization**: Divided the functionality into three independent modules: note analysis, comment generation, and comment publishing, improving code maintainability.
- **Search Result Optimization**: Solved the issue of invisible titles when searching for notes, providing more complete search results.
- **Enhanced Error Handling**: Added more detailed error handling and debugging information output.
## Core Functionalities
### 1. User Authentication and Login
- **Persistent Login**: Supports manual QR code scanning login, saves the state after the first login, and no repeated scanning is required for subsequent use.
- **Login State Management**: Automatically detects the login state and prompts the user to log in when necessary.
### 2. Content Discovery and Retrieval
- **Intelligent Keyword Search**: Supports multi-keyword search, allows specifying the number of return results, and provides complete note information.
- **Multi-Dimensional Content Retrieval**: Integrates four different retrieval methods to ensure accurate retrieval of note titles, authors, publication times, and content.
- **Comment Data Retrieval**: Supports retrieving comment content of notes, including commenter, comment text, and time information.
### 3. Content Analysis and Generation
- **Note Content Analysis**: Automatically analyzes note content, extracts key information, and identifies the note's domain.
- **AI Comment Generation**: Utilizes the AI capabilities of MCP clients (like Claude) to generate natural and relevant comments based on note content.
- **Multi-Type Comment Support**: Supports generating four different types of comments:
- **Traffic Type**: Guides users to follow or chat privately.
- **Like Type**: Simple interaction to gain favor.
- **Consultation Type**: Increases interaction in the form of questions.
- **Professional Type**: Showcases professional knowledge to establish authority.
### 4. Data Return and Feedback
- **Structured Data Return**: Returns note analysis results in JSON format to the MCP client for AI to generate comments.
- **Comment Publishing Feedback**: Provides real-time feedback on comment publishing results.
## Installation Steps
1. **Python Environment Preparation**: Ensure the system has Python 3.8 or higher installed. If not, download and install it from the Python official website.
2. **Project Acquisition**: Clone or download this project to your local machine.
3. **Create a Virtual Environment**: Create and activate a virtual environment (recommended) in the project directory:
```bash
# Create a virtual environment
python3 -m venv venv
# Activate the virtual environment
# Windows
venv\Scripts\activate
# macOS/Linux
source venv/bin/activate
```
4. **Install Dependencies**: Install required dependencies in the activated virtual environment:
```bash
pip install -r requirements.txt
pip install fastmcp
```
5. **Install Browser**: Install the browser required by Playwright:
```bash
playwright install
```
## MCP Server Configuration
Add the following content to the configuration file of the MCP Client (like Claude for Desktop) to configure this tool as an MCP Server:
### Mac Configuration Example
```json
{
"mcpServers": {
"xiaohongshu MCP": {
"command": "/absolute/path/to/venv/bin/python3",
"args": [
"/absolute/path/to/xiaohongshu_mcp.py",
"--stdio"
]
}
}
}
```
### Windows Configuration Example
```json
{
"mcpServers": {
"xiaohongshu MCP": {
"command": "C:\\Users\\username\\Desktop\\MCP\\Redbook-Search-Comment-MCP2.0\\venv\\Scripts\\python.exe",
"args": [
"C:\\Users\\username\\Desktop\\MCP\\Redbook-Search-Comment-MCP2.0\\xiaohongshu_mcp.py",
"--stdio"
]
}
}
}
```
> **Important Note**:
> - Use the **full absolute path** of the Python interpreter in the virtual environment.
> - Similarly, `xiaohongshu_mcp.py` also requires a **full absolute path**.
### Python Command Distinction (python vs. python3)
The Python command may vary in different system environments, depending on your system configuration. Here's how to determine which command to use:
1. **Determine Your Python Command**:
- Run `python --version` and `python3 --version` in the terminal.
- Check which command returns the Python 3.x version (this project requires Python 3.8+).
2. **Confirm in the Virtual Environment**:
- After activating the virtual environment, run `which python` or `where python` (Windows).
- This will display the full path of the Python interpreter.
3. **Use the Correct Command in Configuration**:
- Mac: Usually `python3` or `python` in the virtual environment.
- Windows: Usually `python` or `python.exe`.
## Usage
### (1) Start the Server
1. **Direct Run**: Execute in the project directory after activating the virtual environment:
```bash
python3 xiaohongshu_mcp.py
```
2. **Start via MCP Client**: After configuring the MCP Client, follow the client's operation process to start and connect.
### (2) Main Function Operations
After connecting to the server in the MCP Client (like Claude for Desktop), you can use the following functions:
### 1. Login to Xiaohongshu
**Tool Function**:
```
mcp0_login()
```
**Usage in MCP Client**:
Send the following text directly:
```
Help me log in to my Xiaohongshu account
```
or:
```
Please log in to Xiaohongshu
```
**Function Description**: The browser window will open for manual QR code scanning login when used for the first time. After successful login, the tool saves the login state.
### 2. Search Notes
**Tool Function**:
```
mcp0_search_notes(keywords="keywords", limit=5)
```
**Usage in MCP Client**:
Send a search request with keywords:
```
Help me search for Xiaohongshu notes with the keyword: food
```
Specify the number of returns:
```
Help me search for Xiaohongshu notes with the keyword: travel, return 10 results
```
**Function Description**: Searches Xiaohongshu notes based on keywords and returns a specified number of results. Default returns 5 results.
### 3. Get Note Content
**Tool Function**:
```
mcp0_get_note_content(url="note URL")
```
**Usage in MCP Client**:
Send a request with the note URL:
```
Help me get the content of this note: https://www.xiaohongshu.com/search_result/xxxx
```
or:
```
Please view the content of this Xiaohongshu note: https://www.xiaohongshu.com/search_result/xxxx
```
**Function Description**: Retrieves the detailed content of a specified note URL, including title, author, publication time, and content.
### 4. Get Note Comments
**Tool Function**:
```
mcp0_get_note_comments(url="note URL")
```
**Usage in MCP Client**:
Send a comment request with the note URL:
```
Help me get the comments of this note: https://www.xiaohongshu.com/search_result/xxxx
```
or:
```
Please view the comment section of this Xiaohongshu note: https://www.xiaohongshu.com/search_result/xxxx
```
**Function Description**: Retrieves comment information of a specified note URL, including commenter, comment content, and comment time.
### 5. Publish Smart Comments
**Tool Function**:
```
mcp0_post_smart_comment(url="note URL", comment_type="comment type")
```
**Usage in MCP Client**:
Send a request with the note URL and comment type:
```
Help me write a [type] comment for this note: https://www.xiaohongshu.com/explore/xxxx
```
**Function Description**: Obtains note analysis results and returns them to the MCP client, which generates comments and calls `post_comment` to publish.
### 6. Publish Comments
**Tool Function**:
```
mcp0_post_comment(url="note URL", comment="comment content")
```
**Usage in MCP Client**:
Send a request with the note URL and comment content:
```
Help me publish this comment to the note: https://www.xiaohongshu.com/explore/xxxx
Comment content: [comment content]
```
**Function Description**: Publishes specified comment content to the note page.
## Guide
### 0. Working Principle
This tool adopts a two-step process to achieve intelligent comment functionality:
1. **Note Analysis**: Call the `post_smart_comment` tool to obtain note information (title, author, content, etc.).
2. **Comment Generation and Publishing**:
- The MCP client (like Claude) generates comments based on note analysis results.
- Calls the `post_comment` tool to publish comments.
This design fully utilizes the AI capabilities of the MCP client to achieve more natural and relevant comment generation.
### 1. Usage in MCP Client
#### Basic Operations
| Function | Example Command |
|---------|----------|
| **Search Notes** | `Help me search for [keyword] Xiaohongshu notes` |
| **Get Note Content** | `Help me view the content of this Xiaohongshu note: https://www.xiaohongshu.com/explore/xxxx` |
| **Analyze Notes** | `Help me analyze this Xiaohongshu note: https://www.xiaohongshu.com/explore/xxxx` |
| **Get Comments** | `Help me view the comments of this note: https://www.xiaohongshu.com/explore/xxxx` |
| **Generate Comments** | `Help me write a [type] comment for this Xiaohongshu note: https://www.xiaohongshu.com/explore/xxxx` |
#### Comment Type Options
| Type | Description | Applicable Scenario |
|---------|------|----------|
| **Traffic** | Guides users to follow or chat privately | Increase followers or private chat interactions |
| **Like** | Simple interaction to gain favor | Increase exposure and interaction rate |
| **Consultation** | Increases interaction in the form of questions | Trigger the blogger to reply and increase interaction depth |
| **Professional** | Showcases professional knowledge to establish authority | Establish a professional image and enhance credibility |
### 2. Actual Work Flow Example
```
User: Help me write a professional-type comment for this Xiaohongshu note: https://www.xiaohongshu.com/explore/xxxx
Claude: I will help you write a professional-type comment. Let me retrieve the note content and generate the comment.
[Call post_smart_comment tool]
# Tool returns note analysis results, including title, author, content, domain, and keywords
Claude: I have obtained the note information, which is a note about [topic]. Based on the content, I generated and published the following professional comment:
"[Generated professional comment content]"
[Call post_comment tool]
Claude: The comment has been successfully published!
```
**Note**: In the above process, the `post_smart_comment` tool is only responsible for obtaining note analysis results and returning them to the MCP client, while the actual comment generation is completed by the MCP client (like Claude).
### 3. Working Principle
The new Xiaohongshu MCP tool adopts a modular design, divided into three core modules:
1. **Note Analysis Module** (analyze_note)
- Retrieves note title, author, publication time, and content.
- Analyzes the note's domain and keywords.
- Returns structured note information.
2. **Comment Generation Module** (implemented by MCP client)
- Receives note analysis results.
- Generates natural and relevant comments based on note content and comment type.
- Allows users to preview and modify comments before publishing.
3. **Comment Publishing Module** (post_comment)
- Receives generated comment content.
- Locates and operates the comment input box.
- Publishes comments and returns results.
## V. Code Structure
- **xiaohongshu_mcp.py**: The core file implementing main functionalities, including login, search, content and comment retrieval, and comment publishing.
- **requirements.txt**: Records project dependencies.
## VI. Frequently Asked Questions and Solutions
1. **Connection Failure**:
- Ensure the **full absolute path** of the Python interpreter in the virtual environment is used.
- Ensure the MCP server is running.
- Try restarting the MCP server and client.
2. **Browser Session Issues**:
If encountering errors like `Page.goto: Target page, context or browser has been closed`:
- Restart the MCP server.
- Reconnect and log in.
3. **Dependency Installation Issues**:
If encountering `ModuleNotFoundError`:
- Ensure all dependencies are installed in the virtual environment.
- Check if the fastmcp package is installed.
## VII. Precautions and Problem Solving
### 1. Usage Precautions
- **Browser Mode**: The tool runs in non-headless mode using Playwright, opening a real browser window during operation.
- **Login Method**: The first login requires manual QR code scanning, and subsequent use does not require scanning again if the login state is valid.
- **Platform Rules**: Strictly comply with Xiaohongshu platform regulations during use, avoid excessive operations, and prevent account risks.
- **Comment Frequency**: It is recommended to control comment publishing frequency, avoid publishing a large number of comments in a short time, and limit daily comments to no more than 30.
### 2. Common Issues and Solutions
#### Browser Instance Issues
If encountering errors similar to “Page.goto: Target page, context or browser has been closed”:
```bash
# Delete browser lock files
rm -f /project/path/browser_data/SingletonLock /project/path/browser_data/SingletonCookie
# If the issue persists, backup and rebuild the browser data directory
mkdir -p /project/path/backup_browser_data
mv /project/path/browser_data/* /project/path/backup_browser_data/
mkdir -p /project/path/browser_data
```
#### Content Retrieval Issues
If note content cannot be retrieved or is incomplete:
1. **Increase wait time**: Xiaohongshu note pages may require longer loading times, especially for notes with many images or videos.
2. **Clear browser cache**: Sometimes browser cache may affect content retrieval.
3. **Try different retrieval methods**: The tool integrates multiple retrieval methods; if one fails, try another.
#### Adaptation to Platform Changes
Xiaohongshu may update page structures and DOM elements, causing the tool to malfunction. If encountered:
1. **Check project updates**: Follow the latest project version and update in time.
2. **Adjust selectors**: If familiar with code, try adjusting CSS selectors or XPath expressions.
3. **Submit issue feedback**: Submit issues to project maintainers, describing specific problems and page changes.
## VIII. Disclaimer
This tool is for learning and research purposes only. Users must strictly comply with relevant laws and regulations and Xiaohongshu platform regulations. The project developers are not responsible for any issues caused by improper use.
Connection Info
You Might Also Like
awesome-mcp-servers
A collection of MCP servers.
cc-switch
All-in-One Assistant for Claude Code, Codex & Gemini CLI across platforms.
git
A Model Context Protocol server for Git automation and interaction.
oh-my-opencode
Background agents · Curated agents like oracle, librarians, frontend...
TrendRadar
TrendRadar: Your hotspot assistant for real news in just 30 seconds.
Appwrite
Build like a team of hundreds