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

    • Like/unlike feeds
    • Favorite/unfavorite feeds
    • Post comments
  • 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
pip install -e .

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

# Like a feed
xhs interact like "feed123" "token123"

# Unlike a feed
xhs interact like "feed123" "token123" --unlike

# Favorite a feed
xhs interact favorite "feed123" "token123"

# Post a comment
xhs interact comment "feed123" "token123" --content "Great post!"

# Use custom server URL
xhs interact like "feed123" "token123" --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

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
├── 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.0.tar.gz (9.6 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.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for xiaohongshu_aio-0.1.0.tar.gz
Algorithm Hash digest
SHA256 01f2d05cd1d980c0d60e5af9119cfb7bcebaf7b92c6c8abaa9e8d8d47fc656e3
MD5 38a3672005487d161267da72bea911c9
BLAKE2b-256 a3e1f28e5df901bfa3f262149a902af81412d843c41ae11dc97f8b25c037d3d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for xiaohongshu_aio-0.1.0.tar.gz:

Publisher: python-package.yml on CN-P5/xiaohongshu-aio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for xiaohongshu_aio-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e79949e8ce2ccaf01d25b78de6dbefeaba3ece2b602455e84e1c05781849a9a
MD5 8c16728d123c45e2bcf9e249e518fbe5
BLAKE2b-256 449327148ea7e6a887b189466d86786c082527e9323c64a4ea9e71266eebff3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for xiaohongshu_aio-0.1.0-py3-none-any.whl:

Publisher: python-package.yml on CN-P5/xiaohongshu-aio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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