Skip to main content

微信开发者工具 MCP Server (v0.9.24)

PyPI version MCP Registry License: MIT English

wechat-devtools-mcp:让编辑器里的 AI 直接编译、预览、调试、自动化测试小程序

把微信开发者工具封装为 MCP 服务,让编辑器里的 AI 直接完成小程序的编译、预览、调试、自动化测试闭环。Windows / macOS,已上架官方 MCP Registry。

快速开始 · 工具 · 环境变量 · 与官方内建 MCP 的关系 · 常见问题 · 给 AI agent · 版本历史

能做什么

  • 构建与发布:打开项目、编译、生成预览二维码、上传、构建 npm
  • 自动化:点击、输入、读写页面数据、调用页面方法、mock wx API、在小程序里执行任意 JS
  • 长图截图:自动滚动并拼接整页,识别固定头尾;拍不全时如实上报
  • 运行时日志:Console 日志与 CDP 结构化日志(回放采集前的历史、按页面归类、去噪)
  • 任务级流程:配套 Skill 提供 9 条 SOP(初始化、UI 调试、异常排查、全页面巡检、Mock 集成测试等)

快速开始

前置条件

  • 微信开发者工具 2.x 或 1.06.x
  • Node.js ≥ 18
  • uv:pip install uv 或 brew install uv(Python ≥ 3.10 由 uv 自动准备)

1. 安装 MCP Server

uv tool install wechat-devtools-mcp
wechat-devtools-mcp --version

2. 开启开发者工具服务端口

开发者工具 → 设置 → 安全设置 → 服务端口 → 开启。

不开则 open / compile / preview 等操作全部报 CLI_TIMEOUT。

3. 写入 MCP 配置

把下面的配置加进编辑器的 MCP 配置文件,两个路径换成你自己的绝对路径。

macOS:

{
  "mcpServers": {
    "wechat-devtools-mcp": {
      "command": "uvx",
      "args": ["wechat-devtools-mcp"],
      "env": {
        "WECHAT_DEVTOOLS_CLI": "/Applications/wechatwebdevtools.app/Contents/MacOS/cli",
        "WECHAT_PROJECT_PATH": "/Users/you/Projects/mini-app"
      }
    }
  }
}

Windows(JSON 里 \ 要写成 \\):

{
  "mcpServers": {
    "wechat-devtools-mcp": {
      "command": "uvx",
      "args": ["wechat-devtools-mcp"],
      "env": {
        "WECHAT_DEVTOOLS_CLI": "C:\\Program Files (x86)\\Tencent\\微信web开发者工具\\cli.bat",
        "WECHAT_PROJECT_PATH": "D:\\MyProjects\\mini-app"
      }
    }
  }
}
  • 9222 端口常年被 Chrome 等占用的机器,在 env 里再加一行 "WECHAT_CDP_PORT": "9333"。
  • server 名请用 wechat-devtools-mcp。开发者工具 2.x 把自家的 MCP 注册成了 wechat-devtools,同名会撞车。
各编辑器的配置文件位置与差异
  • Claude Code(项目级):仓库根目录 .mcp.json

  • Claude Desktop:claude_desktop_config.json

  • Antigravity:mcp_config.json

  • Kiro:~/.kiro/settings/mcp.json。可在 server 配置里加免确认列表:

    "autoApprove": ["wechat_ide", "wechat_build", "wechat_automator", "wechat_inspector", "wechat_screenshot", "wechat_navigate", "wechat_file"]
    
  • Trae ≥ 1.3:AI 面板 → 设置 → MCP → 手动配置;也可以直接编辑配置文件。聊天时须选 Builder with MCP 智能体。

    • Windows:%APPDATA%\Trae\User\globalStorage\mcp.json
    • macOS:~/Library/Application Support/Trae/User/globalStorage/mcp.json
  • Cursor / VS Code:在 MCP 面板新增 server,Name 填 wechat-devtools-mcp,Command 填 uvx wechat-devtools-mcp,环境变量同上。

  • OpenAI Codex:~/.codex/config.toml

    [mcp_servers.wechat-devtools-mcp]
    command = "uvx"
    args = ["wechat-devtools-mcp"]
    
    [mcp_servers.wechat-devtools-mcp.env]
    WECHAT_DEVTOOLS_CLI = "/Applications/wechatwebdevtools.app/Contents/MacOS/cli"
    WECHAT_PROJECT_PATH = "/Users/you/Projects/mini-app"
    

    Windows 路径同样把 \ 写成 \\。

