Skip to main content
Glama
Xiaohongshu MCP Server

Xiaohongshu MCP Server

by muhenan

小红书 MCP Python 项目

这是一个基于 Model Context Protocol (MCP) 的小红书自动化工具,提供登录、状态检查和内容发布功能。

功能特性

  • 登录功能 - 支持扫码登录小红书账号

  • 状态检查 - 快速检查当前登录状态

  • 内容发布 - 自动发布图文内容到小红书

  • MCP 集成 - 完整的 MCP 服务器实现,可与 AI 客户端(例如 Cursor、Claude Code、Codex)集成

Related MCP server: XiaoHongShu MCP

安装要求

  • Python >= 3.10

  • 已安装 Chrome 浏览器

  • uv 包管理器(推荐)

快速开始

安装依赖

# 使用 uv 安装(推荐)
uv sync

# 或使用 pip
pip install -e .

安装 Playwright 浏览器

uv run playwright install chromium

最简单启动(开发模式)

uv run mcp dev src/xiaohongshu_mcp/server.py

等价的生产脚本启动方式:

uv run xiaohongshu-mcp-server

使用方式

方式一:独立命令行工具

1. 登录小红书

# 使用有界面模式登录(推荐)
uv run xiaohongshu-login

# 使用无头模式登录
uv run xiaohongshu-login --headless

2. 检查登录状态

uv run xiaohongshu-status

3. 发布内容

uv run xiaohongshu-publish \
  --title "我的标题" \
  --content "这是正文内容" \
  --images "image1.jpg" "image2.png"

方式二:MCP 服务器

启动 MCP 服务器,可与支持 MCP 协议的 AI 客户端(例如 Cursor、Claude Code、Codex)集成:

# 启动开发模式 MCP 服务器
uv run mcp dev src/xiaohongshu_mcp/server.py

# 或使用脚本启动
uv run xiaohongshu-mcp-server

MCP 工具说明

服务器提供三个 MCP 工具:

  1. xiaohongshu_login - 登录小红书账号

    • headless: bool - 是否使用无头模式(默认:False)

    • chrome_path: str - Chrome 路径(可选)

  2. xiaohongshu_check_status - 检查登录状态

    • headless: bool - 是否使用无头模式(默认:True)

    • chrome_path: str - Chrome 路径(可选)

  3. xiaohongshu_publish - 发布内容

    • title: str - 标题(必填,<=40字符)

    • content: str - 正文内容(必填)

    • image_paths: List[str] - 图片路径列表(必填)

    • headless: bool - 是否使用无头模式(默认:False)

    • chrome_path: str - Chrome 路径(可选)

配置说明

登录状态保存

登录状态通过 cookies 保存在:

~/.xiaohongshu_mcp/cookies.json

日志配置

MCP 服务器日志保存在:

logs/mcp_server.log

支持的图片格式

  • JPG/JPEG

  • PNG

  • GIF

  • WebP

项目结构

src/xiaohongshu_mcp/
├── browser/              # 浏览器管理模块
│   ├── cookies.py       # Cookie 管理
│   └── driver.py        # 浏览器驱动
├── xiaohongshu/         # 小红书功能模块
│   ├── login.py         # 登录功能
│   └── publish.py       # 发布功能
├── server.py            # MCP 服务器
├── login.py             # 登录命令行工具
├── check_status.py      # 状态检查工具
└── publish.py           # 发布命令行工具

注意事项

  • 发布功能建议使用有界面模式,便于观察发布过程

  • 首次使用需要扫码登录

  • 图片文件必须存在且格式正确

  • 标题长度不能超过 40 个字符

故障排除

常见问题

  1. 登录失败

    • 确保网络连接正常

    • 尝试清除 cookies 后重新登录

    • 检查 Chrome 浏览器是否正常安装

  2. 发布失败

    • 确认已登录状态

    • 检查图片文件路径和格式

    • 验证标题和内容长度

  3. MCP 服务器启动失败

    • 确保安装了 mcp[cli] 依赖

    • 检查日志文件查看详细错误信息

技术栈

  • Python 3.10+ - 主要开发语言

  • Playwright - 浏览器自动化

  • MCP Python SDK - Model Context Protocol 支持

  • Loguru - 日志管理

  • Pydantic - 数据验证

  • uv - 包管理器

许可证

本项目基于 MIT 许可证开源。

Available Tools

3 tools
xiaohongshu_check_statusC

检查小红书登录状态

Args: headless: 是否使用无头模式,默认True(状态检查可使用无头模式) chrome_path: Chrome浏览器可执行文件路径,可选

Returns: 登录状态信息

Inputs: chrome_path, headless. Returns: result

xiaohongshu_loginC

登录小红书账号

Args: headless: 是否使用无头模式,默认False(建议使用有界面模式进行扫码) chrome_path: Chrome浏览器可执行文件路径,可选

Returns: 登录结果消息

Inputs: chrome_path, headless. Returns: result

xiaohongshu_publishC

发布小红书内容

Args: title: 标题(必填,不超过40个字符) content: 正文内容(必填) image_paths: 图片路径列表(必填,支持jpg/jpeg/png/gif/webp格式) headless: 是否使用无头模式,默认False(建议使用有界面模式观察发布过程) chrome_path: Chrome浏览器可执行文件路径,可选

Returns: 发布结果消息

Inputs: content (required), image_paths (required), title (required), chrome_path, +1 more. Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.1/5.0

    Scored across 3 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose: check_status verifies login state, login performs authentication, and publish creates content. There is no overlap in functionality, and the descriptions clearly differentiate their roles in the Xiaohongshu workflow.

    Naming Consistency5/5

    All tools follow a consistent 'xiaohongshu_verb' pattern with snake_case naming: xiaohongshu_check_status, xiaohongshu_login, and xiaohongshu_publish. This uniformity makes the tool set predictable and easy to understand.

    Tool Count2/5

    With only 3 tools, the server feels thin for a social media platform like Xiaohongshu. It covers basic login and posting but lacks essential operations such as reading, updating, deleting content, or interacting with other users, limiting its utility for comprehensive agent workflows.

    Completeness2/5

    The tool set is severely incomplete for the Xiaohongshu domain. It only supports login and publishing, missing core CRUD operations like retrieving posts, editing content, deleting posts, browsing feeds, or managing interactions (e.g., likes, comments). This will cause significant agent failures in typical social media tasks.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables interaction with Xiaohongshu (Little Red Book) platform through automated browser operations. Supports authentication, content publishing, search, discovery, and commenting using Puppeteer-based automation.
      546 npm
      58
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to publish content to XiaoHongShu (Little Red Book) social platform, including checking login status and posting with titles, content, images, and hashtags through browser automation.
      4
      ISC
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables automated interaction with Xiaohongshu (Little Red Book) platform including searching posts, retrieving content and comments, and posting AI-generated comments with persistent login support.
      460
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables automated interaction and data scraping for Xiaohongshu (RedNote), including posting, liking, commenting, following, and retrieving user and note data.
      5
      MIT