How to Configure the xiaohongshu-mcp Docker Container with Cookies: A Complete Guide

Use the agent-reach configure xhs-cookies command to inject XiaoHongShu session cookies directly into the running Docker container, supporting both Cookie-Editor JSON exports and HTTP header string formats.

The Agent-Reach repository provides a streamlined CLI toolchain for automating XiaoHongShu (Little Red Book) interactions through containerized services. To enable authenticated operations like searching and commenting through the headless browser, you must configure the xiaohongshu-mcp Docker container with cookies extracted from your active browser session.

Why Cookies Are Required for xiaohongshu-mcp

The xiaohongshu-mcp service runs a headless browser inside a Docker container to execute authenticated requests. Without valid session cookies, the container cannot maintain login state, preventing access to user-specific features. When properly configured, the XiaoHongShuChannel class (defined in agent_reach/channels/xiaohongshu.py, lines 22-38) detects the active MCP backend through its _check_mcp method and routes all channel operations through the containerized service.

Prerequisites for Configuration

Before running the configuration command, ensure you have:

  • Docker installed and the xiaohongshu-mcp container actively running
  • Valid XiaoHongShu cookies exported from your browser using Cookie-Editor or similar extensions
  • Agent-Reach CLI installed and accessible in your PATH

The _configure_xhs_cookies function in agent_reach/cli.py (lines 53-122) automatically detects and normalizes two input formats:

  • Cookie-Editor JSON Export: An array of cookie objects containing name, value, domain, path, and other standard fields
  • HTTP Header String: Semicolon-delimited key-value pairs (e.g., sessionid=abc123; userid=xyz789)

The CLI first checks if the input starts with [ to identify JSON format (lines 53-78). If parsing fails or the input matches header format, it falls back to parsing as an HTTP header string (lines 97-122).

Step-by-Step Configuration Process

Exporting Cookies from Your Browser

First, extract your active XiaoHongShu session cookies using the Cookie-Editor browser extension:


# Example HTTP Header String output from Cookie-Editor

"xhsweb_session=abc123def456; xhsweb_t=ghi789jkl012; ..."

Injecting Cookies via the CLI

Pass the cookie string directly to the configuration command:

agent-reach configure xhs-cookies "xhsweb_session=abc123; xhsweb_t=def456"

For JSON format exports:

agent-reach configure xhs-cookies '[{"name":"xhsweb_session","value":"abc123","domain":".xiaohongshu.com","path":"/"}]'

How the CLI Handles Docker Integration

According to the source code in agent_reach/cli.py, the configuration command executes seven distinct operations:

  1. Input Detection (lines 53-78): Validates JSON array format or falls back to header string parsing
  2. Normalization (lines 84-119): Re-encodes cookies into the standardized JSON array format expected by the MCP service
  3. Docker Verification (lines 133-144): Checks for docker executable via shutil.which("docker"); if missing, saves to ~/.agent-reach/xhs-cookies.json with manual copy instructions
  4. Container Discovery (lines 162-174): Executes docker ps --filter name=xiaohongshu-mcp to verify the container is running
  5. Path Resolution (lines 176-188): Retrieves the COOKIES_PATH environment variable from the container (defaults to /app/cookies.json if undefined)
  6. File Injection (lines 190-218): Creates a temporary file, writes the JSON array, and uses docker cp to transfer it into the container, followed by docker restart to reload the service
  7. Verification (lines 224-240): Optionally invokes mcporter call xiaohongshu.check_login_status() to confirm authenticated access

Verification and Troubleshooting

After configuration, the CLI automatically attempts to verify the login status. You can also manually check the connection:

mcporter call xiaohongshu.check_login_status()

When successful, the XiaoHongShuChannel health check (_check_mcp in agent_reach/channels/xiaohongshu.py, lines 214-226) reports that the "xiaohongshu-mcp 服务运行中" (service is running), indicating the channel is ready for authenticated operations.

If Docker is not installed locally, the CLI saves cookies to ~/.agent-reach/xhs-cookies.json and outputs manual copy instructions:

[!] Docker not found.
✅ Cookies saved to /home/user/.agent-reach/xhs-cookies.json
Docker not found. Copy manually:
docker cp /home/user/.agent-reach/xhs-cookies.json xiaohongshu-mcp:/app/data/cookies.json

Summary

  • The agent-reach configure xhs-cookies command automates cookie injection into the xiaohongshu-mcp Docker container without requiring manual volume mounts
  • Input flexibility: Accepts both Cookie-Editor JSON exports and HTTP header strings, normalizing them in agent_reach/cli.py (lines 53-122)
  • Automatic container management: Detects running containers, resolves the COOKIES_PATH environment variable, and restarts the service to reload credentials
  • Graceful degradation: Falls back to local file output with manual instructions when Docker is unavailable
  • Health verification: Integrates with mcporter to confirm login status and activates the XiaoHongShuChannel backend in agent_reach/channels/xiaohongshu.py

Frequently Asked Questions

What file path does the xiaohongshu-mcp container use for cookies?

The container determines its cookie storage location through the COOKIES_PATH environment variable. If undefined, the CLI defaults to /app/cookies.json (as implemented in agent_reach/cli.py, lines 176-188).

Can I configure cookies without Docker installed on my machine?

Yes. If the CLI cannot locate the Docker executable via shutil.which("docker"), it writes the normalized cookie JSON to ~/.agent-reach/xhs-cookies.json and provides the exact docker cp command needed to manually transfer the file to the container (agent_reach/cli.py, lines 133-144).

How do I verify that my cookies are working correctly?

The configuration command automatically runs mcporter call xiaohongshu.check_login_status() if the mcporter CLI is available (lines 224-240). You can also manually invoke this command after configuration to confirm the session is valid.

What happens if the xiaohongshu-mcp container is not running?

The CLI aborts the operation and prints the recommended docker run command to start the container (agent_reach/cli.py, lines 162-174). The cookies are not written until the container is active and detectable via docker ps.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →