Content
Xiaohongshu Auto-Comment Tool (MCP Server)
This is a Xiaohongshu auto-search and comment tool developed based on Playwright, which can be used as an MCP Server and connected to the MCP Client through specific configuration to help users automatically complete tasks such as logging in to Xiaohongshu, searching for keywords, obtaining note content, and publishing intelligent comments.
## Features
- **Auto Login**: Supports manual scan code login. After the first successful login, the login status will be saved, and subsequent use will not require repeated scan codes.
- **Keyword Search**: Can search for Xiaohongshu notes based on user-input keywords and specify the number of returned results.
- **Note Content Acquisition**: Enter the URL of a note to obtain its detailed content.
- **Note Comment Acquisition**: Obtain comment information for a note through its URL.
- **Intelligent Comment Publishing**: Supports multiple comment types, including:
- **Lead** (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)
Can choose to publish according to needs.
## Installation Steps
### Python Environment Check
Ensure that the system has Python 3.8 or a higher version installed. If not installed, download and install it from the Python official website.
### Project Acquisition
Clone or download this project to your local machine.
### Install Dependencies
Open the command line in the project directory and execute the following command to install the required dependencies:
```bash
pip install -r requirements.txt
```
### Browser Installation
When running the tool for the first time, it will automatically install the required browser.
## 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"
]
}
}
}
```
Please adjust the file path in `args` according to the actual situation.
## Usage
### Starting the Tool
If started through MCP Client, follow the operation process of MCP Client.
If running 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 and wait for the user to manually scan the code to log in. After successful login, the tool will save the login status.
- **Search Notes**: Call the `search_notes` function in the code. For example:
```python
# Search for notes related to "food" and return the top 3 results
await search_notes("food", 3)
```
- **Get Note Content**: Use the `get_note_content` function to obtain the note content of the 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 obtain the comments of the note at the specified URL. For example:
```python
# Get the comments of 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 the specified note, and choose different comment types. For example:
```python
# Publish an inquiry-type comment on the specified note
await post_smart_comment("https://www.xiaohongshu.com/search_result/xxxx", "inquiry")
```
Comment type parameter options:
- **Lead** (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 the main functions, containing the code logic for login, search, content and comment acquisition, and comment publishing.
- **main.py**: An example calling script, used to demonstrate how to call the functions in `xiaohongshu_mcp.py`.
- **requirements.txt**: Records the dependency libraries required by the project, which can be installed through the command `pip install -r requirements.txt`.
## Precautions
- **Browser Mode**: The tool runs in non-headless mode using Playwright, and a real browser window will be opened during operation.
- **Login Method**: The first login requires manual scanning of the code. If the login status is valid for subsequent use, there is no need to scan the code again.
- **Platform Rules**: Please strictly comply with the relevant regulations of the Xiaohongshu platform during use, avoid excessive operations, and prevent the account from facing risks such as sealing.
- **Function Compatibility**: Due to the Xiaohongshu platform may update and adjust, the availability of search results and comment functions may be affected. If an exception occurs, please pay close attention to project updates or contact the developer.
## Disclaimer
This tool is only used for learning and research purposes. Users should strictly comply with relevant laws and regulations and the provisions of the Xiaohongshu platform. The project developer does not bear any responsibility for any problems caused by improper use.
Connection Info
You Might Also Like
awesome-mcp-servers
A collection of MCP servers.
git
A Model Context Protocol server for Git automation and interaction.
cc-switch
All-in-One Assistant for Claude Code, Codex & Gemini CLI across platforms.
TrendRadar
TrendRadar: Your hotspot assistant for real news in just 30 seconds.
oh-my-opencode
Background agents · Curated agents like oracle, librarians, frontend...
Appwrite
Build like a team of hundreds