wechat-devtools

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Wechat 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 uv
Editor 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
Enable
. Failure to enable will cause all CLI operations to report
CLI_TIMEOUT
.

Step 1:运行时环境检查

Step 1: Runtime Environment Check

首先调用
wechat_ide(action='status')
一次性确认所有前置条件。
检查项偏好命令失败时操作
CLI 已安装
status
cli_exists: true
安装工具并配置
WECHAT_DEVTOOLS_CLI
项目路径已配置
status
project_exists: true
配置
WECHAT_PROJECT_PATH
已登录
is_login
logged_in: true
login(qr_format='terminal')
扫码
Node.js 可用
status
node_available: true
安装 Node.js ≥ 8.0
First call
wechat_ide(action='status')
to verify all prerequisites at once.
Check ItemPreferred CommandAction on Failure
CLI Installed
status
cli_exists: true
Install the tool and configure
WECHAT_DEVTOOLS_CLI
Project Path Configured
status
project_exists: true
Configure
WECHAT_PROJECT_PATH
Logged In
is_login
logged_in: true
login(qr_format='terminal')
to scan QR code
Node.js Available
status
node_available: true
Install Node.js ≥ 8.0

Efficiency Principles

Efficiency Principles

IDE 只在会话开始时 open 一次,compile 只在代码变更后执行,页面跳转优先用 evaluate 而非 navigate。
场景正确做法错误做法
没改代码,换页面测试
evaluate(expression="wx.reLaunch({url:'/pages/xxx/index'}); 'ok'")
page_data
重新 open → compile
改了代码
compile
page_data
验证(compile 自动重连 automator)
重新 open → compile
连接断开先快速恢复(仅
start
直接走完整恢复

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.
ScenarioCorrect PracticeIncorrect Practice
Testing different pages without code changes
evaluate(expression="wx.reLaunch({url:'/pages/xxx/index'}); 'ok'")
page_data
Re-open → compile
Code changed
compile
page_data
verification (compile automatically reconnects automator)
Re-open → compile
Connection disconnectedQuick recovery first (only
start
)
Directly perform full recovery

API 速查表

API Cheat Sheet

wechat_ide
— IDE 生命周期

wechat_ide
— IDE Lifecycle

action功能关键参数
open
打开 IDE/项目(cdp_enabled 时自动做启动健康检查)
cdp_enabled=true
(开启 CDP 9222 端口,自动采集 5s CDP 日志检测启动错误)
login
扫码登录
qr_format="terminal"
is_login
检查登录状态
close
/
quit
关闭项目 / 退出 IDE
status
环境诊断
actionFunctionKey Parameters
open
Open IDE/project (automatically performs startup health check when cdp_enabled)
cdp_enabled=true
(Enable CDP port 9222, automatically collect 5s CDP logs to detect startup errors)
login
QR code login
qr_format="terminal"
is_login
Check login status
close
/
quit
Close project / Exit IDE
status
Environment diagnosis

wechat_build
— 构建与发布

wechat_build
— Building and Publishing

action功能关键参数
compile
编译检查(捕获错误/警告,成功后自动重连 automator)
  • 注意:compile_condition 对 tabBar 页面可能无效(app 路由守卫覆盖),用 evaluate + wx.reLaunch 跳转更可靠
|
preview
| 生成预览二维码 |
qr_format="terminal"
| |
upload
| 上传到微信后台 |
version
(必填)
,
desc?
| |
build_npm
| 构建 NPM 依赖(upload 前必做) | — | |
cache_clean
| 清除缓存 |
clean_type="compile"
|
actionFunctionKey Parameters
compile
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
|
preview
| Generate preview QR code |
qr_format="terminal"
| |
upload
| Upload to WeChat backend |
version
(required)
,
desc?
| |
build_npm
| Build NPM dependencies (mandatory before upload) | — | |
cache_clean
| Clear cache |
clean_type="compile"
|

wechat_automator
— 自动化交互

wechat_automator
— Automated Interaction

前提:先调用
start
开启自动化端口(整个会话仅需一次)。
action功能必填参数
start
开启自动化端口
tap
点击元素
selector
input
输入文本
selector
,
value
element_info
获取元素详情(文本/尺寸/WXML)
selector
set_data
热更新页面 data(无需重编译)
data_json
call_method
调用页面方法
method
,
args_json?
call_wx
调用 wx API
method
mock_wx
Mock wx API 返回值
method
,
result_json
evaluate
执行 JS 表达式(逻辑层万能钥匙)
expression
  • 注意:v0.7.0 起支持声明语句(const/let/var)
  • v0.9.2:compile 后自动 invalidate 旧缓存连接再重连,daemon 健康检查 3s 超时保护,navigate currentPage 轮询 2s 独立超时
  • v0.9.0:底层改为持久化 Node daemon(NDJSON 协议),WS 连接按端口缓存复用,工具调用延迟 ~3ms
|
page_stack
| 获取页面栈 | — | |
page_data
| 获取当前页面 data |
expected_path?
(轮询验证页面路径) | |
system_info
| 获取运行时系统信息 | — | |
storage
| 读取本地缓存 |
key?
(空=列出全部) |
Prerequisite: Call
start
first to enable the automation port (only required once per session).
actionFunctionRequired Parameters
start
Enable automation port
tap
Click element
selector
input
Input text
selector
,
value
element_info
Get element details (text/size/WXML)
selector
set_data
Hot update page data (no recompilation needed)
data_json
call_method
Call page method
method
,
args_json?
call_wx
Call wx API
method
mock_wx
Mock wx API return value
method
,
result_json
evaluate
Execute JS expression (universal key for logic layer)
expression
  • 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
|
page_stack
| Get page stack | — | |
page_data
| Get current page data |
expected_path?
(poll to verify page path) | |
system_info
| Get runtime system information | — | |
storage
| Read local cache |
key?
(empty = list all) |

wechat_inspector
— 日志采集

wechat_inspector
— Log Collection

action功能关键参数
console
采集 console 日志和 JS 异常
duration=10
,
log_type="all"
cdp
CDP 协议采集底层日志(WXML/渲染层)
duration=10
,
detail_level="concise"
,
max_logs=50
cdp 前提:以
cdp_enabled=true
打开项目,确保端口 9222 可用。
actionFunctionKey Parameters
console
Collect console logs and JS exceptions
duration=10
,
log_type="all"
cdp
Collect underlying logs via CDP protocol (WXML/rendering layer)
duration=10
,
detail_level="concise"
,
max_logs=50
CDP Prerequisite: Open the project with
cdp_enabled=true
and ensure port 9222 is available.

wechat_screenshot
— 截图

wechat_screenshot
— Screenshot

  • output_path
    (可选):截图保存路径。留空则自动保存到项目目录下
    screenshots/
    文件夹
  • full_page
    (默认
    true
    ):设为
    false
    只截当前视口
  • scroll_top
    (可选):截图前滚动到的位置(逻辑像素),配合
    full_page=false
    使用
  • page_path
    (可选):确保截图前在指定页面上,若当前页面不匹配则自动跳转
  • 前提:先调用
    wechat_automator(action='start')
  • 注意:不要主动截图,仅在用户明确要求或排查异常需要视觉确认时才调用
  • 限制:使用
    scroll-view
    组件滚动的页面无法长图拼接(automator SDK 限制),仅截取当前视口
  • 限制:截图可能无法捕获 fixed/absolute overlay(弹窗、蒙层),以 page_data 为准
  • 路径规约:推荐
    <project>/screenshots/
    或显式绝对路径。避免写入
    .claude/image-cache/
    — 这是 Claude Code 的用户发图缓存目录,MCP 截图混入会互相污染
  • output_path
    (optional): Screenshot save path. Leave blank to automatically save to the
    screenshots/
    folder under the project directory
  • full_page
    (default
    true
    ): Set to
    false
    to capture only the current viewport
  • scroll_top
    (optional): Position to scroll to before taking the screenshot (logical pixels), use with
    full_page=false
  • page_path
    (optional): Ensure being on the specified page before taking the screenshot, automatically navigate if current page does not match
  • Prerequisite: Call
    wechat_automator(action='start')
    first
  • Note: Do not take screenshots actively, only call when explicitly requested by the user or visual confirmation is needed for troubleshooting
  • Limitation: Pages using
    scroll-view
    component cannot be stitched into long screenshots (automator SDK limitation), only the current viewport is captured
  • Limitation: Screenshots may not capture fixed/absolute overlays (pop-ups, masks), rely on
    page_data
    instead
  • Path Convention: Recommended to use
    <project>/screenshots/
    or explicit absolute path. Avoid writing to
    .claude/image-cache/
    — this is the user image cache directory for Claude Code, mixing MCP screenshots will cause mutual contamination

wechat_navigate
— 跳转并采集日志

wechat_navigate
— Navigate and Collect Logs

  • page_path
    必填):如
    pages/index/index
  • wait_ms
    :等待毫秒,建议 3000
  • clear_logs
    :是否过滤历史 CDP 日志,默认
    true
  • check_data
    :跳转后是否检查 page_data 空值,默认
    true
  • detail_level
    concise
    (仅 errors+warnings)或
    full
  • v0.8.0 新增:自动检测 TabBar 页面并使用
    switchTab
    替代
    reLaunch
    ,返回
    navigation_method
    字段
  • 前提:需
    automator start
    +
    cdp_enabled=true
  • page_path
    (required): e.g.
    pages/index/index
  • wait_ms
    : Wait time in milliseconds, recommended 3000
  • clear_logs
    : Whether to filter historical CDP logs, default
    true
  • check_data
    : Whether to check for empty page_data after navigation, default
    true
  • detail_level
    :
    concise
    (only errors+warnings) or
    full
  • Added in v0.8.0: Automatically detects TabBar pages and uses
    switchTab
    instead of
    reLaunch
    , returns
    navigation_method
    field
  • Prerequisite: Requires
    automator start
    +
    cdp_enabled=true