macOS 桌面版编辑器报找不到 uvx / node:从图标启动的编辑器不继承终端的 PATH。把 command 改成绝对路径 /opt/homebrew/bin/uvx,并在 env 里加:

"PATH": "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin",
"NODE_PATH": "/opt/homebrew/bin/node"

4. 安装 Skill(必须)

npx -y skills add WaterTian/wechat-devtools-mcp/.agents/skills/wechat-devtools

不走 npx skills 的客户端(如 Trae):把本仓库的 .agents/skills/wechat-devtools/ 整个复制到小程序项目的 .agents/skills/ 下。

Skill 含 9 条 SOP、7 个工具的全 action 速查、CDP 渐进排查策略与故障手册,详见 SKILL.md。

5. 自检

在编辑器里调一次 wechat_ide(action='status'),下面几项都符合再开工:

字段 期望 不符时
cli_exists true 核对 WECHAT_DEVTOOLS_CLI
project_exists true 核对 WECHAT_PROJECT_PATH
node_available true 安装 Node.js ≥ 18
service_port_enabled true 见第 2 步
cdp_port_occupant.kind none 或 ide foreign 表示端口被别的浏览器占着,设 WECHAT_CDP_PORT=9333
skill_version 等于 mcp_version 重跑第 4 步

升级

uv tool install wechat-devtools-mcp --force --refresh
uvx --refresh wechat-devtools-mcp --version
  • --refresh 刷新索引缓存,否则可能装回旧版。用 uvx 配置的客户端复用已缓存的环境、不会自动升级,所以要跑第二条。
  • 升级后重启编辑器(停掉旧的 MCP 进程),并重跑第 4 步更新 Skill。
  • 曾用 pip install 装过的,先 pip uninstall wechat-devtools-mcp,否则旧路径优先于 uv。

工具

工具 用途与 action / 关键参数
wechat_ide IDE 生命周期与环境诊断
open login is_login close quit status
wechat_build 构建与发布
compile preview upload build_npm cache_clean
wechat_automator 自动化交互与运行时查询
start tap input element_info set_data call_method call_wx mock_wx evaluate page_stack page_data system_info storage
wechat_inspector 运行时日志采集
console cdp
wechat_screenshot 长图拼接截图
full_page page_path scroll_top wait_for_selector
wechat_navigate 跳转并采集 CDP 日志
page_path
wechat_file 项目文件读取
project_info list_pages read_page read_file
  • 完整参数见 MCP_DOC.md。
  • automator 连接失败时,动作会自动 start 一次并重试,返回里带 auto_recovered。
  • open 成功后,cdp_port 在同一会话内自动沿用,其它工具不必再传。
  • 云函数与云数据库请用 CloudBase MCP。

环境变量

变量 说明 默认
WECHAT_DEVTOOLS_CLI 开发者工具 CLI 的绝对路径(必填) —
WECHAT_PROJECT_PATH 默认项目根目录的绝对路径(必填) —
WECHAT_CLI_TIMEOUT CLI 超时秒数 30
WECHAT_CDP_PORT CDP 调试端口。9222 被 Chrome 占用时设成 9333 9222
WECHAT_AUTOMATOR_READY_TIMEOUT start 等 automator 首次应答的秒数,大项目冷启动可加大 45
NODE_PATH Node.js 可执行文件 node

与官方内建 MCP 的关系

微信开发者工具 2.x 自 2026-08-18 起为官方 Stable(1.06 已下架),IDE 内建了 MCP Server(49 个原子工具,其中 2 个已废弃)。两者互补,不是替代:

场景 用谁
打开项目、编译、预览、上传、点击输入、云开发 2.x 优先用官方内建 MCP
长图拼接截图 本项目。官方只截视口,并压到长边 1280 的 JPEG
CDP 结构化日志 本项目。官方只读缓存
任务级 SOP(巡检、异常排查、跨页面校验) 本项目的 Skill
存量 1.06.x(NW.js) 本项目继续兼容;官方内建 MCP 只有 2.x 有
  • 官方 MCP 是否可用:看 wechat_ide(action='status') 的 official_mcp.available。true 只表示服务在跑,不代表已鉴权。
  • 官方 MCP 需要独立 Token(Stable 2.02.2609240 起):到 IDE「设置 → 安全」重新复制 MCP 配置到你的 agent,否则官方工具一律返回 401。本项目不经过该接口,不受影响。
  • 注册名:官方 bridge 叫 wechat-devtools,本项目统一用 wechat-devtools-mcp。只在同一 agent 同时接入两者时才需要区分。

