Skip to main content

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

当前提供 5 个原子工具:

  • get_hot_list
  • get_feed_list
  • get_content_detail
  • get_author_profile
  • get_author_content_list

工具列表

1. 获取热榜 get_hot_list

  • 描述:基于首页首屏公开内容做热度排序后返回。
  • 参数:
    • limit:返回条数,默认 20
    • refresh:是否刷新,默认 False

2. 获取内容流 get_feed_list

  • 描述:读取首页首屏公开内容流。
  • 参数:
    • channel:兼容参数,当前未启用
    • cursor:分页游标,当前仅支持首屏(cursor 非空时可能返回空结果)
    • limit:返回条数,默认 20
    • refresh:是否刷新,默认 False

3. 获取内容详情 get_content_detail

  • 描述:读取单条内容详情页并解析公开字段。
  • 参数:
    • content_id:内容 ID
    • url:内容完整 URL

4. 获取作者主页 get_author_profile

  • 描述:读取作者公开主页信息。
  • 参数:
    • author_id:作者 ID
    • url:作者主页 URL

5. 获取作者公开内容列表 get_author_content_list

  • 描述:读取作者主页公开内容列表。
  • 参数:
    • author_id:作者 ID
    • url:作者主页 URL
    • cursor:分页游标,当前仅支持首屏
    • limit:返回条数,默认 20

环境变量

这个包默认不需要认证信息。

可选环境变量:

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"
      }
    }
  }
}

平台差异说明

  1. 当前实现只使用 requests + HTML 解析,不依赖浏览器自动化。
  2. 解析核心依赖页面脚本中的 window.__INITIAL_STATE__;如页面结构变更,需要同步更新解析逻辑。
  3. 仅面向游客态公开内容能力,不包含登录态、私有内容或用户专属数据。

发布说明

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

astron_xiaohongshu_mcp-0.1.5.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

astron_xiaohongshu_mcp-0.1.5-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file astron_xiaohongshu_mcp-0.1.5.tar.gz.

File metadata

  • Download URL: astron_xiaohongshu_mcp-0.1.5.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0rc1

File hashes

Hashes for astron_xiaohongshu_mcp-0.1.5.tar.gz
Algorithm Hash digest
SHA256 3948fb5c45def6c569203750ffd442aea037c1df4c02eca225af6640e03f98eb
MD5 0b4f5d02ee4332698fa8bf1f1045b78f
BLAKE2b-256 66d6cb88bbf0eb541c346df88a85ac75cc39bafa9513eb6537ea08b429b1221f

See more details on using hashes here.

File details

Details for the file astron_xiaohongshu_mcp-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for astron_xiaohongshu_mcp-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 31a88252f807e19db2bca11ceea5f02416481943658491f5324eaa6930c0cff6
MD5 80ce90006af07d63a02d94ea4f876400
BLAKE2b-256 e03bd4345c5bfe06d02391ddf6cf3e36839554bc0cf0c60cf11a0f7cf195cf88

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page