A Model Context Protocol (MCP) server for Xiaohongshu (Little Red Book) automation
Project description
xhs-mcp
一个小红书的 MCP 服务器,支持通过对话的方式进行账号登陆、文案生成、以及自动发布。相比于已有的实现,优势在于登陆账号以及文案发布全部可以在对话过程中自动实现,并能支持多个账号批量发布文案。此外,在调用发表文章的接口时,该工具还支持自动根据文案内容生成小红书配图。
原理
使用浏览器模拟的方式,通过 Chrome 驱动启动浏览器,来自动进行账号登录(会发送验证码到手机上),以及发布文案。登录后,会将 Cookie 保存下来,之后发布文章就不再需要重新登录了。项目已集成 webdriver-manager,无需手动下载和配置 Chrome 驱动,只需下载并安装 Chrome 浏览器本体即可(下载地址:https://www.google.com/intl/zh-CN/chrome/)。
示例
环境配置
- 确保系统已安装 Chrome 浏览器(项目会自动管理对应的驱动程序,不需要手动下载驱动程序,只要手动下载并安装浏览器本体即可),下载地址(https://www.google.com/intl/zh-CN/chrome/)
- 安装 uv
pip install uv # 注意,如果使用conda进行环境管理,需要在base环境中pip
启动服务器
在发布图文时,必须有一张配图才可以发布。所以在调用发布文案工具时会自动根据文案生成一张小红书风格的配图。在生成小配图时,用到了 DeepSeek 的 chat 模型,所以需要配置 DEEPSEEK_API_KEY 这个环境变量。如果需要切换到其它模型,请配置 BASE_URL 环境变量(默认为 DEEPSEEK 的地址),,并将"DEEPSEEK_API_KEY"设为对应的密钥即可。
方式 1: 配置文件运行
在配置文件中添加
{
"mcpServers": {
"xhs": {
"command": "uvx",
"args": [
"--from",
"lcl_xhs_mcp@latest",
"xhs-server"
],
"env": {
"DEEPSEEK_API_KEY": "xxxx",
"BASE_URL": "https://api.deepseek.com"
}
}
}
}
方式 2:直接运行命令
env DEEPSEEK_API_KEY=xxxx uvx --from lcl_xhs_mcp@latest xhs-server
若切换模型:
env DEEPSEEK_API_KEY=xxxx BASE_URL=xxxx uvx --from lcl_xhs_mcp@latest xhs-server
方式 3: 源码安装并运行
这种方式能够获得最新的代码。
git clone https://github.com/SoftEgLi/xhs-mcp.git
cd xhs-mcp
pip install -e . # 注意,如果安装了anaconda,需要在base环境中进行pip
MCP 配置文件:
{
"mcpServers": {
"xhs-test": {
"command": "xhs-server",
"args": [],
"env": {
"DEEPSEEK_API_KEY": "xxxx",
"BASE_URL": "https://api.deepseek.com"
}
}
}
}
注意事项
Cookie 的有效期是一个月,如果你自己在网页上登录了小红书,那么之前的 Cookie 有可能会失效,失效后在发布文章时,会重新走一遍 MCP 的登录流程。
开源协议
使用 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 mcpcn_lcl_xhs_mcp-0.4.5.tar.gz.
File metadata
- Download URL: mcpcn_lcl_xhs_mcp-0.4.5.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bffc3d5d5cb7fec15c107e2002d5f1da48ee3502c30751108e49b37a3264d8a0
|
|
| MD5 |
deca82233ac4c9f895c07b9a494bb83e
|
|
| BLAKE2b-256 |
61e671307e7d60d3b8f263f62a297dcc9bbc95be210d529c11ff9cb30564dd28
|
File details
Details for the file mcpcn_lcl_xhs_mcp-0.4.5-py3-none-any.whl.
File metadata
- Download URL: mcpcn_lcl_xhs_mcp-0.4.5-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
574975b38df90b155b5d2535073ac63dd23ae3bed2d4a5f02de4e2455683ca5e
|
|
| MD5 |
748d6a7f8109e9997cbe4105efe3826a
|
|
| BLAKE2b-256 |
38c6b61b0c9d287d196d8d6f06777f385ce92e9d8ba216bccc2008c5cf3ecebb
|