Beyond the Sandbox: Connecting Your AI Assistant to Xiaohongshu with MCP
The xiaohongshu-mcp repository is an implementation of the Model Context Protocol (MCP) specifically for Xiaohongshu (Red).
Before diving into the code, let's talk shop. Usually, AI models are "trapped" in a box—they only know what they were trained on. If you want them to interact with a specific platform like Xiaohongshu, you’d traditionally have to write custom API wrappers every single time.
MCP (Model Context Protocol) changes that. It's an open standard that allows AI assistants (like Claude Desktop or other IDE-based LLMs) to connect directly to external data and tools. By using this specific MCP server, you are essentially giving your AI a "plugin" to read or interact with Xiaohongshu data seamlessly.
Automated Market Research
You can build tools that ask an AI to "Summarize the top 10 trending posts about mechanical keyboards on Xiaohongshu."
Content Analysis
Use it to fetch post details for sentiment analysis or trend tracking without manually scraping the site.
Standardized Integration
Since it follows the MCP standard, once you set it up, any MCP-compatible client can use it. No more reinventing the wheel for every project.
To use this, you'll generally need Node.js installed, as most MCP servers are built with TypeScript/JavaScript.
First, clone the repository and install the dependencies
git clone https://github.com/xpzouying/xiaohongshu-mcp.git
cd xiaohongshu-mcp
npm install
If you are using an MCP client like Claude Desktop, you would add the server to your configuration file (usually claude_desktop_config.json)
{
"mcpServers": {
"xiaohongshu": {
"command": "node",
"args": ["/path/to/xiaohongshu-mcp/build/index.js"],
"env": {
"XHS_COOKIE": "your_cookie_here"
}
}
}
}
> Pro Tip: You'll need to grab your cookie from a browser session on xiaohongshu.com to authenticate the requests!
Once the server is running, your AI assistant can call "tools" provided by this server. While the exact tools depend on the repo's latest updates, a typical "Search" call might look like this internally
// Example of how the MCP server might handle a search request
async function searchXHS(query: string) {
const results = await xhsClient.search({
keyword: query,
sortBy: "general", // or 'hot'
page: 1
});
return results.map(post => ({
title: post.title,
author: post.user.nickname,
likes: post.stats.likeCount
}));
}
If you were talking to an AI configured with this server, you could simply say
"Hey, find me the most popular posts about 'minimalist desk setups' from the last week and tell me what common items they feature."
The AI would use the MCP server to fetch the raw data, parse it, and give you the summary.
| Feature | Benefit |
| Protocol | Standardized (MCP), so it works with many AI clients. |
| Data Source | Direct access to Xiaohongshu (Red) content. |
| Efficiency | No need to write custom scrapers or API handlers from scratch. |
It’s a neat way to bridge the gap between "Static AI" and "Live Social Data."