Content
# Xiaohongshu Auto-Comment Tool (MCP Server)
This is a Xiaohongshu auto-search and comment tool developed based on Playwright, serving as an MCP Server that can be integrated with MCP Client through specific configuration, helping users automate tasks such as logging in to Xiaohongshu, searching for keywords, retrieving note content, and publishing intelligent comments.
## Features
- **Auto Login**: Supports manual QR code scanning login. After the first successful login, the login state will be saved, and subsequent use does not require repeated scanning.
- **Keyword Search**: Can search for Xiaohongshu notes based on user-input keywords and specify the number of return results.
- **Note Content Retrieval**: Input the note's URL to retrieve its detailed content.
- **Note Comment Retrieval**: Obtain comment information for a note through its URL.
- **Intelligent Comment Publishing**: Supports multiple comment types, including:
- **Lead Flow** (guide users to follow or private chat)
- **Like** (simple interaction to gain goodwill)
- **Inquiry** (increase interaction in the form of questions)
- **Professional** (show professional knowledge to establish authority)
## Installation Steps
### Python Environment Check
Ensure the system has Python 3.8 or higher installed. If not, download and install it from the Python official website.
### Project Acquisition
Clone or download this project to your local machine.
### Dependency Installation
Open a command line in the project directory and execute the following command to install required dependencies:
```bash
pip install -r requirements.txt
```
### Browser Installation
The required browser will be automatically installed when the tool is run for the first time.
## MCP Server Configuration
Add the following content to the configuration file of MCP Client to configure this tool as an MCP Server:
```json
{
"mcpServers": {
"xiaohongshu MCP": {
"command": "python",
"args": [
"/ABSOLUTE/PATH/TO/PARENT/FOLDER/xiaohongshu_mcp.py",
"--stdio"
]
}
}
}
```
Adjust the file path in the `args` according to the actual situation.
## Usage
### Starting the Tool
- If started through MCP Client, follow the MCP Client's operation process.
- If run directly, execute in the command line under the project directory:
```bash
python main.py
```
### Main Function Operations
- **Login to Xiaohongshu**: After starting the tool, if not logged in, it will open a browser window, waiting for the user to manually scan the QR code to log in. After successful login, the tool will save the login state.
- **Search Notes**: Call the `search_notes` function in the code. For example:
```python
# Search for notes related to "food", return the top 3 results
await search_notes("food", 3)
```
- **Get Note Content**: Use the `get_note_content` function to get the note content of a specified URL. For example:
```python
# Get the content of the note at the specified URL
await get_note_content("https://www.xiaohongshu.com/search_result/xxxx")
```
- **Get Note Comments**: Call the `get_note_comments` function to get comments for a note at a specified URL. For example:
```python
# Get comments for the note at the specified URL
await get_note_comments("https://www.xiaohongshu.com/search_result/xxxx")
```
- **Publish Intelligent Comments**: Use the `post_smart_comment` function to publish comments on a specified note, choosing different comment types. For example:
```python
# Publish an inquiry-type comment on the note at the specified URL
await post_smart_comment("https://www.xiaohongshu.com/search_result/xxxx", "inquiry")
```
Comment type parameter options:
- **Lead Flow** (default): Guide users to follow or private chat
- **Like**: Simple interaction to gain goodwill
- **Inquiry**: Increase interaction in the form of questions
- **Professional**: Show professional knowledge to establish authority
## Code Structure
- **docs/xiaohongshu_mcp.py**: The core file implementing main functions, including code logic for login, search, content and comment retrieval, and comment publishing.
- **main.py**: An example calling script to demonstrate how to call functions in `xiaohongshu_mcp.py`.
- **requirements.txt**: Records project dependencies, installed via `pip install -r requirements.txt`.
## 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. 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 operation, and prevent account bans.
- **Function Compatibility**: Due to platform updates and adjustments, the availability of search results and comment functions may be affected. If abnormalities occur, please follow project updates or contact the developer.
## Disclaimer
This tool is for learning and research purposes only. Users must strictly comply with relevant laws and regulations and Xiaohongshu platform rules. The project developer does not bear any responsibility for 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