Astron-Xiaohongshu-MCP: 基于小红书公开网页与 __INITIAL_STATE__ 解析的自包含 MCP Server,支持 MCP 协议和 uvx 一键启动。
Project description
小红书公开内容 MCP Server
概述
Astron-xiaohongshu-mcp 是一个基于 MCP 协议的小红书工具服务,直接请求公开网页并解析 window.__INITIAL_STATE__,无需浏览器依赖或额外后端。
当前工程形态:
- 使用
MCP Python SDK - 使用单文件
server.py承载工具定义、请求封装和解析逻辑 - 通过独立
pyproject打包 - 支持
uvx一键启动 - 通过环境变量配置超时和 User-Agent
当前提供 6 个原子工具:
get_hot_listget_feed_listsearch_contentget_content_detailget_author_profileget_author_content_list
工具列表
1. 获取热榜 get_hot_list
- 描述:基于首页首屏公开内容做热度排序后返回。
- 参数:
limit:返回条数,默认20refresh:是否刷新,默认False
2. 获取内容流 get_feed_list
- 描述:读取首页首屏公开内容流。
- 参数:
channel:兼容参数,当前未启用cursor:分页游标,当前仅支持首屏(cursor非空时可能返回空结果)limit:返回条数,默认20refresh:是否刷新,默认False
3. 搜索内容 search_content
- 描述:搜索公开内容(MVP,本地关键词过滤)。
- 参数:
query:搜索词,必填cursor:兼容参数,当前未启用limit:返回条数,默认20
4. 获取内容详情 get_content_detail
- 描述:读取单条内容详情页并解析公开字段。
- 参数:
content_id:内容 IDurl:内容完整 URL
5. 获取作者主页 get_author_profile
- 描述:读取作者公开主页信息。
- 参数:
author_id:作者 IDurl:作者主页 URL
6. 获取作者公开内容列表 get_author_content_list
- 描述:读取作者主页公开内容列表。
- 参数:
author_id:作者 IDurl:作者主页 URLcursor:分页游标,当前仅支持首屏limit:返回条数,默认20
搜索能力说明
由于小红书公开搜索页在游客态场景下可能存在访问限制或结果不稳定,search_content 当前采用 MVP 策略:
- 先抓取首页首屏公开内容;
- 在本地对标题、摘要、正文、作者名、标签进行关键词过滤;
- 返回过滤后的结构化列表结果。
这意味着:
- 结果覆盖范围主要受“首屏样本”限制;
- 不保证等价于平台全站搜索;
- 适合“轻量检索 + 工具链联动”的基础场景。
环境变量
这个包默认不需要认证信息。
可选环境变量:
export XIAOHONGSHU_MCP_TIMEOUT_SECONDS="30"
export XIAOHONGSHU_MCP_USER_AGENT="Mozilla/5.0 ..."
说明:
XIAOHONGSHU_MCP_TIMEOUT_SECONDS控制页面请求超时。XIAOHONGSHU_MCP_USER_AGENT用于覆盖默认请求头。
安装与启动
推荐方式:使用 uvx 一键启动
uvx --from astron-xiaohongshu-mcp astron-xiaohongshu-mcp
如果你还没有安装 uv / uvx,可先执行:
curl -fsSL https://install.astral.sh/uv | bash
使用 pip 安装
pip install astron-xiaohongshu-mcp
xiaohongshu-mcp
本地源码运行
cd MCP/xiaohongshu-mcp
PYTHONPATH=src python3 -m xiaohongshu_mcp.server
客户端配置
使用 uvx
{
"mcpServers": {
"xiaohongshu-mcp": {
"command": "uvx",
"args": ["--from", "astron-xiaohongshu-mcp", "astron-xiaohongshu-mcp"],
"env": {
"XIAOHONGSHU_MCP_TIMEOUT_SECONDS": "30"
}
}
}
}
使用本地源码
{
"mcpServers": {
"xiaohongshu-mcp": {
"command": "python3",
"args": ["-m", "xiaohongshu_mcp.server"],
"env": {
"PYTHONPATH": "/path/to/MCP/xiaohongshu-mcp/src",
"XIAOHONGSHU_MCP_TIMEOUT_SECONDS": "30"
}
}
}
}
平台差异说明
- 当前实现只使用
requests + HTML 解析,不依赖浏览器自动化。 - 解析核心依赖页面脚本中的
window.__INITIAL_STATE__;如页面结构变更,需要同步更新解析逻辑。 - 仅面向游客态公开内容能力,不包含登录态、私有内容或用户专属数据。
发布说明
cd MCP/xiaohongshu-mcp
rm -rf build dist src/*.egg-info
python3 -m build --no-isolation
python3 -m twine check dist/*
python3 -m twine upload dist/*
License
Apache License 2.0. See LICENSE.
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 astron_xiaohongshu_mcp-0.1.2.tar.gz.
File metadata
- Download URL: astron_xiaohongshu_mcp-0.1.2.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31e72e667b6b5045b3b8372439930027348f9dd1ebfe779d8c8a7a9279286669
|
|
| MD5 |
0b5e589afcc611570b4fa62f5116c199
|
|
| BLAKE2b-256 |
6fe212dc930a83b531f89664dcbd50adbf37427f3775c293105e01356d6b1aba
|
File details
Details for the file astron_xiaohongshu_mcp-0.1.2-py3-none-any.whl.
File metadata
- Download URL: astron_xiaohongshu_mcp-0.1.2-py3-none-any.whl
- Upload date:
- Size: 15.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7f3578ca512794369e4405ddeb88a009d2c9a17ba3051c48a1d6ebbe409984f
|
|
| MD5 |
0eab32412e1f3c13d00eef6a64bb78d1
|
|
| BLAKE2b-256 |
54d0e4fd7e56a827823941f9e8f32e60e80ad6db93693d1591cd87d7fe39fa18
|