wechat-devtools
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWechat DevTools MCP Skill (v0.9.5)
Wechat DevTools MCP Skill (v0.9.5)
前置条件
Prerequisites
Step 0:安装与配置
Step 0: Installation and Configuration
bash
pip install uv # 如未安装 uv
uv tool install wechat-devtools-mcp --force # 通过uv安装wechat-devtools-mcp编辑器配置:
json
{
"mcpServers": {
"wechat-devtools": {
"command": "uvx",
"args": ["wechat-devtools-mcp"],
"env": {
"WECHAT_DEVTOOLS_CLI": "C:\\Program Files (x86)\\Tencent\\微信web开发者工具\\cli.bat",
"WECHAT_PROJECT_PATH": "D:\\Your\\Project\\Path"
}
}
}
}主流编辑器配置见 README.md
[!IMPORTANT] 必须手动开启开发者工具的服务端口:→设置→安全设置→服务端口。未开启将导致所有 CLI 操作报开启。CLI_TIMEOUT
bash
pip install uv # Install uv if not present
uv tool install wechat-devtools-mcp --force # Install wechat-devtools-mcp via uvEditor Configuration:
json
{
"mcpServers": {
"wechat-devtools": {
"command": "uvx",
"args": ["wechat-devtools-mcp"],
"env": {
"WECHAT_DEVTOOLS_CLI": "C:\\Program Files (x86)\\Tencent\\微信web开发者工具\\cli.bat",
"WECHAT_PROJECT_PATH": "D:\\Your\\Project\\Path"
}
}
}
}See README.md for mainstream editor configurations
[!IMPORTANT] You must manually enable the service port of the developer tools:→Settings→Security Settings→Service Port. Failure to enable will cause all CLI operations to reportEnable.CLI_TIMEOUT
Step 1:运行时环境检查
Step 1: Runtime Environment Check
首先调用一次性确认所有前置条件。wechat_ide(action='status')
| 检查项 | 偏好命令 | 失败时操作 |
|---|---|---|
| CLI 已安装 | | 安装工具并配置 |
| 项目路径已配置 | | 配置 |
| 已登录 | | |
| Node.js 可用 | | 安装 Node.js ≥ 8.0 |
First callto verify all prerequisites at once.wechat_ide(action='status')
| Check Item | Preferred Command | Action on Failure |
|---|---|---|
| CLI Installed | | Install the tool and configure |
| Project Path Configured | | Configure |
| Logged In | | |
| Node.js Available | | Install Node.js ≥ 8.0 |
Efficiency Principles
Efficiency Principles
IDE 只在会话开始时 open 一次,compile 只在代码变更后执行,页面跳转优先用 evaluate 而非 navigate。
| 场景 | 正确做法 | 错误做法 |
|---|---|---|
| 没改代码,换页面测试 | | 重新 open → compile |
| 改了代码 | | 重新 open → compile |
| 连接断开 | 先快速恢复(仅 | 直接走完整恢复 |
The IDE is opened only once at the start of the session, compile is executed only after code changes, and page navigation uses evaluate preferentially over navigate.
| Scenario | Correct Practice | Incorrect Practice |
|---|---|---|
| Testing different pages without code changes | | Re-open → compile |
| Code changed | | Re-open → compile |
| Connection disconnected | Quick recovery first (only | Directly perform full recovery |
API 速查表
API Cheat Sheet
wechat_ide
— IDE 生命周期
wechat_idewechat_ide
— IDE Lifecycle
wechat_ide| action | 功能 | 关键参数 |
|---|---|---|
| 打开 IDE/项目(cdp_enabled 时自动做启动健康检查) | |
| 扫码登录 | |
| 检查登录状态 | — |
| 关闭项目 / 退出 IDE | — |
| 环境诊断 | — |
| action | Function | Key Parameters |
|---|---|---|
| Open IDE/project (automatically performs startup health check when cdp_enabled) | |
| QR code login | |
| Check login status | — |
| Close project / Exit IDE | — |
| Environment diagnosis | — |
wechat_build
— 构建与发布
wechat_buildwechat_build
— Building and Publishing
wechat_build| action | 功能 | 关键参数 |
|---|---|---|
| 编译检查(捕获错误/警告,成功后自动重连 automator) | — |
- 注意:compile_condition 对 tabBar 页面可能无效(app 路由守卫覆盖),用 evaluate + wx.reLaunch 跳转更可靠
| | 生成预览二维码 | |
| | 上传到微信后台 | (必填), |
| | 构建 NPM 依赖(upload 前必做) | — |
| | 清除缓存 | |
previewqr_format="terminal"uploadversiondesc?build_npmcache_cleanclean_type="compile"| action | Function | Key Parameters |
|---|---|---|
| Compilation check (captures errors/warnings, automatically reconnects automator after success) | — |
- Note: compile_condition may be invalid for tabBar pages (overridden by app route guards), using evaluate + wx.reLaunch for navigation is more reliable
| | Generate preview QR code | |
| | Upload to WeChat backend | (required), |
| | Build NPM dependencies (mandatory before upload) | — |
| | Clear cache | |
previewqr_format="terminal"uploadversiondesc?build_npmcache_cleanclean_type="compile"wechat_automator
— 自动化交互
wechat_automatorwechat_automator
— Automated Interaction
wechat_automator前提:先调用开启自动化端口(整个会话仅需一次)。start
| action | 功能 | 必填参数 |
|---|---|---|
| 开启自动化端口 | — |
| 点击元素 | |
| 输入文本 | |
| 获取元素详情(文本/尺寸/WXML) | |
| 热更新页面 data(无需重编译) | |
| 调用页面方法 | |
| 调用 wx API | |
| Mock wx API 返回值 | |
| 执行 JS 表达式(逻辑层万能钥匙) | |
- 注意:v0.7.0 起支持声明语句(const/let/var)
- v0.9.2:compile 后自动 invalidate 旧缓存连接再重连,daemon 健康检查 3s 超时保护,navigate currentPage 轮询 2s 独立超时
- v0.9.0:底层改为持久化 Node daemon(NDJSON 协议),WS 连接按端口缓存复用,工具调用延迟 ~3ms
| | 获取页面栈 | — |
| | 获取当前页面 data | (轮询验证页面路径) |
| | 获取运行时系统信息 | — |
| | 读取本地缓存 | (空=列出全部) |
page_stackpage_dataexpected_path?system_infostoragekey?Prerequisite: Callfirst to enable the automation port (only required once per session).start
| action | Function | Required Parameters |
|---|---|---|
| Enable automation port | — |
| Click element | |
| Input text | |
| Get element details (text/size/WXML) | |
| Hot update page data (no recompilation needed) | |
| Call page method | |
| Call wx API | |
| Mock wx API return value | |
| Execute JS expression (universal key for logic layer) | |
- Note: Declaration statements (const/let/var) are supported since v0.7.0
- v0.9.2: Automatically invalidates old cache connections and reconnects after compile, adds 3s timeout protection for daemon health check, and 2s independent timeout for navigate currentPage polling
- v0.9.0:底层改为持久化 Node daemon(NDJSON 协议),WS 连接按端口缓存复用,工具调用延迟 ~3ms
| | Get page stack | — |
| | Get current page data | (poll to verify page path) |
| | Get runtime system information | — |
| | Read local cache | (empty = list all) |
page_stackpage_dataexpected_path?system_infostoragekey?wechat_inspector
— 日志采集
wechat_inspectorwechat_inspector
— Log Collection
wechat_inspector| action | 功能 | 关键参数 |
|---|---|---|
| 采集 console 日志和 JS 异常 | |
| CDP 协议采集底层日志(WXML/渲染层) | |
cdp 前提:以打开项目,确保端口 9222 可用。cdp_enabled=true
| action | Function | Key Parameters |
|---|---|---|
| Collect console logs and JS exceptions | |
| Collect underlying logs via CDP protocol (WXML/rendering layer) | |
CDP Prerequisite: Open the project withand ensure port 9222 is available.cdp_enabled=true
wechat_screenshot
— 截图
wechat_screenshotwechat_screenshot
— Screenshot
wechat_screenshot- (可选):截图保存路径。留空则自动保存到项目目录下
output_path文件夹screenshots/ - (默认
full_page):设为true只截当前视口false - (可选):截图前滚动到的位置(逻辑像素),配合
scroll_top使用full_page=false - (可选):确保截图前在指定页面上,若当前页面不匹配则自动跳转
page_path - 前提:先调用
wechat_automator(action='start') - 注意:不要主动截图,仅在用户明确要求或排查异常需要视觉确认时才调用
- 限制:使用 组件滚动的页面无法长图拼接(automator SDK 限制),仅截取当前视口
scroll-view - 限制:截图可能无法捕获 fixed/absolute overlay(弹窗、蒙层),以 page_data 为准
- 路径规约:推荐 或显式绝对路径。避免写入
<project>/screenshots/— 这是 Claude Code 的用户发图缓存目录,MCP 截图混入会互相污染.claude/image-cache/
- (optional): Screenshot save path. Leave blank to automatically save to the
output_pathfolder under the project directoryscreenshots/ - (default
full_page): Set totrueto capture only the current viewportfalse - (optional): Position to scroll to before taking the screenshot (logical pixels), use with
scroll_topfull_page=false - (optional): Ensure being on the specified page before taking the screenshot, automatically navigate if current page does not match
page_path - Prerequisite: Call first
wechat_automator(action='start') - Note: Do not take screenshots actively, only call when explicitly requested by the user or visual confirmation is needed for troubleshooting
- Limitation: Pages using component cannot be stitched into long screenshots (automator SDK limitation), only the current viewport is captured
scroll-view - Limitation: Screenshots may not capture fixed/absolute overlays (pop-ups, masks), rely on instead
page_data - Path Convention: Recommended to use or explicit absolute path. Avoid writing to
<project>/screenshots/— this is the user image cache directory for Claude Code, mixing MCP screenshots will cause mutual contamination.claude/image-cache/
wechat_navigate
— 跳转并采集日志
wechat_navigatewechat_navigate
— Navigate and Collect Logs
wechat_navigate- (必填):如
page_pathpages/index/index - :等待毫秒,建议 3000
wait_ms - :是否过滤历史 CDP 日志,默认
clear_logstrue - :跳转后是否检查 page_data 空值,默认
check_datatrue - :
detail_level(仅 errors+warnings)或concisefull - v0.8.0 新增:自动检测 TabBar 页面并使用 替代
switchTab,返回reLaunch字段navigation_method - 前提:需 +
automator startcdp_enabled=true
- (required): e.g.
page_pathpages/index/index - : Wait time in milliseconds, recommended 3000
wait_ms - : Whether to filter historical CDP logs, default
clear_logstrue - : Whether to check for empty page_data after navigation, default
check_datatrue - :
detail_level(only errors+warnings) orconcisefull - Added in v0.8.0: Automatically detects TabBar pages and uses instead of
switchTab, returnsreLaunchfieldnavigation_method - Prerequisite: Requires +
automator startcdp_enabled=true
wechat_file
— 文件读取
wechat_filewechat_file
— File Reading
wechat_file| action | 功能 | 必填参数 |
|---|---|---|
| 项目完整信息(app.json + 目录结构) | — |
| 所有页面列表(含文件完整性检查) | — |
| 读取页面源码(wxml/wxss/js/json) | |
| 读取任意单文件(最多 800 行) | |
云函数与云数据库管理:本 MCP 自 v0.9.5 起不再提供工具。请改用 CloudBase MCP(wechat_cloud/manageFunctions/readNoSqlDatabaseContent等),无 IDE 依赖且覆盖更完整。writeNoSqlDatabaseContent
| action | Function | Required Parameters |
|---|---|---|
| Get complete project information (app.json + directory structure) | — |
| Get all page list (including file integrity check) | — |
| Read page source code (wxml/wxss/js/json) | |
| Read any single file (max 800 lines) | |
Cloud Function and Cloud Database Management: This MCP no longer providestools since v0.9.5. Please use CloudBase MCP instead (withwechat_cloud/manageFunctions/readNoSqlDatabaseContentetc.), which has no IDE dependency and covers more features.writeNoSqlDatabaseContent
SOP 标准操作流程
SOP Standard Operating Procedures
SOP A:初始化(新环境必做)
SOP A: Initialization (Mandatory for New Environments)
wechat_ide(action='status') # 诊断环境
wechat_ide(action='is_login') # 检查登录
↳ 未登录: wechat_ide(action='login', qr_format='terminal')
wechat_ide(action='open', cdp_enabled=True) # 开启 IDE + CDP 9222 + 自动健康检查
↳ 返回 success=false + startup_errors → 小程序启动阶段有致命错误,必须先修复再继续
↳ 返回 success=true → 启动正常,继续后续步骤
↳ IDE 冷启动可能出现瞬态错误(simulator not found / subPackages of undefined),属正常现象,忽略并继续执行 compile 即可刷新
wechat_automator(action='start') # 启动 daemon + 开启自动化 9420
wechat_file(action='project_info') # [可选] 确认项目结构
wechat_build(action='cache_clean', clean_type='all') # 清除全部缓存
wechat_build(action='compile') # 编译建立干净 CDP 基线(自动重连 automator)
wechat_automator(action='page_data') # 验证连接可用
↳ ⚠ 检查输出中 AppID 是否为 undefined
↳ 如果 undefined → project_path 可能指向了子目录而非项目根目录
↳ 云开发项目根目录包含 project.config.json、miniprogram/ 和 cloudfunctions/
↳ 正确: project_path="D:/MyProject" 错误: project_path="D:/MyProject/miniprogram"project_path 规则:必须指向包含的根目录。云开发项目的project.config.json是子目录,不能作为 project_path。miniprogram/
wechat_ide(action='status') # Diagnose environment
wechat_ide(action='is_login') # Check login status
↳ Not logged in: wechat_ide(action='login', qr_format='terminal')
wechat_ide(action='open', cdp_enabled=True) # Launch IDE + CDP 9222 + automatic health check
↳ Returns success=false + startup_errors → Fatal error during mini program startup, must fix before proceeding
↳ Returns success=true → Startup normal, proceed to next steps
↳ Transient errors may occur during IDE cold start (simulator not found / subPackages of undefined), which is normal, ignore and continue to execute compile to refresh
wechat_automator(action='start') # Launch daemon + enable automation port 9420
wechat_file(action='project_info') # [Optional] Confirm project structure
wechat_build(action='cache_clean', clean_type='all') # Clear all cache
wechat_build(action='compile') # Compile to establish clean CDP baseline (automatically reconnects automator)
wechat_automator(action='page_data') # Verify connection availability
↳ ⚠ Check if AppID is undefined in the output
↳ If undefined → project_path may point to a subdirectory instead of the project root
↳ Cloud development project root directory contains project.config.json, miniprogram/ and cloudfunctions/
↳ Correct: project_path="D:/MyProject" Wrong: project_path="D:/MyProject/miniprogram"project_path Rule: Must point to the root directory containing. For cloud development projects,project.config.jsonis a subdirectory and cannot be used as project_path.miniprogram/
SOP A-2:代码变更后重编译(无需重新 open)
SOP A-2: Recompile After Code Changes (No Need to Re-open IDE)
wechat_build(action='compile') # 编译(自动重连 automator)
wechat_automator(action='page_data') # 验证连接可用不需要重新 open IDE、不需要 cache_clean。仅在修改了小程序源码后执行。
wechat_build(action='compile') # Compile (automatically reconnects automator)
wechat_automator(action='page_data') # Verify connection availabilityNo need to re-open IDE or perform cache_clean. Only execute after modifying mini program source code.
页面跳转标准方法
Standard Page Navigation Methods
| 场景 | 方式 |
|---|---|
| 普通页面 | |
| tabBar 页面 | |
| 强制重置 | |
| 跳转后 | |
| Scenario | Method |
|---|---|
| Normal page | |
| TabBar page | |
| Force reset | |
| After navigation | Verify |
SOP B:UI 调试(数据/布局问题)
SOP B: UI Debugging (Data/Layout Issues)
wechat_file(action='list_pages') # ⓪ 首次导航前,获取有效页面路径列表
↳ tabBar 页面路径通常是 pages/xxx/index(非 pages/xxx/xxx)
wechat_navigate(page_path='pages/xxx/index', wait_ms=3000) # ① 跳转 + CDP 日志
wechat_automator(action='page_data') # ② 查看 data 状态
↳ ⚠ 必须校验 data.path === 预期的 page_path
↳ 如不匹配 → 页面跳转失败或被重定向(见 page_data 注意事项)
↳ 数据异常: set_data(data_json='{"key":"val"}') 热更新验证
↳ 确认元素: element_info(selector='.target')
↳ 仅在用户要求或需要视觉确认时: wechat_screenshot() # 默认保存到项目 screenshots/wechat_file(action='list_pages') # ⓪ Before first navigation, get list of valid page paths
↳ TabBar page paths are usually pages/xxx/index (not pages/xxx/xxx)
wechat_navigate(page_path='pages/xxx/index', wait_ms=3000) # ① Navigate + CDP logs
wechat_automator(action='page_data') # ② Check data status
↳ ⚠ Must verify that data.path === expected page_path
↳ If not matching → Page navigation failed or redirected (see page_data notes)
↳ Data exception: set_data(data_json='{"key":"val"}') to hot update and verify
↳ Confirm element: element_info(selector='.target')
↳ Only when requested by user or visual confirmation is needed: wechat_screenshot() # Default saves to project screenshots/SOP C:异常排查(报错/白屏/JS 异常)
SOP C: Troubleshooting (Errors/White Screen/JS Exceptions)
wechat_automator(action='page_data') # ① 首选:直接检查页面数据
↳ 关键字段为 null/空 → 数据未加载或参数错误
↳ 数据正常 → 跳到步骤 ④ 确认非数据问题
wechat_automator(action='evaluate', expression='wx.cloud.callFunction({name:"xxx",data:{...}})')
# ② 直接调 API 获取完整返回值
↳ 遇到 [object Object] 时必用此步骤,可拿到完整 JSON
wechat_inspector(action='cdp', duration=5, detail_level='concise')
# ③ CDP 辅助参考
⚠ CDP 错误计数可能包含历史缓存,以 page_data 为准
wechat_build(action='compile') # ④ 捕获编译错误
↳ 检查 wxml_errors 字段;⚠ 中文引号 "" 等编译错误工具无法捕获wechat_automator(action='page_data') # ① Preferred: Directly check page data
↳ Key fields are null/empty → Data not loaded or parameter error
↳ Data normal → Proceed to step ④ to confirm it's not a data issue
wechat_automator(action='evaluate', expression='wx.cloud.callFunction({name:"xxx",data:{...}})')
# ② Directly call API to get complete return value
↳ Must use this step when encountering [object Object] to get complete JSON
wechat_inspector(action='cdp', duration=5, detail_level='concise')
# ③ CDP auxiliary reference
⚠ CDP error count may include historical cache, rely on page_data instead
wechat_build(action='compile') # ④ Capture compilation errors
↳ Check wxml_errors field; ⚠ Compilation errors like Chinese quotes "" cannot be captured by the toolSOP D:全页面巡检(回归/发布前验收)
SOP D: Full Page Inspection (Regression/Pre-release Acceptance)
wechat_build(action='cache_clean', clean_type='all') # 建立干净 CDP 基线
wechat_build(action='compile')
↳ ⚠ 检查 AppID 是否为 undefined
wechat_file(action='list_pages') # 获取页面列表,确认有效路径wechat_build(action='cache_clean', clean_type='all') # Establish clean CDP baseline
wechat_build(action='compile')
↳ ⚠ Check if AppID is undefined
wechat_file(action='list_pages') # Get page list, confirm valid paths对每个 page 顺序执行(禁止并行):
Execute sequentially for each page (parallel execution is prohibited):
wechat_navigate(page_path=page, wait_ms=3000) # 跳转 + CDP 日志
wechat_automator(action='page_data') # 核心验证:关键字段非 null/空
↳ ⚠ 必须校验 data.path === 预期的 page_path
↳ 如不匹配 → 页面跳转失败或被重定向,标记异常
↳ 字段正常且 path 匹配 → ✅ 页面通过
↳ 字段为空 → ⚠ 标记异常,用 evaluate 进一步诊断
↳ 仅在 page_data 异常时补充截图
wechat_navigate(page_path=page, wait_ms=3000) # Navigate + CDP logs
wechat_automator(action='page_data') # Core verification: Key fields are not null/empty
↳ ⚠ Must verify that data.path === expected page_path
↳ If not matching → Page navigation failed or redirected, mark as exception
↳ Fields normal and path matching → ✅ Page passed
↳ Fields empty → ⚠ Mark as exception, use evaluate for further diagnosis
↳ Only take supplementary screenshots when page_data is abnormal
汇总:按 page_data 结果排序输出报告
Summary: Output report sorted by page_data results
undefinedundefinedSOP E:Mock 集成测试(支付/权限/设备)
SOP E: Mock Integration Testing (Payment/Permissions/Devices)
wechat_automator(action='mock_wx', method='requestPayment', result_json='{"errMsg":"requestPayment:ok"}')
wechat_automator(action='mock_wx', method='getUserProfile', result_json='{"userInfo":{"nickName":"测试用户"}}')
wechat_automator(action='mock_wx', method='getLocation', result_json='{"latitude":23.099,"longitude":113.324}')
wechat_automator(action='tap', selector='.pay-btn') # 触发交互
wechat_automator(action='page_data') # 验证 data 变化Mock 仅当前会话有效,重启 IDE 后需重新设置。
wechat_automator(action='mock_wx', method='requestPayment', result_json='{"errMsg":"requestPayment:ok"}')
wechat_automator(action='mock_wx', method='getUserProfile', result_json='{"userInfo":{"nickName":"Test User"}}')
wechat_automator(action='mock_wx', method='getLocation', result_json='{"latitude":23.099,"longitude":113.324}')
wechat_automator(action='tap', selector='.pay-btn') # Trigger interaction
wechat_automator(action='page_data') # Verify data changesMock is only valid for the current session, needs to be reset after restarting IDE.
SOP F:网络调试与 UI 适配
SOP F: Network Debugging and UI Adaptation
① 网络与 API 调试
undefined① Network and API Debugging
undefined拦截请求(逻辑层注入)
Intercept requests (logic layer injection)
evaluate(expression='var o=wx.request; wx.request=function(p){console.log(p.url);return o.apply(wx,arguments)}')
evaluate(expression='var o=wx.request; wx.request=function(p){console.log(p.url);return o.apply(wx,arguments)}')
模拟超时
Simulate timeout
mock_wx(method='request', result_json='{"errMsg":"request:fail timeout"}')
**② UI 适配测试**
mock_wx(method='getSystemInfo', result_json='{"theme":"dark"}') # 暗黑模式适配
mock_wx(method='getSystemInfo', result_json='{"platform":"mac","windowWidth":1024}') # iPad/PC 适配
system_info() # 记录 windowWidth/Height
undefinedmock_wx(method='request', result_json='{"errMsg":"request:fail timeout"}')
**② UI Adaptation Testing**
mock_wx(method='getSystemInfo', result_json='{"theme":"dark"}') # Dark mode adaptation
mock_wx(method='getSystemInfo', result_json='{"platform":"mac","windowWidth":1024}') # iPad/PC adaptation
system_info() # Record windowWidth/Height
undefinedSOP G:子页面测试(需 query 参数的页面)
SOP G: Subpage Testing (Pages Requiring Query Parameters)
wechat_file(action='read_page', page_path='pages/xxx/xxx') # ① 查看 onLoad 方法
↳ 从 options 参数中确认 query 参数名(如 id / matchId)
wechat_navigate(page_path='pages/xxx/xxx?正确参数名=值', wait_ms=3000) # ② 跳转
wechat_automator(action='page_data') # ③ 验证数据
↳ 关键字段非空 → ✅
↳ 大部分为 null → 参数名可能有误,回到 ①wechat_file(action='read_page', page_path='pages/xxx/xxx') # ① Check onLoad method
↳ Confirm query parameter names (such as id / matchId) from options parameter
wechat_navigate(page_path='pages/xxx/xxx?correct_param_name=value', wait_ms=3000) # ② Navigate
wechat_automator(action='page_data') # ③ Verify data
↳ Key fields not empty → ✅
↳ Most fields are null → Parameter name may be incorrect, go back to ①SOP I:跨页面数据一致性校验
SOP I: Cross-page Data Consistency Verification
适用场景:验证同一数据在不同页面的展示是否一致(如积分、用户状态、等级等)
wechat_file(action='list_pages') # ① 获取页面列表Applicable scenario: Verify whether the same data is displayed consistently across different pages (such as points, user status, level, etc.)
wechat_file(action='list_pages') # ① Get page list定义需要校验的公共字段(如 points, phone_bound, level)
Define common fields to verify (such as points, phone_bound, level)
② 逐页面采集数据(顺序执行,禁止并行):
② Collect data page by page (execute sequentially, parallel execution is prohibited):
wechat_navigate(page_path=page, wait_ms=3000)
wechat_automator(action='page_data')
↳ 校验 data.path === 预期页面(跳转失败则标记并跳过)
↳ 提取公共字段值,记录到比对表
wechat_navigate(page_path=page, wait_ms=3000)
wechat_automator(action='page_data')
↳ Verify that data.path === expected page (mark and skip if navigation failed)
↳ Extract values of common fields, record to comparison table
③ 比对各页面的同名字段值
③ Compare values of fields with the same name across pages
↳ 值一致 → ✅ 字段通过
↳ 值不一致 → ⚠ 标记异常,用 evaluate 直接调 API 对比返回值
↳ 子页面数据异常时,检查是否使用了独立的数据获取链路
undefined↳ Values consistent → ✅ Field passed
↳ Values inconsistent → ⚠ Mark as exception, use evaluate to directly call API for comparison
↳ When subpage data is abnormal, check if independent data acquisition link is used
undefinedSOP J:小程序 + 管理后台并行数据比对
SOP J: Parallel Data Comparison Between Mini Program and Management Backend
适用场景:验证小程序前端数据与管理后台数据的一致性
undefinedApplicable scenario: Verify consistency between mini program frontend data and management backend data
undefined架构:
Architecture:
管理后台 → Playwright MCP(浏览器端口)
Management Backend → Playwright MCP (browser port)
小程序 → WeChat DevTools MCP(automator 9420 端口)
Mini Program → WeChat DevTools MCP (automator port 9420)
两者使用不同端口,可以并行运行
They use different ports and can run in parallel
① 分别从两端提取数据(可并行)
① Extract data from both ends respectively (can be parallel)
Agent A: Playwright 操作管理后台,提取数据
Agent A: Operate management backend via Playwright, extract data
Agent B: WeChat MCP 操作小程序,提取 page_data
Agent B: Operate mini program via WeChat MCP, extract page_data
② 在主进程中做数据比对(串行)
② Perform data comparison in main process (serial)
> **端口独占规则**:automator 9420 端口是独占的,同一时刻只能有一个 Agent 操作 WeChat MCP。Playwright 和 WeChat MCP 可同时使用(不同端口)。
---
> **Port Exclusivity Rule**: The automator port 9420 is exclusive, only one Agent can operate WeChat MCP at the same time. Playwright and WeChat MCP can be used simultaneously (different ports).
---CDP 日志策略
CDP Log Strategy
concise → 仅 errors + warnings(节省 Token,优先使用)
↓ summary.errors > 0 时
full → 完整日志 + source 定位 → wechat_file(action='read_file', file_path=source)| 场景 | 推荐参数 |
|---|---|
| 快速诊断 | |
| 深度排查 | |
| 页面巡检 | |
重要:CDP 错误计数可能包含跨页面累积的历史日志。v0.4.0 的(默认)会基于时间戳过滤历史日志,但仍建议以clear_logs=true作为最终验证标准。page_data
concise → Only errors + warnings (saves tokens, preferred)
↓ When summary.errors > 0
full → Complete logs + source location → wechat_file(action='read_file', file_path=source)| Scenario | Recommended Parameters |
|---|---|
| Quick diagnosis | |
| In-depth troubleshooting | |
| Page inspection | |
Important: CDP error count may include accumulated historical logs across pages.(default) in v0.4.0 filters historical logs based on timestamp, but it is still recommended to useclear_logs=trueas the final verification standard.page_data
CDP 日志噪音过滤
CDP Log Noise Filtering
以下日志来源属于开发工具内部噪音,不代表应用错误,应在判断时排除:
| source 前缀 | 说明 | 处理 |
|---|---|---|
| 开发者工具自身的断言/警告 | 忽略 |
| IDE 扩展注入的提醒 | 区分对待 |
以下 message 模式属于框架级提醒,非应用错误:
| message 模式 | 说明 |
|---|---|
| devtools 内部断言 |
| 浏览器引擎警告 |
| 废弃 API 迁移提醒 |
| 框架 API 废弃预警 |
| 组件属性类型不匹配警告 |
判断原则:CDP 的 errors/warnings 计数可能被上述噪音抬高,导致误判。始终以返回的实际数据作为最终验证标准。page_data
The following log sources are internal noise of the developer tools and do not represent application errors, should be excluded when judging:
| source Prefix | Description | Handling |
|---|---|---|
| Assertions/warnings from the developer tool itself | Ignore |
| Reminders injected by IDE extensions | Treat differently |
The following message patterns are framework-level reminders, not application errors:
| message Pattern | Description |
|---|---|
| Internal assertions of devtools |
| Browser engine warning |
| Deprecated API migration reminder |
| Framework API deprecation warning |
| Component property type mismatch warning |
Judgment Principle: The errors/warnings count in CDP may be inflated by the above noise, leading to misjudgment. Always use the actual data returned byas the final verification standard.page_data
page_data 使用注意事项
page_data Notes
-
必须校验 path 字段:返回的表示当前实际页面,如果与导航目标不一致,说明页面跳转失败或被重定向。
data.path -
常见不一致原因:
- 用户未登录,页面拦截跳转到登录/欢迎页
- 云函数调用失败(AppID undefined),页面 fallback 到首页
- page_path 拼写错误,navigate 静默失败(返回 success: true)
- 页面 onLoad 中有条件跳转逻辑
-
推荐模式:
wechat_navigate(page_path='pages/xxx/index', wait_ms=3000) wechat_automator(action='page_data') ↳ data.path !== 'pages/xxx/index' → 页面未正确加载 ↳ 用 page_stack 查看完整页面栈,定位重定向原因
-
Must verify the path field: The returnedrepresents the current actual page. If it does not match the navigation target, it means the page navigation failed or was redirected.
data.path -
Common reasons for inconsistency:
- User not logged in, page intercepts and redirects to login/welcome page
- Cloud function call failed (AppID undefined), page falls back to homepage
- page_path spelling error, navigate fails silently (returns success: true)
- Conditional navigation logic exists in page onLoad
-
Recommended Pattern:
wechat_navigate(page_path='pages/xxx/index', wait_ms=3000) wechat_automator(action='page_data') ↳ data.path !== 'pages/xxx/index' → Page not loaded correctly ↳ Use page_stack to view complete page stack, locate redirection reason
返回值格式
Return Value Format
json
{"success": true, "data": {...}, "message": "操作描述"}
{"success": false, "error_code": "CLI_TIMEOUT", "message": "...", "hint": "修复提示"}
{"success": false, "error_code": "UNKNOWN_ERROR", "message": "小程序启动阶段检测到 N 个错误...", "hint": "...", "startup_errors": [...], "cdp_summary": {...}}| error_code | 含义 | 处理 |
|---|---|---|
| 必填参数缺失 | 查看 hint 字段 |
| 找不到 CLI | 检查 |
| 项目路径未配置 | 检查 |
| Node.js 未安装 | 安装 Node.js ≥ 8.0 |
| CLI 执行超时 | 开启服务端口;重启 IDE |
json
{"success": true, "data": {...}, "message": "Operation description"}
{"success": false, "error_code": "CLI_TIMEOUT", "message": "...", "hint": "Fix hint"}
{"success": false, "error_code": "UNKNOWN_ERROR", "message": "N errors detected during mini program startup...", "hint": "...", "startup_errors": [...], "cdp_summary": {...}}| error_code | Meaning | Handling |
|---|---|---|
| Required parameter missing | Check hint field |
| CLI not found | Check |
| Project path not configured | Check |
| Node.js not installed | Install Node.js ≥ 8.0 |
| CLI execution timeout | Enable service port; restart IDE |
Connection Recovery Tiers
Connection Recovery Tiers
Quick Recovery (try first):
wechat_automator(action='start') # 仅重连
wechat_automator(action='page_data') # 验证Full Recovery (when quick fails):
wechat_ide(action='open', cdp_enabled=True) # 重新打开
wechat_automator(action='start') # 重连
wechat_build(action='compile') # 重编译(自动重连 automator)
wechat_automator(action='page_data') # 验证Quick Recovery (try first):
wechat_automator(action='start') # Only reconnect
wechat_automator(action='page_data') # VerifyFull Recovery (when quick fails):
wechat_ide(action='open', cdp_enabled=True) # Re-open
wechat_automator(action='start') # Reconnect
wechat_build(action='compile') # Recompile (automatically reconnects automator)
wechat_automator(action='page_data') # Verify故障速查
Troubleshooting Quick Reference
| 症状 | 原因 | 解决 |
|---|---|---|
| CDP 采集失败(9222 无响应) | IDE 未用 cdp_enabled 启动 | |
| 截图空白 / 尺寸 0 | automator 未启动或页面未渲染 | 确认 |
| page_path 拼写错 / 未注册 | |
| 元素被遮挡或在 shadow-root 外 | 检查 WXML 结构,尝试父节点 |
| 逻辑层崩溃 / 正在重载 | 等待 3s 后重试 |
| 服务端口未开启 / IDE 未运行 | 开启服务端口; |
| 元素未找到 | 不在当前页面或 selector 错 | |
| project_path 指向子目录而非项目根目录 | 改为包含 |
| AppID 未配置或未登录 | 检查 project_path + 登录状态 |
| automator WS 连接断开(v0.9.0 daemon 架构下极少出现) | 先快速恢复(仅 |
| automator 未启动或已断开 | 同上 |
| navigate 返回 success 但页面未跳转 | page_path 不存在或拼写错误 | |
| page_data.path 与 navigate 目标不一致 | 页面被重定向(未登录/参数错/云函数失败) | 检查 AppID、登录状态、页面 onLoad 逻辑 |
| CDP errors 计数含 console.assert | devtools 内部噪音 | 过滤 |
| 子页面数据与主页面不一致 | 子页面使用独立数据获取链路 | 用 |
| 长图截图底部导航栏重复出现 | 固定区域检测失败(已在 v0.5.0 修复) | 升级到最新版本;如仍复现请反馈 |
| 小程序启动阶段有致命错误(页面无法显示) | 根据 |
| IDE 冷启动瞬态错误,运行时尚未就绪 | 忽略,继续执行 compile 刷新即可 |
| compile 成功但 IDE 显示红色 WXML 错误 | WXML 编译错误走 IDE 内部通道 | 检查中文引号 |
| wechat_navigate 内部变量作用域 bug(v0.7.0 已修复) | 升级到 v0.7.0;或改用 evaluate + wx.reLaunch |
| compile_condition 入口页被覆盖 | app 路由守卫覆盖编译入口 | 编译默认页,evaluate(wx.reLaunch) 跳转 |
| switchTab ok 但未切换 | switchTab 异步未完成 | 增加 wait_ms;v0.8.0 navigate 已自动处理 TabBar 页面 |
evaluate 报 | v0.6.0 仅支持表达式(v0.7.0 已修复) | 升级到 v0.7.0;或用 IIFE 包裹 |
| 截图看不到弹窗/蒙层 | fixed/absolute overlay 不在同一渲染层 | 以 page_data 为准 |
call_method 报 | v0.6.0 未返回路径(v0.7.0 已修复) | 升级到 v0.7.0;或先 page_data 确认 path |
| navigate TabBar 页面无效 | TabBar 页面不支持 reLaunch/navigateTo | v0.8.0 自动检测并使用 switchTab;或手动 |
| 截图显示错误页面 | screenshot connect 后页面被重置 | 使用 |
| scroll-view 页面长图只有一屏 | automator SDK 无法捕获 scroll-view 内部滚动 | 已知限制,返回 |
| Symptom | Cause | Solution |
|---|---|---|
| CDP collection failed (port 9222 unresponsive) | IDE not started with cdp_enabled | Restart with |
| Blank screenshot / size 0 | automator not started or page not rendered | Confirm |
| page_path spelled incorrectly / not registered | Verify with |
| Element blocked or outside shadow-root | Check WXML structure, try parent node |
| Logic layer crashed / reloading | Retry after waiting 3s |
| Service port not enabled / IDE not running | Enable service port; |
| Element not found | Not on current page or selector wrong | Confirm page with |
| project_path points to subdirectory instead of project root | Change to directory containing |
| AppID not configured or not logged in | Check project_path + login status |
| automator WS connection disconnected (rare under v0.9.0 daemon architecture) | First perform quick recovery (only |
| automator not started or disconnected | Same as above |
| navigate returns success but page not navigated | page_path does not exist or spelled incorrectly | Confirm path with |
| page_data.path does not match navigate target | Page redirected (not logged in/parameter error/cloud function failed) | Check AppID, login status, page onLoad logic |
| CDP errors count includes console.assert | devtools internal noise | Filter |
| Subpage data inconsistent with main page | Subpage uses independent data acquisition link | Use |
| Bottom navigation bar repeated in long screenshot | Fixed area detection failed (fixed in v0.5.0) | Upgrade to latest version; feedback if still reproducible |
| Fatal error during mini program startup (page cannot be displayed) | Fix code according to error details in |
| Transient error during IDE cold start, not ready yet | Ignore, continue to execute compile to refresh |
| compile succeeds but IDE shows red WXML error | WXML compilation errors go through IDE internal channel | Check Chinese quotes |
| Internal variable scope bug in wechat_navigate (fixed in v0.7.0) | Upgrade to v0.7.0; or use evaluate + wx.reLaunch |
| compile_condition entry page overridden | App route guard overrides compilation entry | Compile default page, navigate with evaluate(wx.reLaunch) |
| switchTab ok but not switched | switchTab not completed asynchronously | Increase wait_ms; v0.8.0 navigate automatically handles TabBar pages |
evaluate reports | v0.6.0 only supports expressions (fixed in v0.7.0) | Upgrade to v0.7.0; or wrap with IIFE |
| Pop-ups/masks not visible in screenshot | fixed/absolute overlay not in same rendering layer | Rely on page_data |
call_method reports | v0.6.0 does not return path (fixed in v0.7.0) | Upgrade to v0.7.0; or confirm path with page_data first |
| navigate to TabBar page ineffective | TabBar pages do not support reLaunch/navigateTo | v0.8.0 automatically detects and uses switchTab; or manually |
| Screenshot shows wrong page | Page reset after screenshot connection | Use |
| Long screenshot of scroll-view page only shows one screen | automator SDK cannot capture internal scroll of scroll-view | Known limitation, returns |
连接断开恢复流程
Connection Disconnection Recovery Process
当截图或自动化操作报 或 连接失败时,执行以下标准恢复流程:
Connection closedws://localhost:9420wechat_ide(action='open', project_path='...', cdp_enabled=true) # ① 重新打开项目
wechat_automator(action='start', project_path='...') # ② 重启 automator
wechat_build(action='compile', project_path='...') # ③ 重新编译When screenshot or automation operation reports or connection failure, execute the following standard recovery process:
Connection closedws://localhost:9420wechat_ide(action='open', project_path='...', cdp_enabled=true) # ① Re-open project
wechat_automator(action='start', project_path='...') # ② Restart automator
wechat_build(action='compile', project_path='...') # ③ Recompile④ 重试失败的操作
④ Retry the failed operation
---
---绝对红线
Absolute Red Lines
- ❌ 返回
open后仍继续执行后续测试操作(必须先修复错误)startup_errors - ❌ 未确认 时调用
is_login: true/previewupload - ❌ 对生产项目调用
cache_clean(clean_type='all') - ❌ 在 中执行
evaluate或不安全代码eval() - ❌ 脑补运行状态——必须以 MCP 接口返回的实际数据为准
- ❌ 同一失败操作重试超过 3 次(应转为诊断根因)
- ❌ 自动化测试中使用 硬等待(用
sleep或轮询wait_ms)page_data - ❌ 在 SOP 流程中主动调用截图——仅在用户明确要求或异常排查需要视觉确认时才截图
- ❌ 连接断开时直接走完整恢复(应先快速恢复:仅 →
start)page_data - ❌ 没改代码就 compile(浪费时间,直接 evaluate 跳转)
- ❌ compile 后不验证 automator 连接(v0.8.0 自动重连,但需 确认)
page_data - ❌ 使用 子目录作为云开发项目的 project_path
miniprogram/ - ❌ navigate 后不校验 是否匹配预期页面
page_data.path - ❌ 将 CDP 日志中 来源的
devtools://视为应用错误console.assert - ❌ 在多个并行 Agent 中同时使用 (9420 端口独占)
wechat_automator - ✅ 的
wechat_screenshot可选,留空自动保存到项目output_path目录screenshots/ - ✅ 使用任何自动化/截图功能前必须先调用
automator(action='start') - ✅ 执行 /
tap前先用input确认元素存在element_info - ✅ 前确认版本号已递增,
upload已执行build_npm - ✅ 关注 CDP 日志中的 标记(渲染阻塞/性能问题)
[Violation] - ✅ 后检查 AppID 是否为 undefined
compile - ❌ WXML 属性值中使用中文引号 或未转义双引号(编译错误且工具无法检测)
"" - ✅ 截图/操作失败后执行 →
open→start恢复连接compile - ✅ navigate 后必须通过 或
page_data校验当前页面路径page_stack - ✅ 在跨页面测试中比对同名字段的一致性
- ❌ Continue executing subsequent test operations after returns
open(must fix errors first)startup_errors - ❌ Call /
previewwithout confirminguploadis_login: true - ❌ Call on production projects
cache_clean(clean_type='all') - ❌ Execute or unsafe code in
eval()evaluate - ❌ Assume running status — must rely on actual data returned by MCP interfaces
- ❌ Retry the same failed operation more than 3 times (should switch to diagnosing root cause)
- ❌ Use hard wait in automated testing (use
sleepor pollwait_ms)page_data - ❌ Actively call screenshot in SOP process — only take screenshots when explicitly requested by user or visual confirmation is needed for troubleshooting
- ❌ Directly perform full recovery when connection is disconnected (should first perform quick recovery: only →
start)page_data - ❌ Compile without code changes (wastes time, directly navigate with evaluate)
- ❌ Do not verify automator connection after compile (v0.8.0 automatically reconnects, but need confirmation)
page_data - ❌ Use subdirectory as project_path for cloud development projects
miniprogram/ - ❌ Do not verify if matches expected page after navigate
page_data.path - ❌ Treat from
console.assertsource in CDP logs as application errorsdevtools:// - ❌ Use in multiple parallel Agents (port 9420 is exclusive)
wechat_automator - ✅ of
output_pathis optional, leave blank to automatically save to projectwechat_screenshotdirectoryscreenshots/ - ✅ Must call before using any automation/screenshot features
automator(action='start') - ✅ Use to confirm element exists before executing
element_info/tapinput - ✅ Confirm version number has been incremented and has been executed before
build_npmupload - ✅ Pay attention to marks in CDP logs (render blocking/performance issues)
[Violation] - ✅ Check if AppID is undefined after
compile - ❌ Use Chinese quotes or unescaped double quotes in WXML attribute values (compilation error that cannot be detected by tools)
"" - ✅ Execute →
open→startto restore connection after screenshot/operation failurecompile - ✅ Must verify current page path via or
page_dataafter navigatepage_stack - ✅ Compare consistency of fields with the same name in cross-page testing