wechat_file
— 文件读取

wechat_file
— File Reading

action功能必填参数
project_info
项目完整信息(app.json + 目录结构)
list_pages
所有页面列表(含文件完整性检查)
read_page
读取页面源码(wxml/wxss/js/json)
page_path
read_file
读取任意单文件(最多 800 行)
file_path
云函数与云数据库管理:本 MCP 自 v0.9.5 起不再提供
wechat_cloud
工具。请改用 CloudBase MCP
manageFunctions
/
readNoSqlDatabaseContent
/
writeNoSqlDatabaseContent
等),无 IDE 依赖且覆盖更完整。

actionFunctionRequired Parameters
project_info
Get complete project information (app.json + directory structure)
list_pages
Get all page list (including file integrity check)
read_page
Read page source code (wxml/wxss/js/json)
page_path
read_file
Read any single file (max 800 lines)
file_path
Cloud Function and Cloud Database Management: This MCP no longer provides
wechat_cloud
tools since v0.9.5. Please use CloudBase MCP instead (with
manageFunctions
/
readNoSqlDatabaseContent
/
writeNoSqlDatabaseContent
etc.), which has no IDE dependency and covers more features.

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
的根目录。云开发项目的
miniprogram/
是子目录,不能作为 project_path。
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
project.config.json
. For cloud development projects,
miniprogram/
is a subdirectory and cannot be used as project_path.

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 availability
No need to re-open IDE or perform cache_clean. Only execute after modifying mini program source code.

