Xiaohongshu MCP REST API Client
Project description
Xiaohongshu MCP Client
English | 简体中文
A Python client for Xiaohongshu MCP (Model Context Protocol) REST API, providing a comprehensive command-line interface for managing Xiaohongshu accounts and interacting with the platform.
Features
-
Account Management
- Add, remove, list, and switch between multiple accounts
- Import and export cookies
- Track last used time and account notes
- Automatic username detection - auto-detects current login nickname when username is not provided
- Current account management - easily check and switch between accounts
-
Login Management
- Check login status
- Get login QR code
- Logout (clear cookies)
-
Content Publishing
- Publish image content with images and tags
- Publish video content
- Support for visibility settings
-
Feed Management
- List recommended feeds
- Search feeds by keyword
- Get detailed feed information
-
Interaction
- Post comments on feeds
- Reply to comments on feeds
-
User Information
- Get current user profile
- Get other user profiles
Installation
Prerequisites
- Python 3.12+
- Xiaohongshu MCP server running (default:
http://localhost:18060)
Install from source
cd xiaohongshu-aio
uv pip install -e .
Install from PyPI (Recommended)
pip install -U xiaohongshu-aio
Install and Start MCP Server
- Download MCP server:
xhs mcp download - Start MCP server:
xhs mcp start - Check status:
xhs mcp status
Usage
Command Structure
xhs <command> [options]
Account Management
# List all accounts
xhs account list
# Add a new account (auto-detects username from current login)
xhs account add
# Add a new account with custom username and notes
xhs account add --username myaccount --notes "My personal account"
# Remove an account
xhs account remove --username myaccount
# Switch to another account
xhs account switch --username myaccount
# Import cookies for an account (auto-detects username)
xhs account import
# Import cookies with custom username
xhs account import --username myaccount
# Get current account
xhs account current
Login Management
# Check login status
xhs login status
# Check login status with custom server URL
xhs login status --base-url http://localhost:18060
# Get login QR code
xhs login qrcode
# Logout
xhs login logout
Publishing Content
# Publish image content
xhs publish "Title" "Content" "https://example.com/image1.jpg" "https://example.com/image2.jpg" --tags food travel
# Publish video content
xhs publish "Video Title" "Video content" "C:\path\to\video.mp4" --is-video
# Publish with custom server URL
xhs publish "Title" "Content" "https://example.com/image.jpg" --base-url http://localhost:18060
Feed Management
# List feeds
xhs feed list
# Search feeds
xhs feed search --keyword "coffee"
# Get feed detail
xhs feed detail --feed-id "feed123" --xsec-token "token123"
# Use custom server URL
xhs feed list --base-url http://localhost:18060
Interaction
# Post a comment
xhs interact comment "feed123" "token123" --content "Great post!"
# Reply to a comment
xhs interact reply "feed123" "token123" --comment-id "comment_id" --content "Reply content"
# Use custom server URL
xhs interact comment "feed123" "token123" --content "Great post!" --base-url http://localhost:18060
User Information
# Get current user profile
xhs user me
# Get other user profile
xhs user profile --user-id "user123" --xsec-token "token123"
# Use custom server URL
xhs user me --base-url http://localhost:18060
MCP Server Management
# Download MCP server
xhs mcp download
# Test MCP connection
xhs mcp test
# Start MCP server
xhs mcp start
# Stop MCP server
xhs mcp stop
# Restart MCP server
xhs mcp restart
# Check MCP server status
xhs mcp status
Configuration
You can configure the client using environment variables:
| Environment Variable | Default Value | Description |
|---|---|---|
XHS_MCP_BASE_URL |
http://localhost:18060 |
MCP server base URL (preferred) |
XHS_BASE_URL |
http://localhost:18060 |
MCP server base URL (fallback) |
XHS_TIMEOUT |
60 |
HTTP request timeout in seconds |
XHS_VERIFY_SSL |
true |
Whether to verify SSL certificates |
Project Structure
xiaohongshu-aio/
├── src/
│ └── xiaohongshu_aio/
│ ├── __init__.py # Package initialization
│ ├── client.py # REST API client
│ ├── account.py # Account management
│ ├── cli.py # Command-line interface
│ └── mcp_service.py # MCP server management
├── pyproject.toml # Project configuration
├── README.md # This file
├── README_en.md # English README
└── user_cookies.json # Account cookies storage
Dependencies
httpx- Modern HTTP clienttyper- Command-line interfacepydantic- Data validationpydantic-settings- Settings managementrich- Rich console output
Acknowledgments
This project is based on the xiaohongshu-mcp project. Thanks to the original project author for their contribution.
License
MIT
Project details
Release history Release notifications | RSS feed
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 xiaohongshu_aio-0.1.5.tar.gz.
File metadata
- Download URL: xiaohongshu_aio-0.1.5.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f13c41a869dfa3eef1be315679742710906bf54a1cede08f5916fba651f8a399
|
|
| MD5 |
528e45620e5425ceb27f73ed8234e245
|
|
| BLAKE2b-256 |
cf415a1653ee72802c76f51816a75921efd5e900bc8da217ff9aae6343ad791d
|
File details
Details for the file xiaohongshu_aio-0.1.5-py3-none-any.whl.
File metadata
- Download URL: xiaohongshu_aio-0.1.5-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4e743350c05c1bcb14d5b7c43fe5ac9c6383d675ff72cbff56afebcb6e1af5e
|
|
| MD5 |
991c7a1350b5445062bdfcb75042deec
|
|
| BLAKE2b-256 |
efcb0ebb2f79d0d70cc174252b12813678a65b3bf77a0aaa0167ac4aa44ae6a7
|