chenningling
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"xiaohongshu MCP": {
"args": [
"/绝对路径/到/xiaohongshu_mcp.py",
"--stdio"
],
"command": "/绝对路径/到/venv/bin/python3"
}
}
}
服务介绍
Xiaohongshu Automatic Search and Comment Tool (MCP Server)
This project is based on JonaFly/RednoteMCP and has been optimized and improved according to my personal usage experience (by windsurf). I would like to express my sincere gratitude to the original author!
This is a Xiaohongshu automatic search and comment tool developed using Playwright, serving as an MCP Server. It can be connected to an MCP Client (such as Claude for Desktop) through specific configurations, helping users automatically complete actions such as logging into Xiaohongshu, searching for keywords, obtaining note contents, and posting intelligent comments.
Note: Redbook-Search-Comment-MCP2.0 has been released! Just click to start using it!
Main optimizations in 2.0 include:
- Fixed the issue where titles were not displayed when searching for notes
- Added multiple methods for fetching notes to ensure complete content retrieval
- Refactored the commenting feature, utilizing the AI capabilities of the MCP client (e.g., Claude) to generate more natural comments
- Modularized functionalities into three independent modules: note analysis, comment generation, and comment posting
I. Features
- Automatic Login: Supports manual QR code scanning for login. After the first successful login, the login status will be saved, eliminating the need for repeated scans.
- Keyword Search: Can search Xiaohongshu notes based on user-inputted keywords and allows specifying the number of results to return.
- Note Content Retrieval: By inputting the URL of a note, you can obtain its detailed content.
- Note Comment Retrieval: Retrieves comment information for a given note via its URL.
- Intelligent Comment Posting: Supports various types of comments, including traffic attraction (guiding users to follow or private message), likes (simple interaction to gain favor), inquiries (increasing interaction through questions), and professional (showcasing expertise to establish authority). You can choose the type of comment to post based on your needs.
II. Installation Steps
-
Prepare Python Environment: Ensure that Python 3.8 or a higher version is installed on your system. If not, download and install from the official Python website.
-
Get the Project: Clone or download this project to your local machine.
-
Create Virtual Environment: Create and activate a virtual environment within the project directory (recommended):
bashCreate virtual environment
python3 -m venv venv
Activate virtual environment
Windows
venvScriptsactivate
macOS/Linux
source venv/bin/activate
-
Install Dependencies: Install the required dependencies in the activated virtual environment:
bash
pip install -r requirements.txt
pip install fastmcp -
Install Browser: Install the browser required by Playwright:
bash
playwright install
III. MCP Server Configuration
Add the following content to the configuration file of the MCP Client (e.g., Claude for Desktop) to set up this tool as an MCP Server:
json
{
"mcpServers": {
"xiaohongshu MCP": {
"command": "/absolute/path/to/venv/bin/python3",
"args": [
"/absolute/path/to/xiaohongshu_mcp.py",
"--stdio"
]
}
}
}
Important Note:
- Please use the full absolute path of the Python interpreter in the virtual environment.
- For example:
/Users/username/Desktop/RedBook-Search-Comment-MCP/venv/bin/python3- Similarly,
xiaohongshu_mcp.pyshould also use the full absolute path
IV. Usage
(I) Starting the Server
-
Run Directly: In the project directory, after activating the virtual environment, execute:
bash
python3 xiaohongshu_mcp.py -
Start via MCP Client: After configuring the MCP Client, follow the client's operational procedures to start and connect.
(II) Main Function Operations
After connecting to the server through the MCP Client (e.g., Claude for Desktop), you can use the following features:
1. Log in to Xiaohongshu
Tool Function:
mcp0_login()
Usage in MCP Client:
Directly send the following text:
Help me log in to my Xiaohongshu account
or:
Please log in to Xiaohongshu
Function Description: When used for the first time, a browser window will open, waiting for the user to manually scan the QR code to log in. After a successful login, the tool will save the login status.
2. Search Notes
Tool Function:
mcp0_search_notes(keywords="keyword", limit=5)Usage in MCP Client:
Send a search request with keywords:
Help me search for Xiaohongshu notes, keyword: food
Specify the number of results to return:
Help me search for Xiaohongshu notes, keyword: travel, return 10 results
Function Description: Search Xiaohongshu notes based on keywords and return a specified number of results. The default is to return 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 check the content of this Xiaohongshu note: https://www.xiaohongshu.com/search_result/xxxx
Function Description: Retrieve detailed content of the specified note URL, including title, author, publication time, and main text.
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 check the comment section of this Xiaohongshu note: https://www.xiaohongshu.com/search_result/xxxx
Function Description: Retrieve comment information for the specified note URL, including commenter, comment content, and comment time.
5. Post Smart Comment
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 post a professional type comment on this note: https://www.xiaohongshu.com/search_result/xxxx
or:
Please post a traffic-driving comment under this Xiaohongshu note: https://www.xiaohongshu.com/search_result/xxxx
Available Values for Comment Type Parameter:
"traffic-driving"(default): Guide users to follow or private message"like": Simple interaction to gain favor"inquiry": Increase interaction through questions"professional": Demonstrate expertise to establish authority
Function Description: Post a smart comment under the specified note. The system will automatically generate appropriate comment content based on the note's content and the specified comment type.
V. Code Structure
- xiaohongshu_mcp.py: Core file implementing the main functionalities, including login, search, content and comment retrieval, and posting comments.
- requirements.txt: Records the required dependencies for the project.
VI. Common Issues and Solutions
-
Connection Failure:
- Ensure you are using the full absolute path of the Python interpreter in your virtual environment
- Ensure the MCP server is running
- Try restarting the MCP server and client
-
Browser Session Issues:
If encountering thePage.goto: Target page, context or browser has been closederror:- Restart the MCP server
- Reconnect and log in again
-
Dependency Installation Issues:
If encountering aModuleNotFoundError:- Ensure all dependencies are installed in the virtual environment
- Check if the fastmcp package is installed
VII. Precautions
- Browser Mode: The tool runs in non-headless mode using Playwright, which opens a real browser window during operation.
- Login Method: The first login requires manual QR code scanning. Subsequent uses do not require re-scanning if the login status remains valid.
- Platform Rules: Strictly adhere to Xiaohongshu platform regulations during use to avoid excessive operations that could lead to account bans or other risks.
- Function Compatibility: Due to potential updates and adjustments by the Xiaohongshu platform, the availability of search and comment functions may be affected. In case of anomalies, please promptly monitor project updates or contact the developer.
VIII. Disclaimer
This tool is intended solely for learning and research purposes. Users must strictly comply with relevant laws and regulations as well as Xiaohongshu platform rules. The developers of this project assume no responsibility for any issues arising from improper use.