页面跳转标准方法

Standard Page Navigation Methods

场景方式
普通页面
evaluate(expression="wx.navigateTo({url:'<path>'}); 'ok'")
tabBar 页面
wechat_navigate(page_path='<tabBar路径>')
自动走 switchTab
强制重置
evaluate(expression="wx.reLaunch({url:'<path>'}); 'ok'")
跳转后
page_data
校验
path
匹配预期
ScenarioMethod
Normal page
evaluate(expression="wx.navigateTo({url:'<path>'}); 'ok'")
TabBar page
wechat_navigate(page_path='<tabBar path>')
automatically uses switchTab
Force reset
evaluate(expression="wx.reLaunch({url:'<path>'}); 'ok'")
After navigationVerify
path
matches expectation via
page_data

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 tool

SOP 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

undefined
undefined

SOP 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 changes
Mock 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
undefined
mock_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
undefined

SOP 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
undefined

SOP J:小程序 + 管理后台并行数据比对

SOP J: Parallel Data Comparison Between Mini Program and Management Backend

适用场景:验证小程序前端数据与管理后台数据的一致性
undefined
Applicable 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)
场景推荐参数
快速诊断
duration=5, detail_level='concise', max_logs=20
深度排查
duration=10, detail_level='full', max_logs=100
页面巡检
duration=3, detail_level='concise', max_logs=30
重要: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)
ScenarioRecommended Parameters
Quick diagnosis
duration=5, detail_level='concise', max_logs=20
In-depth troubleshooting
duration=10, detail_level='full', max_logs=100
Page inspection
duration=3, detail_level='concise', max_logs=30
Important: CDP error count may include accumulated historical logs across pages.
clear_logs=true
(default) in v0.4.0 filters historical logs based on timestamp, but it is still recommended to use
page_data
as the final verification standard.

