xianyu-buyer-mcp
Enables AI agents to interact with Goofish (闲鱼) marketplace, supporting product search, batch inquiry messaging, and conversation management for buyers.
README
xianyu-buyer-mcp
闲鱼(Goofish)买家侧询价 MCP Server。支持搜索商品、批量发送询价消息、自动回收卖家回复。
功能
| 工具 | 说明 |
|---|---|
login |
扫码登录闲鱼(首次需要,后续自动复用 cookies) |
check_login |
检查登录状态 |
search |
搜索商品,返回商品列表 + 卖家 ID |
send_inquiry |
向单个卖家发送询价消息 |
batch_send_inquiry |
批量发送询价消息 |
get_conversations |
获取 IM 对话列表,查看所有卖家回复 |
get_conversation_detail |
获取与某个卖家的完整聊天记录 |
安装
前置条件
- Python 3.11+
- 闲鱼/淘宝app(用于扫码登录)
- 闲鱼网页版/淘宝桌面端(用于接受与回复消息)
步骤
# 1. 克隆项目
git clone https://github.com/<your-username>/xianyu-buyer-mcp.git
cd xianyu-buyer-mcp
# 2. 安装依赖
pip install -e .
# 3. 安装 Chromium 浏览器
playwright install chromium
可选配置
复制环境变量模板并按需修改:
cp .env.example .env
| 变量 | 默认值 | 说明 |
|---|---|---|
PLAYWRIGHT_HEADLESS |
false |
是否无头模式(建议保持 false 以便扫码) |
PROXY |
(空) | HTTP 代理地址 |
COOKIES_PATH |
~/.xianyu-buyer-mcp/cookies.json |
Cookie 存储路径 |
XIANYU_HOME_URL |
https://www.goofish.com |
闲鱼首页 URL |
在 MCP 客户端中使用
Claude Desktop / Cursor / QoderWork
在 MCP 配置文件中添加:
{
"mcpServers": {
"xianyu-buyer": {
"command": "python",
"args": ["/path/to/xianyu-buyer-mcp/server.py"]
}
}
}
首次使用
- 在 AI 助手中调用
login工具 - 浏览器窗口会自动弹出闲鱼登录页
- 用闲鱼或淘宝 App 扫码登录
- Cookies 自动保存到
~/.xianyu-buyer-mcp/cookies.json - 后续使用无需重复扫码
典型流程
# 1. 登录
login()
# 2. 搜索商品
search("MacBook Pro M1 16G 512G", max_price=5000)
# 3. 批量询价
batch_send_inquiry(
items='[{"itemId": "xxx", "sellerId": "yyy"}, ...]',
message="你好,还在吗?"
)
# 4. 查看回复
get_conversations()
# 5. 查看某个对话详情
get_conversation_detail(item_id="xxx", seller_id="yyy")
技术细节
- 反检测: 使用 playwright-stealth + 自定义 UA + navigator 伪造,降低被识别为机器人的风险
- CAPTCHA 规避: 卖家信息查询通过 IM 页面的
lib.mtop.requestSDK 完成,避免商品详情页触发滑块验证 - 频率控制: 批量发送消息间隔 2 秒,避免触发平台风控
- 线程安全: 所有浏览器操作在单线程 executor 中序列化执行
注意事项
- 闲鱼有反爬机制,请勿高频调用或用于大规模数据采集
- Cookies 有效期有限,过期后需重新扫码
- 本项目仅供学习研究,请遵守闲鱼平台的使用条款
License
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.