Skip to main content

xianyu-mcp

xianyu-mcp 是一个面向 MCP 客户端使用者的闲鱼 MCP Server。它通过 Playwright 和闲鱼网页能力,提供登录、商品发布、收藏管理、商品查询、卖家主页读取等能力。

你可以把它接入支持 MCP 的客户端,例如 Codex、Claude Code、MCP Inspector,或任何兼容 stdio / streamable_http 的 MCP 工具。

它能做什么

  • 登录闲鱼账号,获取扫码二维码并轮询登录结果
  • 登录二维码会保存到本地 screenshots/ 目录,并返回可供用户打开的图片文件提示
  • 发布商品、下架商品、删除商品
  • 搜索商品、读取商品详情、读取首页推荐
  • 添加收藏、取消收藏、读取收藏列表
  • 读取我发布的商品列表、读取卖家主页信息
  • 通过 analyze_goods 工具生成商品分析提示词和分析上下文数据

当前项目实际注册了 16 个 MCP tools。

环境要求

  • Python 3.10 或更高版本
  • 可正常启动的 Chromium 浏览器环境
  • 能访问闲鱼网页

通过 uvx 使用(推荐)

无需手动安装,uvx 会自动处理。

Claude Code 配置

claude mcp add xianyu -e MCP_TRANSPORT=stdio -- uvx xianyu-mcp

首次运行

首次运行会自动安装 Playwright Chromium(约需 1-2 分钟)。


快速开始

方式一:默认作为 stdio MCP Server 运行

默认启动方式是 stdio,适合 Claude Code 等 MCP 客户端以子进程方式拉起。

xianyu-mcp

如果命令行入口不可用,也可以这样启动:

python -m xianyu_mcp

方式二:作为本地 streamable_http MCP Server 运行

如果需要常驻服务供多个客户端复用,可切换到 streamable_http:

MCP_TRANSPORT=streamable_http

然后启动服务:

xianyu-mcp

默认地址为:

http://127.0.0.1:18000/mcp

配置

你可以通过环境变量或 .env 文件调整运行行为。常用项如下:

变量 默认值 说明
HEADLESS true 是否使用无头浏览器
PAGE_TIMEOUT 30000 页面操作超时,单位毫秒
SLOW_MO 0 浏览器慢动作延时,单位毫秒
COOKIE_AUTO_SYNC_ENABLED true 是否开启 Cookie 自动同步
COOKIE_SYNC_INTERVAL_SECONDS 600 Cookie 同步间隔,单位秒
COOKIE_SYNC_TIMEOUT_SECONDS 30 单次 Cookie 同步超时,单位秒
AUTO_SCREENSHOT false 是否自动截图
SCREENSHOT_DIR ./screenshots 截图目录
LOG_LEVEL INFO 日志级别
MCP_TRANSPORT stdio 传输模式:stdio 或 streamable_http
MCP_TOOL_TIMEOUT_SECONDS 10 单个工具调用超时,单位秒
MCP_HTTP_HOST 127.0.0.1 HTTP 模式监听地址
MCP_HTTP_PORT 18000 HTTP 模式监听端口
MCP_STREAMABLE_HTTP_PATH /mcp HTTP 模式路径

例如,如果你想看到浏览器界面:

HEADLESS=false

Tools 一览

账号登录

  • check_login_status:检查当前是否已登录
  • get_login_qrcode:获取登录二维码(二维码图片保存到本地 screenshots/)
  • check_login_scan_result:检查扫码结果(人脸验证时同样返回本地二维码文件提示)
  • logout:退出登录并清理本地会话

商品查询与收藏

  • search_goods:按关键词搜索商品(支持价格/排序/快速筛选)
  • get_home_goods:读取首页推荐商品
  • get_goods_detail:读取商品详情(支持传入商品 ID 或链接)
  • get_favorites:读取收藏列表
  • add_favorite:收藏商品
  • remove_favorite:取消收藏

发布与我的商品管理

  • get_my_goods:读取我发布的商品列表
  • publish_goods:发布商品
  • take_down_goods:下架商品
  • delete_goods:删除商品

卖家与分析

  • get_seller_profile:读取卖家主页信息(默认含商品与评价,最多各 10 条)
  • analyze_goods:生成商品风险与价格分析提示词(返回 prompt + 商品/卖家数据)

发布新版本到 PyPI

修改代码后,更新 pyproject.toml 中的版本号,然后:

# 安装构建工具(首次需要,指定官方源)
pip install hatch twine -i https://pypi.org/simple/

# 构建
hatch build

# 上传到 PyPI
# Username: __token__
# Password: 在 https://pypi.org/manage/account/ 的 API tokens 中创建
python -m twine upload dist/*

# 验证上传成功
uvx xianyu-mcp==<新版本号> --help

注意:上传后 PyPI 同步约需 1-2 分钟,验证前稍等片刻。

使用建议

  • 默认使用 stdio,适合 Claude Code 等 MCP 客户端以子进程方式拉起
  • 如果需要常驻服务给多个客户端复用,可切换到 streamable_http
  • 首次启动会自动安装 Playwright/Chromium,启动超时建议适当放宽
  • 登录、发布商品这类依赖页面状态的操作,建议先确认账号已登录
  • 不考虑制作购买和聊天的工具。

Metadata

Release files for xianyu-mcp 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xianyu-mcp 0.0.1
File Size Uploaded Provenance
xianyu_mcp-0.0.1.tar.gz 52.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for xianyu-mcp 0.0.1
File Interpreter ABI Platform
xianyu_mcp-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 119.4 kB

Release files / xianyu_mcp-0.0.1.tar.gz

Download URL xianyu_mcp-0.0.1.tar.gz
Size 52.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3f19cd84ffe06a7445eb37ca6b54b68072bae6c826e4da8a3ff684d356b50427
BLAKE2b-256 checksum
How to use checksums
e45b01b5ea11ff85d37d3b425df4aab323b81634cfc2eacf915d8c92d8bf8ad5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / xianyu_mcp-0.0.1-py3-none-any.whl

Download URL xianyu_mcp-0.0.1-py3-none-any.whl
Size 67.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
69ef68068e4de4d0316a3cc2f764bc61a73a19cc7b83c71bf6f199f093ff8105
BLAKE2b-256 checksum
How to use checksums
bf30d2f7303384ca4512d2077e81107c31f8df91e57ce73fc18d29e184f279cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for xianyu-mcp 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page