CDP 日志噪音过滤

CDP Log Noise Filtering

以下日志来源属于开发工具内部噪音,不代表应用错误,应在判断时排除:
source 前缀说明处理
devtools://devtools/
开发者工具自身的断言/警告忽略
ide:///extensions/
IDE 扩展注入的提醒区分对待
以下 message 模式属于框架级提醒,非应用错误:
message 模式说明
console.assert
devtools 内部断言
SharedArrayBufferIssue
浏览器引擎警告
getSystemInfo API 提示
废弃 API 迁移提醒
wx.saveFile 即将废弃
/
wx.removeSavedFile 即将废弃
框架 API 废弃预警
[Component] property "xxx" received type-uncompatible value
组件属性类型不匹配警告
判断原则: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 PrefixDescriptionHandling
devtools://devtools/
Assertions/warnings from the developer tool itselfIgnore
ide:///extensions/
Reminders injected by IDE extensionsTreat differently
The following message patterns are framework-level reminders, not application errors:
message PatternDescription
console.assert
Internal assertions of devtools
SharedArrayBufferIssue
Browser engine warning
getSystemInfo API prompt
Deprecated API migration reminder
wx.saveFile will be deprecated
/
wx.removeSavedFile will be deprecated
Framework API deprecation warning
[Component] property "xxx" received type-uncompatible value
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 by
page_data
as the final verification standard.

page_data 使用注意事项

page_data Notes

  1. 必须校验 path 字段:返回的
    data.path
    表示当前实际页面,如果与导航目标不一致,说明页面跳转失败或被重定向。
  2. 常见不一致原因
    • 用户未登录,页面拦截跳转到登录/欢迎页
    • 云函数调用失败(AppID undefined),页面 fallback 到首页
    • page_path 拼写错误,navigate 静默失败(返回 success: true)
    • 页面 onLoad 中有条件跳转逻辑
  3. 推荐模式
    wechat_navigate(page_path='pages/xxx/index', wait_ms=3000)
    wechat_automator(action='page_data')
      ↳ data.path !== 'pages/xxx/index' → 页面未正确加载
      ↳ 用 page_stack 查看完整页面栈,定位重定向原因

  1. Must verify the path field: The returned
    data.path
    represents the current actual page. If it does not match the navigation target, it means the page navigation failed or was redirected.
  2. 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
  3. 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含义处理
