Skip to main content

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 sync
uv run xhs --help

Install from PyPI (Recommended)

uv tool install xiaohongshu-aio

Install and Start MCP Server

  1. Download MCP server: xhs mcp download
  2. Start MCP server: xhs mcp start
  3. 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 client
  • typer - Command-line interface
  • pydantic - Data validation
  • pydantic-settings - Settings management
  • rich - 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xiaohongshu_aio-0.1.6.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

xiaohongshu_aio-0.1.6-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file xiaohongshu_aio-0.1.6.tar.gz.

File metadata

  • Download URL: xiaohongshu_aio-0.1.6.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for xiaohongshu_aio-0.1.6.tar.gz
Algorithm Hash digest
SHA256 c1b1312c19ef3db26690aefdb05ec1e0cae018c0a0d336043a9195c85b9ad17e
MD5 45897a2fc83d89e423cd007c98a050f1
BLAKE2b-256 2d8b3c4c5768835582b5ca1189ac96bd21472cc0da898fdcbe7c7ba628757730

See more details on using hashes here.

File details

Details for the file xiaohongshu_aio-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for xiaohongshu_aio-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 0eee65fd45cb8c71df1e5d70e7501c008e77bdd165831e3f2b985bf9cd113b00
MD5 c371badba3aeb31eb509a502bfd3b0f1
BLAKE2b-256 7f29551572baad26231292e67fe73333d7ca06456ab3ac847bef2faba8680a83

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