* docs: update README.md [skip ci] * docs: update .all-contributorsrc [skip ci] --------- Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
514 lines
16 KiB
Markdown
514 lines
16 KiB
Markdown
# xiaohongshu-mcp
|
||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
||
[](#contributors-)
|
||
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
||
|
||
MCP for 小红书/xiaohongshu.com。
|
||
|
||
- 我的博客文章:[haha.ai/xiaohongshu-mcp](https://www.haha.ai/xiaohongshu-mcp)
|
||
|
||
## Star History
|
||
|
||
[](https://www.star-history.com/#xpzouying/xiaohongshu-mcp&Timeline)
|
||
|
||
**主要功能**
|
||
|
||
> 💡 **提示:** 点击下方功能标题可展开查看视频演示
|
||
|
||
<details>
|
||
<summary><b>1. 登录和检查登录状态</b></summary>
|
||
|
||
第一步必须,小红书需要进行登录。可以检查当前登录状态。
|
||
|
||
**登录演示:**
|
||
|
||
https://github.com/user-attachments/assets/8b05eb42-d437-41b7-9235-e2143f19e8b7
|
||
|
||
**检查登录状态演示:**
|
||
|
||
https://github.com/user-attachments/assets/bd9a9a4a-58cb-4421-b8f3-015f703ce1f9
|
||
|
||
</details>
|
||
|
||
<details>
|
||
<summary><b>2. 发布图文内容</b></summary>
|
||
|
||
支持发布图文内容到小红书,包括标题、内容描述和图片。后续支持更多的发布功能。
|
||
|
||
**发布图文帖子演示:**
|
||
|
||
https://github.com/user-attachments/assets/8aee0814-eb96-40af-b871-e66e6bbb6b06
|
||
|
||
</details>
|
||
|
||
<details>
|
||
<summary><b>3. 搜索内容</b></summary>
|
||
|
||
根据关键词搜索小红书内容。
|
||
|
||
**搜索帖子演示:**
|
||
|
||
https://github.com/user-attachments/assets/03c5077d-6160-4b18-b629-2e40933a1fd3
|
||
|
||
</details>
|
||
|
||
<details>
|
||
<summary><b>4. 获取推荐列表</b></summary>
|
||
|
||
获取小红书首页推荐内容列表。
|
||
|
||
**获取推荐列表演示:**
|
||
|
||
https://github.com/user-attachments/assets/110fc15d-46f2-4cca-bdad-9de5b5b8cc28
|
||
|
||
</details>
|
||
|
||
<details>
|
||
<summary><b>5. 获取帖子详情(包括互动数据和评论)</b></summary>
|
||
|
||
获取小红书帖子的完整详情,包括:
|
||
|
||
- 帖子内容(标题、描述、图片等)
|
||
- 用户信息
|
||
- 互动数据(点赞、收藏、分享、评论数)
|
||
- 评论列表及子评论
|
||
|
||
**⚠️ 重要提示:**
|
||
|
||
- 需要提供帖子 ID 和 xsec_token(两个参数缺一不可)
|
||
- 这两个参数可以从 Feed 列表或搜索结果中获取
|
||
- 必须先登录才能使用此功能
|
||
|
||
**获取帖子详情演示:**
|
||
|
||
https://github.com/user-attachments/assets/76a26130-a216-4371-a6b3-937b8fda092a
|
||
|
||
</details>
|
||
|
||
<details>
|
||
<summary><b>6. 发表评论到帖子</b></summary>
|
||
|
||
支持自动发表评论到小红书帖子。
|
||
|
||
**功能说明:**
|
||
|
||
- 自动定位评论输入框
|
||
- 输入评论内容并发布
|
||
- 支持 HTTP API 和 MCP 工具调用
|
||
|
||
**⚠️ 重要提示:**
|
||
|
||
- 需要先登录才能使用此功能
|
||
- 需要提供帖子 ID、xsec_token 和评论内容
|
||
- 这些参数可以从 Feed 列表或搜索结果中获取
|
||
|
||
**发表评论演示:**
|
||
|
||
https://github.com/user-attachments/assets/cc385b6c-422c-489b-a5fc-63e92c695b80
|
||
|
||
</details>
|
||
|
||
**小红书基础运营知识**
|
||
|
||
- **标题:(非常重要)小红书要求标题不超过 20 个字**
|
||
- 当前只支持图文发送:从推荐的角度看,图文的流量会比纯文字的更好。
|
||
- (低优先级)可以考虑视频和纯文字的支持。1. 个人感觉这两种会大大增加运营的复杂度;2. 这两类在我的使用场景的价值较低。
|
||
- Tags:马上支持。
|
||
- 根据本人实操,小红书每天的发帖量应该是 **50 篇**。
|
||
- **(非常重要)小红书的同一个账号不允许在多个网页端登录**,如果你登录了当前 xiaohongshu-mcp 后,就不要再在其他的网页端登录该账号,否则就会把当前 MCP 的账号“踢出登录”。你可以使用移动 App 端进行查看当前账号信息。
|
||
|
||
**风险说明**
|
||
|
||
1. 该项目是在自己的另外一个项目的基础上开源出来的,原来的项目稳定运行一年多,没有出现过封号的情况,只有出现过 Cookies 过期需要重新登录。
|
||
2. 我是使用 Claude Code 接入,稳定自动化运营数周后,验证没有问题后开源。
|
||
|
||
该项目是基于学习的目的,禁止一切违法行为。
|
||
|
||
**实操结果**
|
||
|
||
第一天点赞/收藏数达到了 999+,
|
||
|
||
<img width="386" height="278" alt="CleanShot 2025-09-05 at 01 31 55@2x" src="https://github.com/user-attachments/assets/4b5a283b-bd38-45b8-b608-8f818997366c" />
|
||
|
||
<img width="350" height="280" alt="CleanShot 2025-09-05 at 01 32 49@2x" src="https://github.com/user-attachments/assets/4481e1e7-3ef6-4bbd-8483-dcee8f77a8f2" />
|
||
|
||
一周左右的成果
|
||
|
||
<img width="1840" height="582" alt="CleanShot 2025-09-05 at 01 33 13@2x" src="https://github.com/user-attachments/assets/fb367944-dc48-4bbd-8ece-934caa86323e" />
|
||
|
||
## 1. 使用教程
|
||
|
||
### 1.1. 安装
|
||
|
||
<details>
|
||
<summary>安装配置详情</summary>
|
||
|
||
依赖 Golang 环境,安装方法请参考 [Golang 官方文档](https://go.dev/doc/install)。
|
||
|
||
设置 Go 国内源的代理,
|
||
|
||
```bash
|
||
# 配置 GOPROXY 环境变量,以下三选一
|
||
|
||
# 1. 七牛 CDN
|
||
go env -w GOPROXY=https://goproxy.cn,direct
|
||
|
||
# 2. 阿里云
|
||
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
|
||
|
||
# 3. 官方
|
||
go env -w GOPROXY=https://goproxy.io,direct
|
||
```
|
||
|
||
</details>
|
||
|
||
Windows 遇到问题首先看这里:[Windows 安装指南](./docs/windows_guide.md)
|
||
|
||
### 1.2. 登录
|
||
|
||
第一次需要手动登录,需要保存小红书的登录状态。
|
||
|
||
运行
|
||
|
||
```bash
|
||
go run cmd/login/main.go
|
||
```
|
||
|
||
### 1.3. 启动 MCP 服务
|
||
|
||
启动 xiaohongshu-mcp 服务。
|
||
|
||
```bash
|
||
|
||
# 默认:无头模式,没有浏览器界面
|
||
go run .
|
||
|
||
# 非无头模式,有浏览器界面
|
||
go run . -headless=false
|
||
```
|
||
|
||
## 1.4. 验证 MCP
|
||
|
||
```bash
|
||
npx @modelcontextprotocol/inspector
|
||
```
|
||
|
||

|
||
|
||
运行后,打开红色标记的链接,配置 MCP inspector,输入 `http://localhost:18060/mcp` ,点击 `Connect` 按钮。
|
||
|
||

|
||
|
||
按照上面配置 MCP inspector 后,点击 `List Tools` 按钮,查看所有的 Tools。
|
||
|
||
## 1.5. 使用 MCP 发布
|
||
|
||
### 检查登录状态
|
||
|
||

|
||
|
||
### 发布图文
|
||
|
||
示例中是从 https://unsplash.com/ 中随机找了个图片做测试。
|
||
|
||

|
||
|
||
### 搜索内容
|
||
|
||
使用搜索功能,根据关键词搜索小红书内容:
|
||
|
||

|
||
|
||
## 2. MCP 客户端接入
|
||
|
||
本服务支持标准的 Model Context Protocol (MCP),可以接入各种支持 MCP 的 AI 客户端。
|
||
|
||
### 2.1. 快速开始
|
||
|
||
#### 启动 MCP 服务
|
||
|
||
```bash
|
||
# 启动服务(默认无头模式)
|
||
go run .
|
||
|
||
# 或者有界面模式
|
||
go run . -headless=false
|
||
```
|
||
|
||
服务将运行在:`http://localhost:18060/mcp`
|
||
|
||
#### 验证服务状态
|
||
|
||
```bash
|
||
# 测试 MCP 连接
|
||
curl -X POST http://localhost:18060/mcp \
|
||
-H "Content-Type: application/json" \
|
||
-d '{"jsonrpc":"2.0","method":"initialize","params":{},"id":1}'
|
||
```
|
||
|
||
#### Claude Code CLI 接入
|
||
|
||
```bash
|
||
# 添加 HTTP MCP 服务器
|
||
claude mcp add --transport http xiaohongshu-mcp http://localhost:18060/mcp
|
||
```
|
||
|
||
### 2.2. 支持的客户端
|
||
|
||
<details>
|
||
<summary><b>Claude Code CLI</b></summary>
|
||
|
||
官方命令行工具,已在上面快速开始部分展示:
|
||
|
||
```bash
|
||
# 添加 HTTP MCP 服务器
|
||
claude mcp add --transport http xiaohongshu-mcp http://localhost:18060/mcp
|
||
```
|
||
|
||
</details>
|
||
|
||
<details>
|
||
<summary><b>Cursor</b></summary>
|
||
|
||
#### 配置文件的方式
|
||
|
||
创建或编辑 MCP 配置文件:
|
||
|
||
**项目级配置**(推荐):
|
||
在项目根目录创建 `.cursor/mcp.json`:
|
||
|
||
```json
|
||
{
|
||
"mcpServers": {
|
||
"xiaohongshu-mcp": {
|
||
"url": "http://localhost:18060/mcp",
|
||
"description": "小红书内容发布服务 - MCP Streamable HTTP"
|
||
}
|
||
}
|
||
}
|
||
```
|
||
|
||
**全局配置**:
|
||
在用户目录创建 `~/.cursor/mcp.json` (同样内容)。
|
||
|
||
#### 使用步骤
|
||
|
||
1. 确保小红书 MCP 服务正在运行
|
||
2. 保存配置文件后,重启 Cursor
|
||
3. 在 Cursor 聊天中,工具应该自动可用
|
||
4. 可以通过聊天界面的 "Available Tools" 查看已连接的 MCP 工具
|
||
|
||
**Demo**
|
||
|
||
插件 MCP 接入:
|
||
|
||

|
||
|
||
调用 MCP 工具:(以检查登录状态为例)
|
||
|
||

|
||
|
||
</details>
|
||
|
||
<details>
|
||
<summary><b>VSCode</b></summary>
|
||
|
||
#### 方法一:使用命令面板配置
|
||
|
||
1. 按 `Ctrl/Cmd + Shift + P` 打开命令面板
|
||
2. 运行 `MCP: Add Server` 命令
|
||
3. 选择 `HTTP` 方式。
|
||
4. 输入地址: `http://localhost:18060/mcp`,或者修改成对应的 Server 地址。
|
||
5. 输入 MCP 名字: `xiaohongshu-mcp`。
|
||
|
||
#### 方法二:直接编辑配置文件
|
||
|
||
**工作区配置**(推荐):
|
||
在项目根目录创建 `.vscode/mcp.json`:
|
||
|
||
```json
|
||
{
|
||
"servers": {
|
||
"xiaohongshu-mcp": {
|
||
"url": "http://localhost:18060/mcp",
|
||
"type": "http"
|
||
}
|
||
},
|
||
"inputs": []
|
||
}
|
||
```
|
||
|
||
**查看配置**:
|
||
|
||

|
||
|
||
1. 确认运行状态。
|
||
2. 查看 `tools` 是否正确检测。
|
||
|
||
**Demo**
|
||
|
||
以搜索帖子内容为例:
|
||
|
||

|
||
|
||
</details>
|
||
|
||
<details>
|
||
<summary><b>Google Gemini CLI</b></summary>
|
||
|
||
在 `~/.gemini/settings.json` 或项目目录 `.gemini/settings.json` 中配置:
|
||
|
||
```json
|
||
{
|
||
"mcpServers": {
|
||
"xiaohongshu": {
|
||
"httpUrl": "http://localhost:18060/mcp",
|
||
"timeout": 30000
|
||
}
|
||
}
|
||
}
|
||
```
|
||
|
||
更多信息请参考 [Gemini CLI MCP 文档](https://google-gemini.github.io/gemini-cli/docs/tools/mcp-server.html)
|
||
|
||
</details>
|
||
|
||
<details>
|
||
<summary><b>MCP Inspector</b></summary>
|
||
|
||
调试工具,用于测试 MCP 连接:
|
||
|
||
```bash
|
||
# 启动 MCP Inspector
|
||
npx @modelcontextprotocol/inspector
|
||
|
||
# 在浏览器中连接到:http://localhost:18060/mcp
|
||
```
|
||
|
||
使用步骤:
|
||
|
||
- 使用 MCP Inspector 测试连接
|
||
- 测试 Ping Server 功能验证连接
|
||
- 检查 List Tools 是否返回 6 个工具
|
||
|
||
</details>
|
||
|
||
<details>
|
||
<summary><b>其他支持 HTTP MCP 的客户端</b></summary>
|
||
|
||
任何支持 HTTP MCP 协议的客户端都可以连接到:`http://localhost:18060/mcp`
|
||
|
||
基本配置模板:
|
||
|
||
```json
|
||
{
|
||
"name": "xiaohongshu-mcp",
|
||
"url": "http://localhost:18060/mcp",
|
||
"type": "http"
|
||
}
|
||
```
|
||
|
||
</details>
|
||
|
||
### 2.3. 可用 MCP 工具
|
||
|
||
连接成功后,可使用以下 MCP 工具:
|
||
|
||
- `check_login_status` - 检查小红书登录状态(无参数)
|
||
- `publish_content` - 发布图文内容到小红书(必需:title, content, images)
|
||
- `list_feeds` - 获取小红书首页推荐列表(无参数)
|
||
- `search_feeds` - 搜索小红书内容(需要:keyword)
|
||
- `get_feed_detail` - 获取帖子详情(需要:feed_id, xsec_token)
|
||
- `post_comment_to_feed` - 发表评论到小红书帖子(需要:feed_id, xsec_token, content)
|
||
|
||
### 2.4. 使用示例
|
||
|
||
使用 Claude Code 发布内容到小红书:
|
||
|
||
```
|
||
帮我写一篇帖子发布到小红书上,
|
||
配图为:https://cn.bing.com/th?id=OHR.MaoriRock_EN-US6499689741_UHD.jpg&w=3840
|
||
图片是:"纽西兰陶波湖的Ngātoroirangi矿湾毛利岩雕(© Joppi/Getty Images)"
|
||
|
||
使用 xiaohongshu-mcp 进行发布。
|
||
```
|
||
|
||

|
||
|
||
**发布结果:**
|
||
|
||
<img src="./assets/publish_result.jpeg" alt="xiaohongshu-mcp 发布结果" width="400">
|
||
|
||
## ShowCase
|
||
|
||
直接参考大家的使用案例:[ShowCase](./examples/README.md)
|
||
|
||
1. [n8n 完整的教程](./examples/n8n/README.md)
|
||
2. [Cherry Studio 完整的教程](./examples/cherrystudio/README.md)
|
||
|
||
## 小红书 MCP 互助群
|
||
|
||
因为项目刚刚启动,会有很多问题,拉一个群大家一起讨论问题,一起为开源项目做贡献。~~扫我的微信二维码加群讨论技术~~。
|
||
|
||
由于添加微信的人太多了,导致微信把我账号封禁了,原因是:处于不安全的网络中。(不确定是不是因为人太多,可能触发了微信的电信诈骗的安全检测,做了:1.实名认证;2.绑定银行卡;3.人工申诉;都没有用。)
|
||
|
||
换到飞书群,直接扫码进群
|
||
|
||
<details>
|
||
<summary>【飞书一群】已满</summary>
|
||
|
||

|
||
|
||
</details>
|
||
|
||
<details>
|
||
<summary>【微信一群】已满 </summary>
|
||
|
||
<img src="https://github.com/user-attachments/assets/34c51c3a-d5fd-4086-9d37-a5a5284264c9" alt="WechatIMG119" width="300">
|
||
|
||
</details>
|
||
|
||
<!-- 两列排布:飞书二群 | 微信群 -->
|
||
|
||
| 【飞书二群】:扫码进入 | 【微信群2群】:扫码进入 |
|
||
| ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
|
||
| <img src="https://github.com/user-attachments/assets/ca1f5d6e-b1bf-4c15-9975-ff75f339ec9b" alt="qrcode_2qun" width="300"> | <img src="https://github.com/user-attachments/assets/d2c0340c-33e7-4d19-a9f5-cd581b63bd56" alt="WechatIMG119" width="300"> |
|
||
|
||
|
||
|
||
## 🙏 致谢贡献者 ✨
|
||
|
||
感谢以下所有为本项目做出贡献的朋友!(排名不分先后)
|
||
|
||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
||
<!-- prettier-ignore-start -->
|
||
<!-- markdownlint-disable -->
|
||
<table>
|
||
<tbody>
|
||
<tr>
|
||
<td align="center" valign="top" width="14.28%"><a href="https://haha.ai"><img src="https://avatars.githubusercontent.com/u/3946563?v=4?s=100" width="100px;" alt="zy"/><br /><sub><b>zy</b></sub></a><br /><a href="https://github.com/xpzouying/xiaohongshu-mcp/commits?author=xpzouying" title="Code">💻</a> <a href="#ideas-xpzouying" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/xpzouying/xiaohongshu-mcp/commits?author=xpzouying" title="Documentation">📖</a> <a href="#design-xpzouying" title="Design">🎨</a> <a href="#maintenance-xpzouying" title="Maintenance">🚧</a> <a href="#infra-xpzouying" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/xpzouying/xiaohongshu-mcp/pulls?q=is%3Apr+reviewed-by%3Axpzouying" title="Reviewed Pull Requests">👀</a></td>
|
||
<td align="center" valign="top" width="14.28%"><a href="http://www.hwbuluo.com"><img src="https://avatars.githubusercontent.com/u/1271815?v=4?s=100" width="100px;" alt="clearwater"/><br /><sub><b>clearwater</b></sub></a><br /><a href="https://github.com/xpzouying/xiaohongshu-mcp/commits?author=esperyong" title="Code">💻</a></td>
|
||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/laryzhong"><img src="https://avatars.githubusercontent.com/u/47939471?v=4?s=100" width="100px;" alt="Zhongpeng"/><br /><sub><b>Zhongpeng</b></sub></a><br /><a href="https://github.com/xpzouying/xiaohongshu-mcp/commits?author=laryzhong" title="Code">💻</a></td>
|
||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/DTDucas"><img src="https://avatars.githubusercontent.com/u/105262836?v=4?s=100" width="100px;" alt="Duong Tran"/><br /><sub><b>Duong Tran</b></sub></a><br /><a href="https://github.com/xpzouying/xiaohongshu-mcp/commits?author=DTDucas" title="Code">💻</a></td>
|
||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Angiin"><img src="https://avatars.githubusercontent.com/u/17389304?v=4?s=100" width="100px;" alt="Angiin"/><br /><sub><b>Angiin</b></sub></a><br /><a href="https://github.com/xpzouying/xiaohongshu-mcp/commits?author=Angiin" title="Code">💻</a></td>
|
||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/muhenan"><img src="https://avatars.githubusercontent.com/u/43441941?v=4?s=100" width="100px;" alt="Henan Mu"/><br /><sub><b>Henan Mu</b></sub></a><br /><a href="https://github.com/xpzouying/xiaohongshu-mcp/commits?author=muhenan" title="Code">💻</a></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<!-- markdownlint-restore -->
|
||
<!-- prettier-ignore-end -->
|
||
|
||
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||
|
||
|
||
### ✨ 特别感谢
|
||
|
||
| 贡献者 |
|
||
| --- |
|
||
| [<img src="https://avatars.githubusercontent.com/wanpengxie" width="100px;"><br>@wanpengxie](https://github.com/wanpengxie) |
|
||
|
||
|
||
|
||
本项目遵循 [all-contributors](https://github.com/all-contributors/all-contributors) 规范。欢迎任何形式的贡献!
|