PARAM_MISSING
必填参数缺失查看 hint 字段
CLI_NOT_FOUND
找不到 CLI检查
WECHAT_DEVTOOLS_CLI
PROJECT_PATH_MISSING
项目路径未配置检查
WECHAT_PROJECT_PATH
NODE_NOT_FOUND
Node.js 未安装安装 Node.js ≥ 8.0
CLI_TIMEOUT
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_codeMeaningHandling
PARAM_MISSING
Required parameter missingCheck hint field
CLI_NOT_FOUND
CLI not foundCheck
WECHAT_DEVTOOLS_CLI
PROJECT_PATH_MISSING
Project path not configuredCheck
WECHAT_PROJECT_PATH
NODE_NOT_FOUND
Node.js not installedInstall Node.js ≥ 8.0
CLI_TIMEOUT
CLI execution timeoutEnable 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')                # Verify
Full 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 启动
wechat_ide(action='open', cdp_enabled=True)
重启
截图空白 / 尺寸 0automator 未启动或页面未渲染确认
start
已调用;增加
wait_ms=3000
Page is not found
page_path 拼写错 / 未注册
wechat_file(action='list_pages')
核查
Element is obfuscated
元素被遮挡或在 shadow-root 外检查 WXML 结构,尝试父节点
Cannot find context
逻辑层崩溃 / 正在重载等待 3s 后重试
CLI_TIMEOUT
服务端口未开启 / IDE 未运行开启服务端口;
wechat_ide(action='open')
元素未找到不在当前页面或 selector 错
page_stack
确认页面;
element_info
验证 selector
Using AppID: undefined
project_path 指向子目录而非项目根目录改为包含
project.config.json
的目录
appid missing
云函数失败
AppID 未配置或未登录检查 project_path + 登录状态
Connection closed
截图/操作失败
automator WS 连接断开(v0.9.0 daemon 架构下极少出现)先快速恢复(仅
start
page_data
);失败再完整恢复(见 Recovery Tiers)
Failed connecting to ws://localhost:9420
automator 未启动或已断开同上
navigate 返回 success 但页面未跳转page_path 不存在或拼写错误
list_pages
确认路径;用
page_stack
验证
page_data.path 与 navigate 目标不一致页面被重定向(未登录/参数错/云函数失败)检查 AppID、登录状态、页面 onLoad 逻辑
CDP errors 计数含 console.assertdevtools 内部噪音过滤
devtools://
来源,以 page_data 为准
子页面数据与主页面不一致子页面使用独立数据获取链路
evaluate
直接调用 API 对比返回值
长图截图底部导航栏重复出现固定区域检测失败(已在 v0.5.0 修复)升级到最新版本;如仍复现请反馈
open
返回 startup_errors
小程序启动阶段有致命错误(页面无法显示)根据
startup_errors
中的错误详情修复代码,修复后重新
open
simulator not found
/
subPackages of undefined
IDE 冷启动瞬态错误,运行时尚未就绪忽略,继续执行 compile 刷新即可
compile 成功但 IDE 显示红色 WXML 错误WXML 编译错误走 IDE 内部通道检查中文引号
""
、未关闭标签;查看
wxml_errors
字段
currentPageTimeout is not defined
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 报
Unexpected token 'const'
v0.6.0 仅支持表达式(v0.7.0 已修复)升级到 v0.7.0;或用 IIFE 包裹
截图看不到弹窗/蒙层fixed/absolute overlay 不在同一渲染层以 page_data 为准
call_method 报
page.xxx not exists
且无页面信息
v0.6.0 未返回路径(v0.7.0 已修复)升级到 v0.7.0;或先 page_data 确认 path
navigate TabBar 页面无效TabBar 页面不支持 reLaunch/navigateTov0.8.0 自动检测并使用 switchTab;或手动
evaluate(wx.switchTab)
截图显示错误页面screenshot connect 后页面被重置使用
page_path
参数确保截图前在正确页面
scroll-view 页面长图只有一屏automator SDK 无法捕获 scroll-view 内部滚动已知限制,返回
isScrollViewPage: true
;改用页面级滚动或 canvas 截图
SymptomCauseSolution
CDP collection failed (port 9222 unresponsive)IDE not started with cdp_enabledRestart with
wechat_ide(action='open', cdp_enabled=True)
Blank screenshot / size 0automator not started or page not renderedConfirm
start
has been called; increase
wait_ms=3000
Page is not found
page_path spelled incorrectly / not registeredVerify with
wechat_file(action='list_pages')
Element is obfuscated
Element blocked or outside shadow-rootCheck WXML structure, try parent node
Cannot find context
Logic layer crashed / reloadingRetry after waiting 3s
CLI_TIMEOUT
Service port not enabled / IDE not runningEnable service port;
wechat_ide(action='open')
Element not foundNot on current page or selector wrongConfirm page with
page_stack
; verify selector with
element_info
Using AppID: undefined
project_path points to subdirectory instead of project rootChange to directory containing
project.config.json
appid missing
cloud function failed
AppID not configured or not logged inCheck project_path + login status
Connection closed
screenshot/operation failed
automator WS connection disconnected (rare under v0.9.0 daemon architecture)First perform quick recovery (only
start
page_data
); if failed, perform full recovery (see Recovery Tiers)
Failed connecting to ws://localhost:9420
automator not started or disconnectedSame as above
navigate returns success but page not navigatedpage_path does not exist or spelled incorrectlyConfirm path with
list_pages
; verify with
page_stack
page_data.path does not match navigate targetPage redirected (not logged in/parameter error/cloud function failed)Check AppID, login status, page onLoad logic
CDP errors count includes console.assertdevtools internal noiseFilter
devtools://
sources, rely on page_data
Subpage data inconsistent with main pageSubpage uses independent data acquisition linkUse
evaluate
to directly call API for comparison
Bottom navigation bar repeated in long screenshotFixed area detection failed (fixed in v0.5.0)Upgrade to latest version; feedback if still reproducible
open
returns startup_errors
Fatal error during mini program startup (page cannot be displayed)Fix code according to error details in
startup_errors
, re-open after fix
simulator not found
/
subPackages of undefined
Transient error during IDE cold start, not ready yetIgnore, continue to execute compile to refresh
compile succeeds but IDE shows red WXML errorWXML compilation errors go through IDE internal channelCheck Chinese quotes
""
, unclosed tags; check
wxml_errors
field
currentPageTimeout is not defined
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 overriddenApp route guard overrides compilation entryCompile default page, navigate with evaluate(wx.reLaunch)
switchTab ok but not switchedswitchTab not completed asynchronouslyIncrease wait_ms; v0.8.0 navigate automatically handles TabBar pages
evaluate reports
Unexpected token 'const'
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 screenshotfixed/absolute overlay not in same rendering layerRely on page_data
call_method reports
page.xxx not exists
and no page info
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 ineffectiveTabBar pages do not support reLaunch/navigateTov0.8.0 automatically detects and uses switchTab; or manually
evaluate(wx.switchTab)
Screenshot shows wrong pagePage reset after screenshot connectionUse
page_path
parameter to ensure being on correct page before screenshot
Long screenshot of scroll-view page only shows one screenautomator SDK cannot capture internal scroll of scroll-viewKnown limitation, returns
isScrollViewPage: true
; use page-level scrolling or canvas screenshot instead

