xianyu-mcp
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@xianyu-mcp搜索闲鱼 iPhone 15 Pro Max 256G 价格"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
闲鱼 MCP Server 🏪
让 AI Agent(如 OpenCode)能够通过 MCP 协议搜索闲鱼二手商品价格。
✨ 核心特性
🔍 搜索闲鱼二手价格 — 输入关键词,获取商品标题、价格、地区、链接
🍪 Cookie 全自动检测 — 不再需要手动导 Cookie!按优先级自动尝试 4 种方式:
从 Chrome 浏览器自动提取(已登录闲鱼时,全自动,无感)
从已保存的配置文件读取(之前登录过,自动复用)
从环境变量读取(服务器/CI 场景)
弹出浏览器窗口让您登录(首次无 Cookie + 有图形界面时,只需一次)
🔄 一次登录,永久使用 — 交互式登录成功后,Cookie 自动保存复用
⚡ 基于 Playwright — 可靠渲染闲鱼 SPA 页面,精确提取商品信息
Related MCP server: MCP Shop Server
📦 安装
# 1. 安装 Python 依赖
pip install -r /home/hesheng/projects/xianyu-mcp/requirements.txt
# 2. 安装 Playwright Chromium 浏览器
python -m playwright install chromium🚀 启动
# 方式一:直接启动
mcp run /home/hesheng/projects/xianyu-mcp/main.py
# 方式二:配置到 OpenCode在 opencode.jsonc 中添加:
{
"mcpServers": {
"xianyu-mcp": {
"command": "mcp",
"args": ["run", "/home/hesheng/projects/xianyu-mcp/main.py"]
}
}
}🎯 使用示例
在 OpenCode 中直接问:
「帮我搜一下闲鱼上 iPhone 15 Pro Max 256G 二手什么价」 「MacBook Air M3 在闲鱼上大概多少钱」 「索尼 A7M4 二手行情怎么样」
Agent 会自动调用 xianyu_search 工具,返回:
标题 | 价格 | 地区 | 链接 |
iPhone 15 Pro Max 256G 原色 99新 | ¥8,299 | 上海 | [查看] |
iPhone 15 Pro Max 256G 国行在保 | ¥7,999 | 深圳 | [查看] |
🍪 Cookie 获取方式(按自动化程度排序)
方式 1:从 Chrome 自动提取(全自动,推荐 ✅)
如果您的 Chrome 浏览器已经登录过闲鱼,MCP 会自动从 Chrome 的 Cookie 数据库中提取登录态,无需任何操作。
注意:此方式需要安装
keyring库以解密 Chrome 的加密 Cookie:pip install keyring如果未安装
keyring,MCP 会自动降级到方式 4。
方式 2:已保存的配置文件(自动复用)
如果您之前通过方式 4 登录过一次,Cookie 会自动保存到 ~/.config/xianyu/cookies.json,后续启动时自动复用,无需再次登录。
方式 3:环境变量(服务器/无界面环境)
export XIANYU_COOKIE='[{"name":"_m_h5_tk","value":"xxx"...}]'用 EditThisCookie 插件导出 JSON 后,将内容设为环境变量。
方式 4:弹窗登录(首次使用,有图形界面时)
如果以上方式都不可用,且系统有图形界面,MCP 会自动打开一个浏览器窗口,您扫码或登录闲鱼后,Cookie 自动捕获并保存。
🔧 自测试
# 检查语法
python -c "import ast; ast.parse(open('/home/hesheng/projects/xianyu-mcp/main.py').read()); print('Syntax OK')"
python -c "import ast; ast.parse(open('/home/hesheng/projects/xianyu-mcp/cookie_manager.py').read()); print('Syntax OK')"
python -c "import ast; ast.parse(open('/home/hesheng/projects/xianyu-mcp/browser.py').read()); print('Syntax OK')"
python -c "import ast; ast.parse(open('/home/hesheng/projects/xianyu-mcp/search.py').read()); print('Syntax OK')"
# 测试导入(仅测试无外部依赖的部分)
python -c "from cookie_manager import CookieManager; print('CookieManager 导入成功')"📁 项目结构
xianyu-mcp/
├── main.py # MCP 服务入口,FastMCP 定义 tools
├── cookie_manager.py # Cookie 自动检测(4 种方式链式尝试)
├── browser.py # Playwright 浏览器管理器(headless/headful 双模式)
├── search.py # 闲鱼搜索逻辑(页面加载 → 滚动 → DOM 解析)
├── __init__.py
├── requirements.txt
└── README.md⚠️ 注意事项
首次使用时,如果无 Cookie 且有图形界面,会自动弹出浏览器窗口
搜索过频繁可能触发闲鱼风控,建议间隔几秒再搜
Cookie 有效期约 1-3 天,过期后需要重新登录
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/Homoe-hs/xianyu-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server