常见问题

  • 一直报 CLI_TIMEOUT:服务端口没开,见第 2 步。status 的 service_port_enabled 可自查。
  • CDP 采集失败,或采到的全是别的网页:status 的 cdp_port_occupant.kind 为 foreign,说明端口被别的浏览器占着。用 open(cdp_port=9333) 或设 WECHAT_CDP_PORT,之后其它工具不传端口也会自动沿用。
  • automator 9420 连不上,或 start 返回 verified=false:动作失联时会自动 start 一次并重试;start 自带最多 45 秒的就绪等待(ready_timeout 可调)。仍失败就看 status 的 project_window_open:窗口被关了就再 start,不要先 open 重启 IDE。
  • Windows 中文乱码或 UnicodeDecodeError:在 env 里加 "PYTHONIOENCODING": "utf-8"。
  • 装了新版仍跑旧版:按升级一节处理,以 status 的 mcp_version 为准。≤ 0.9.10 与 mcp SDK ≥ 2.0 不兼容(报 ModuleNotFoundError: mcp.server.fastmcp),须升到 ≥ 0.9.11。
  • IDE 2.x 下工具行为异常:注册名与官方的 wechat-devtools 撞车,改用 wechat-devtools-mcp。

给 AI agent

替用户安装或使用本项目时,按这个顺序做:

  1. 安装:uv tool install wechat-devtools-mcp。没有 uv 先装 uv,并确认 Node.js ≥ 18。
  2. 向用户要两个绝对路径(开发者工具 CLI、小程序项目根目录),不要猜。
  3. 写入 MCP 配置,见第 3 步。server 名固定为 wechat-devtools-mcp。
  4. 安装 Skill,见第 4 步。调用任何工具前先读 SKILL.md:工具怎么组合、失败怎么恢复都在里面。
  5. 请用户在开发者工具里开启服务端口(第 2 步,只能人工操作)。
  6. 调 wechat_ide(action='status'),按自检表逐项核对。
项 值
PyPI 包名与可执行文件 wechat-devtools-mcp
MCP Registry 名 io.github.WaterTian/wechat-devtools-mcp
启动命令与传输 uvx wechat-devtools-mcp,stdio
必填环境变量 WECHAT_DEVTOOLS_CLI、WECHAT_PROJECT_PATH
成功返回 {"success": true, "data": {...}, "message": "..."}
失败返回 {"success": false, "error_code": "...", "message": "...", "hint": "..."}
操作流程(SOP) SKILL.md
参数与错误码速查 tool_reference.md
完整工具文档 MCP_DOC.md

版本历史

  • 0.9.24(2026-11-30):截图去除机框四边最外 1px 的混色线;README 重排,新增「给 AI agent」一节。
  • 0.9.23(2026-11-30):长图接缝修复,状态栏 / 胶囊按钮 / 悬浮按钮不再在接缝处重复;弹层占满视口时回报 viewport_covered;懒加载列表拍到底;截图四角的圆角外统一涂黑。
  • 0.9.22(2026-11-18):wechat_screenshot 新增 wait_for_selector,截图前等元素出现;wechat_build 工具描述逐 action 补全。

更早的版本与逐版本说明见 CHANGELOG.md。

参考

Metadata

Release files for wechat-devtools-mcp 0.9.24

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

Built distribution (wheel)

Table of built distributions (wheels) for wechat-devtools-mcp 0.9.24
File Interpreter ABI Platform Actions
wechat_devtools_mcp-0.9.24-py3-none-any.whl Python 3 none any Details for wechat_devtools_mcp-0.9.24-py3-none-any.whl

Release files / wechat_devtools_mcp-0.9.24-py3-none-any.whl

Download URL wechat_devtools_mcp-0.9.24-py3-none-any.whl
Size 639.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ecb979ab09a0a052234e739767af82f31435141af91bfd833c2e95b0ef75edcc
BLAKE2b-256 checksum
How to use checksums
1e9ef6d8cfbd2d9a17d5f59279fd28c515e648ba12a19153b16a6a75fe822db6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for wechat-devtools-mcp 0.9.24

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.9.24 This release

1 release file 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