连接断开恢复流程

Connection Disconnection Recovery Process

当截图或自动化操作报
Connection closed
ws://localhost:9420
连接失败时,执行以下标准恢复流程:
wechat_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
Connection closed
or
ws://localhost:9420
connection failure, execute the following standard recovery process:
wechat_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
    时调用
    preview
    /
    upload
  • ❌ 对生产项目调用
    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
    确认)
  • ❌ 使用
    miniprogram/
    子目录作为云开发项目的 project_path
  • ❌ navigate 后不校验
    page_data.path
    是否匹配预期页面
  • ❌ 将 CDP 日志中
    devtools://
    来源的
    console.assert
    视为应用错误
  • ❌ 在多个并行 Agent 中同时使用
    wechat_automator
    (9420 端口独占)
  • wechat_screenshot
    output_path
    可选,留空自动保存到项目
    screenshots/
    目录
  • ✅ 使用任何自动化/截图功能前必须先调用
    automator(action='start')
  • ✅ 执行
    tap
    /
    input
    前先用
    element_info
    确认元素存在
  • upload
    前确认版本号已递增,
    build_npm
    已执行
  • ✅ 关注 CDP 日志中的
    [Violation]
    标记(渲染阻塞/性能问题)
  • compile
    后检查 AppID 是否为 undefined
  • ❌ WXML 属性值中使用中文引号
    ""
    或未转义双引号(编译错误且工具无法检测)
  • ✅ 截图/操作失败后执行
    open
    start
    compile
    恢复连接
  • ✅ navigate 后必须通过
    page_data
    page_stack
    校验当前页面路径
  • ✅ 在跨页面测试中比对同名字段的一致性
  • ❌ Continue executing subsequent test operations after
    open
    returns
    startup_errors
    (must fix errors first)
  • ❌ Call
    preview
    /
    upload
    without confirming
    is_login: true
  • ❌ Call
    cache_clean(clean_type='all')
    on production projects
  • ❌ Execute
    eval()
    or unsafe code in
    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
    sleep
    hard wait in automated testing (use
    wait_ms
    or poll
    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
    page_data
    confirmation)
  • ❌ Use
    miniprogram/
    subdirectory as project_path for cloud development projects
  • ❌ Do not verify if
    page_data.path
    matches expected page after navigate
  • ❌ Treat
    console.assert
    from
    devtools://
    source in CDP logs as application errors
  • ❌ Use
    wechat_automator
    in multiple parallel Agents (port 9420 is exclusive)
  • output_path
    of
    wechat_screenshot
    is optional, leave blank to automatically save to project
    screenshots/
    directory
  • ✅ Must call
    automator(action='start')
    before using any automation/screenshot features
  • ✅ Use
    element_info
    to confirm element exists before executing
    tap
    /
    input
  • ✅ Confirm version number has been incremented and
    build_npm
    has been executed before
    upload
  • ✅ Pay attention to
    [Violation]
    marks in CDP logs (render blocking/performance issues)
  • ✅ 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
    start
    compile
    to restore connection after screenshot/operation failure
  • ✅ Must verify current page path via
    page_data
    or
    page_stack
    after navigate
  • ✅ Compare consistency of fields with the same name in cross-page testing