xhs-mcp

English 简体中文

Unified CLI xhs-mcp with built-in MCP server subcommand. Automate XiaoHongShu (xiaohongshu.com) with Puppeteer: login, publishing, search, feed discovery, and commenting via MCP and CLI.

npm version npm downloads License: MIT

📦 NPM

✨ Features

📋 Tools

🚀 Quick Start (MCP)

npx xhs-mcp mcp

# Debug logs
XHS_ENABLE_LOGGING=true npx xhs-mcp mcp

First run tip: if Puppeteer browsers are not installed yet, run

npx xhs-mcp browser    # auto-check and install Chromium, shows executable path
# or
npx puppeteer browsers install chrome

Output example:

{
  "success": true,
  "message": "Chromium is ready",
  "data": {
    "installed": true,
    "executablePath": "/path/to/chromium"
  }
}

Verify MCP connection:

echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}' | npx xhs-mcp mcp

🧰 CLI

# Auth
npx xhs-mcp login --timeout 120
npx xhs-mcp logout
npx xhs-mcp status

# Browser
npx xhs-mcp browser  # check and install Chromium, shows executable path

# Discover
npx xhs-mcp feeds
npx xhs-mcp search -k keyword
npx xhs-mcp note-detail --feed-id <id> --xsec-token <token>
npx xhs-mcp comment --feed-id <id> --xsec-token <token> -n "Nice!"

# Publish with local images
npx xhs-mcp publish --type image --title Title --content Content -m path1.jpg,path2.png --tags a,b

# ⭐ Publish with image URLs (auto-download)
npx xhs-mcp publish --type image --title Title --content Content -m "https://example.com/img1.jpg,https://example.com/img2.png" --tags a,b

# Mix URLs and local paths
npx xhs-mcp publish --type image --title Title --content Content -m "https://example.com/img1.jpg,./local/img2.jpg" --tags a,b

# Video
npx xhs-mcp publish --type video --title Title --content Content -m video.mp4 --tags a,b

# Tools
npx xhs-mcp tools [--detailed] [--json]

# MCP Server
npx xhs-mcp mcp --mode http --port 3000

🔧 Client Integration (Cursor)

.cursor/mcp.json:

{
  "mcpServers": {
    "xhs-mcp": {
      "command": "npx",
      "args": ["xhs-mcp", "mcp"],
      "env": { "XHS_ENABLE_LOGGING": "true" }
    }
  }
}

⚠️ Notes

📖 Documentation and Examples

📚 Documentation

🛠️ Build Notes

🎨 Examples

🧪 Tests

🙏 Acknowledgments

Based on and extended from xiaohongshu-mcp (refactored to TypeScript, improved MCP implementation, log cleanup, published to NPM).