小红书 MCP 工具 - 支持登录、发布图文/视频、点赞评论等功能
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
xhs-mcp-py
小红书 MCP 工具的 Python 实现,基于 Playwright 浏览器自动化,支持登录、发布、搜索、点赞、收藏、评论等功能。
特性
- 🔐 扫码登录 - 支持二维码扫码登录,自动保存 cookies
- 📝 发布内容 - 支持发布图文、视频、文字配图,支持定时发布
- 🔍 搜索内容 - 支持关键词搜索,支持多维度筛选(排序、类型、时间、范围、位置)
- ❤️ 互动功能 - 支持点赞、收藏、评论、回复评论
- 📊 数据获取 - 获取首页推荐、笔记详情、用户主页,支持高级评论加载配置
- 🤖 MCP 协议 - 支持 MCP 协议,可与 AI 助手集成
安装
pip install xhs-mcp-py
# 首次运行需安装浏览器
playwright install chromium
快速开始
使用流程
- 首次使用必须先登录:运行
xhs-mcp login-browser或xhs-mcp login-qrcode扫码登录 - 检查登录状态:运行
xhs-mcp status确认已登录 - 执行操作:登录成功后即可使用各种功能
- Cookies 有效期:约 7-30 天,过期后需重新登录
💡 MCP 使用提示:让 AI 助手先调用
check_login_status检查登录状态,如果未登录则调用login_with_browser进行扫码登录。
MCP 客户端配置
Claude Desktop
编辑配置文件 ~/Library/Application Support/Claude/claude_desktop_config.json(macOS)或 %APPDATA%\Claude\claude_desktop_config.json(Windows):
{
"mcpServers": {
"xiaohongshu": {
"command": "xhs-mcp",
"args": ["serve"]
}
}
}
如果 xhs-mcp 不在系统 PATH 中,使用完整路径:
{
"mcpServers": {
"xiaohongshu": {
"command": "/path/to/your/python/bin/xhs-mcp",
"args": ["serve"]
}
}
}
可通过 which xhs-mcp(macOS/Linux)或 where xhs-mcp(Windows)查看完整路径。
配置完成后重启 Claude Desktop。
Claude Code
# 添加 MCP 服务
claude mcp add xhs-mcp -- xhs-mcp serve
# 查看已添加的 MCP
claude mcp list
# 移除 MCP 服务
claude mcp remove xhs-mcp
Cursor
在 Cursor 设置中添加 MCP 配置:
- 打开 Cursor Settings → Features → MCP Servers
- 点击 "Add Server"
- 填写:
- Name:
xhs-mcp - Command:
xhs-mcp serve
- Name:
其他 MCP 客户端
任何支持 MCP 协议的客户端都可以使用,启动命令为:
xhs-mcp serve
发布
文字配图
封面文字:我开源了个小红书自动发布工具:xhs-mcp-py
文字标题:我开源了个小红书自动发布工具:xhs-mcp-py
文字正文内容:
我开源了个小红书自动发布工具:xhs-mcp-py。
基于 Python,轻松兼容 Windows、Mac、Linux。
支持 Claude Code 和 OpenClaw,还能发布文字配图笔记。
核心原理:模拟浏览器登录。
项目地址:https://github.com/luweizheng/xhs-mcp-py
欢迎来玩!
命令行使用
# 1. 扫码登录(首次使用必须执行)
# 方式一:打开浏览器窗口扫码
xhs-mcp login-browser
# 方式二:在终端显示二维码,在 Claude Code、Open Code 中推荐使用这种
xhs-mcp login-qrcode --terminal
# 方式三:保存二维码图片,在 OpenClaw 中将 qrcode.png 发送给 Channel 中的用户
xhs-mcp login-qrcode --save qrcode.png
# 2. 检查登录状态(确认已登录后再执行其他操作)
xhs-mcp status
# 发布图文
xhs-mcp publish -t "标题" -c "文字正文内容" -i image1.jpg -i image2.jpg --tag 旅行 --tag 美食
# 发布视频
xhs-mcp publish-video -t "标题" -c "文字正文内容" -v video.mp4
# 发布文字配图(将文字生成为卡片图片)
xhs-mcp publish-text-card -c "封面文字" -p "第一页内容" -p "第二页内容" -s "基础" -t "笔记标题"
# 搜索内容
xhs-mcp search -k "关键词"
# 退出登录
xhs-mcp logout
# 启动 MCP 服务
xhs-mcp serve
MCP 工具列表
| 工具名 | 说明 |
|---|---|
login_with_browser |
浏览器登录 - 弹出浏览器窗口扫码登录,cookies 保存后可复用 |
check_login_status |
检查登录状态 |
get_login_qrcode |
获取登录二维码(返回 Base64 图片,需配合轮询使用) |
delete_cookies |
删除 cookies,重置登录 |
publish_content |
发布图文内容 |
publish_text_card |
发布文字配图笔记 |
publish_with_video |
发布视频内容 |
list_feeds |
获取首页推荐列表 |
search_feeds |
搜索内容 |
get_feed_detail |
获取笔记详情 |
get_user_profile |
获取用户主页 |
like_feed |
点赞/取消点赞 |
favorite_feed |
收藏/取消收藏 |
post_comment |
发表评论 |
reply_comment |
回复评论 |
API 参考
💡 提示: 点击下方功能标题可展开查看详细说明
第一步必须,小红书需要进行登录。可以检查当前登录状态。
MCP 工具:
login_with_browser- 启动浏览器扫码登录,cookies 保存后可复用check_login_status- 检查当前登录状态delete_cookies- 删除 cookies,重置登录状态
命令行:
# 浏览器扫码登录
xhs-mcp login-browser
# 终端二维码登录,在 Claude Code、Open Code 中推荐使用这种
xhs-mcp login-qrcode --terminal
# 检查登录状态
xhs-mcp status
# 退出登录
xhs-mcp logout
2. 发布图文内容
支持发布图文内容到小红书,包括标题、内容描述和图片。
MCP 工具: publish_content
参数:
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
title |
string | ✅ | 文章标题(最多20个字) |
content |
string | ✅ | 文字正文内容 |
images |
list[string] | ✅ | 图片路径列表(本地绝对路径) |
tags |
list[string] | ❌ | 话题标签列表 |
schedule_at |
string | ❌ | 定时发布时间(ISO8601格式) |
命令行:
xhs-mcp publish -t "标题" -c "文字正文内容" -i image1.jpg -i image2.jpg --tag 旅行 --tag 美食
3. 发布视频内容
支持发布视频内容到小红书,包括标题、内容描述和本地视频文件。
MCP 工具: publish_with_video
参数:
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
title |
string | ✅ | 文章标题(最多20个字) |
content |
string | ✅ | 文字正文内容 |
video |
string | ✅ | 本地视频绝对路径 |
tags |
list[string] | ❌ | 话题标签列表 |
schedule_at |
string | ❌ | 定时发布时间(ISO8601格式) |
命令行:
xhs-mcp publish-video -t "标题" -c "文字正文内容" -v video.mp4
4. 发布文字配图
将文字生成为卡片图片并发布,支持多页和多种样式。
MCP 工具: publish_text_card
参数:
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
cover_text |
string | ✅ | 封面文字 |
pages |
list[string] | ❌ | 正文页列表(最多17页) |
style |
string | ❌ | 卡片样式:基础/边框/备忘/手写/便签/涂写/简约/光影/几何 |
title |
string | ❌ | 文章标题 |
content |
string | ❌ | 文字正文内容 |
tags |
list[string] | ❌ | 话题标签列表 |
命令行:
xhs-mcp publish-text-card -c "封面文字" -p "第一页" -p "第二页" -s "基础" -t "笔记标题"
5. 搜索内容
根据关键词搜索小红书内容,支持多维度筛选。
MCP 工具: search_feeds
参数:
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
keyword |
string | ✅ | 搜索关键词 |
sort_by |
string | ❌ | 排序:综合/最新/最多点赞/最多评论/最多收藏 |
note_type |
string | ❌ | 类型:不限/视频/图文 |
publish_time |
string | ❌ | 时间:不限/一天内/一周内/半年内 |
search_scope |
string | ❌ | 范围:不限/已看过/未看过/已关注 |
location |
string | ❌ | 位置:不限/同城/附近 |
命令行:
xhs-mcp search -k "关键词"
6. 获取推荐列表
获取小红书首页推荐内容列表。
MCP 工具: list_feeds
参数: 无
7. 获取笔记详情
获取小红书笔记的完整详情,包括内容、互动数据和评论。
MCP 工具: get_feed_detail
参数:
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
feed_id |
string | ✅ | 笔记 ID(从搜索或推荐列表获取) |
xsec_token |
string | ✅ | 访问令牌(从搜索或推荐列表获取) |
load_comments |
bool | ❌ | 是否加载评论(基础模式,前10条) |
load_all_comments |
bool | ❌ | 是否加载全部评论(滚动加载) |
limit |
int | ❌ | 限制一级评论数量(默认20) |
click_more_replies |
bool | ❌ | 是否展开二级回复 |
reply_limit |
int | ❌ | 跳过回复数过多的评论(默认10) |
scroll_speed |
string | ❌ | 滚动速度:slow/normal/fast |
8. 获取用户主页
获取小红书用户的个人主页信息。
MCP 工具: get_user_profile
参数:
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
user_id |
string | ✅ | 用户 ID |
xsec_token |
string | ✅ | 访问令牌 |
9. 点赞/收藏
对笔记进行点赞或收藏操作。
MCP 工具:
like_feed- 点赞/取消点赞favorite_feed- 收藏/取消收藏
参数:
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
feed_id |
string | ✅ | 笔记 ID |
xsec_token |
string | ✅ | 访问令牌 |
unlike/unfavorite |
bool | ❌ | 是否取消操作(默认 false) |
10. 发表评论/回复
对笔记发表评论或回复已有评论。
MCP 工具:
post_comment- 发表评论reply_comment- 回复评论
post_comment 参数:
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
feed_id |
string | ✅ | 笔记 ID |
xsec_token |
string | ✅ | 访问令牌 |
content |
string | ✅ | 评论内容 |
reply_comment 参数:
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
feed_id |
string | ✅ | 笔记 ID |
xsec_token |
string | ✅ | 访问令牌 |
content |
string | ✅ | 回复内容 |
comment_id |
string | ❌ | 目标评论 ID |
user_id |
string | ❌ | 目标用户 ID |
注意:
comment_id和user_id至少需要提供一个
开发
# 克隆项目
git clone https://github.com/luweizheng/xhs-mcp-py.git
cd xhs-mcp-py
# 安装开发依赖
pip install -e ".[dev]"
# 安装浏览器
playwright install chromium
# 运行测试
pytest
注意事项
- 首次使用需要扫码登录,登录后 cookies 会保存到本地
- 建议使用
--no-headless模式进行登录,以便扫码 - cookies 默认保存在当前目录的
cookies.json文件 - 可通过环境变量
COOKIES_PATH指定 cookies 文件路径
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xhs_mcp_py-0.1.2.tar.gz.
File metadata
- Download URL: xhs_mcp_py-0.1.2.tar.gz
- Upload date:
- Size: 34.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2c6f7907925bcbd29911c9fb53ce96faded7fdc3f4738ec749a7714d65378d1
|
|
| MD5 |
6010cbe0cd7d58b914971dd6cc0f7ae7
|
|
| BLAKE2b-256 |
bf1fd6587171a597f135d323a15ac227696d88f6860367324fd325cf71921b1b
|
Provenance
The following attestation bundles were made for xhs_mcp_py-0.1.2.tar.gz:
Publisher:
publish.yml on luweizheng/xhs-mcp-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xhs_mcp_py-0.1.2.tar.gz -
Subject digest:
f2c6f7907925bcbd29911c9fb53ce96faded7fdc3f4738ec749a7714d65378d1 - Sigstore transparency entry: 995791519
- Sigstore integration time:
-
Permalink:
luweizheng/xhs-mcp-py@b01d9d7dd2afe8785b9ad42583e0eacf5a75d7bd -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/luweizheng
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b01d9d7dd2afe8785b9ad42583e0eacf5a75d7bd -
Trigger Event:
push
-
Statement type:
File details
Details for the file xhs_mcp_py-0.1.2-py3-none-any.whl.
File metadata
- Download URL: xhs_mcp_py-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a72a7f4cfadc19b90d8fdd45c742f89252fcb10059deb762e1c17617ccaeb6c9
|
|
| MD5 |
ec879ffc7225fa96c9d789382f2b4ac4
|
|
| BLAKE2b-256 |
bcd70871bc59388e10e2876630d6d8b3b2df6c5af2947a16574a962757dfe341
|
Provenance
The following attestation bundles were made for xhs_mcp_py-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on luweizheng/xhs-mcp-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xhs_mcp_py-0.1.2-py3-none-any.whl -
Subject digest:
a72a7f4cfadc19b90d8fdd45c742f89252fcb10059deb762e1c17617ccaeb6c9 - Sigstore transparency entry: 995791521
- Sigstore integration time:
-
Permalink:
luweizheng/xhs-mcp-py@b01d9d7dd2afe8785b9ad42583e0eacf5a75d7bd -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/luweizheng
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b01d9d7dd2afe8785b9ad42583e0eacf5a75d7bd -
Trigger Event:
push
-
Statement type: