WeChat Mini Program Dev MCP
This server enables AI assistants to automate testing and interaction with WeChat Mini Programs through MCP tools, similar to Playwright but specialized for the WeChat ecosystem.
Application Management
Establish and manage automation sessions with WeChat Developer Tools via WebSocket or CLI launch
Navigate within mini programs using
navigateTo,redirectTo,reLaunch,switchTab, andnavigateBackCapture screenshots of the current viewport
Call WeChat Mini Program API methods (e.g.,
wx.showToast)Retrieve and optionally clear console logs
Get current page information including path, query parameters, dimensions, scroll position, and data
Page Operations
Query single or multiple elements using CSS selectors
Wait for elements to appear or for specific timeouts
Get and set page data objects using the
setDatamechanismCall methods exposed on page instances
Element Interactions
Simulate tap/click events and text input on WXML elements
Get element properties: WXML (inner/outer), styles, attributes, size, and bounding rectangles
Query nested elements within other elements (element.$ and element.$$)
Scroll
scroll-viewcomponents to specific positions
Custom Component Support
Access elements inside custom components using
innerSelectorparameterCall methods and get/set rendering data on custom component instances (requires automator 0.6.0+ and base library 2.9.0+)
Flexible Configuration
Configure connection mode, CLI path, ports, timeouts, and authentication via environment variables
Override connection settings on individual tool calls
Launch new Developer Tools instances or connect to existing ones
Automates WeChat Developer Tools for WeChat Mini Programs, enabling navigation, inspection, and manipulation of mini-program pages, elements, and components through the miniprogram-automator API.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@WeChat Mini Program Dev MCP navigate to the user profile page and take a screenshot"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
WeChat Mini Program MCP Server
A FastMCP-based server that automates WeChat Developer Tools via miniprogram-automator. This server provides MCP tools that allow AI assistants to navigate, inspect, and manipulate mini program pages—similar to playwright-mcp, but tailored for the WeChat ecosystem.
Prerequisites
WeChat Developer Tools installed with command-line access (
cli/cli.bat) enabled.Node.js 18+ and
npminstalled locally.A mini program project that can be opened in the Developer Tools.
Related MCP server: miniprogram-automator-mcp
Quick Start (npm package)
@yfme/weapp-dev-mcp has been published to npm. Regular users do not need to clone the repository or manually execute node dist/index.js.
Run with npx
npx -y @yfme/weapp-dev-mcpInstall globally or in a project
npm install -g @yfme/weapp-dev-mcp
weapp-dev-mcpOr as a project dependency:
npm install --save-dev @yfme/weapp-dev-mcp
npx weapp-dev-mcpOnly when developing within this repository is it recommended to run
node dist/index.jsdirectly. General users should start via the npm package method above.
MCP Client Integration
Configuration
To use this server in Claude Desktop or other MCP clients, add the following to your configuration file:
{
"mcpServers": {
"weapp-dev": {
"command": "npx",
"args": [
"-y",
"@yfme/weapp-dev-mcp"
],
"env": {
"WEAPP_WS_ENDPOINT": "ws://localhost:9420"
}
}
}
}Claude Code Auto-Approval for Tools
Since calling MCP tools via Claude Code triggers tool permission requests, the connection state between the MCP and WeChat Developer Tools might be lost. Because retrieving console output is highly dependent on the connection state, it may be impossible to obtain output logs coherently. Therefore, it is recommended to add permissions manually:
Create a .claude/settings.local.json file in your project directory, or add the following content to an existing file to allow direct tool calls without confirmation, or add the specific tools you wish to allow without confirmation as needed:
{
"permissions": {
"allow": [
"mcp__weapp-dev-mcp__mp_ensureConnection",
"mcp__weapp-dev-mcp__mp_navigate",
"mcp__weapp-dev-mcp__mp_screenshot",
"mcp__weapp-dev-mcp__mp_callWx",
"mcp__weapp-dev-mcp__mp_getLogs",
"mcp__weapp-dev-mcp__mp_currentPage",
"mcp__weapp-dev-mcp__mp_listProjects",
"mcp__weapp-dev-mcp__mp_setDefaultProject",
"mcp__weapp-dev-mcp__page_getElement",
"mcp__weapp-dev-mcp__page_getElements",
"mcp__weapp-dev-mcp__page_waitElement",
"mcp__weapp-dev-mcp__page_waitTimeout",
"mcp__weapp-dev-mcp__page_getData",
"mcp__weapp-dev-mcp__page_setData",
"mcp__weapp-dev-mcp__page_callMethod",
"mcp__weapp-dev-mcp__element_tap",
"mcp__weapp-dev-mcp__element_input",
"mcp__weapp-dev-mcp__element_callMethod",
"mcp__weapp-dev-mcp__element_getData",
"mcp__weapp-dev-mcp__element_setData",
"mcp__weapp-dev-mcp__element_getInnerElement",
"mcp__weapp-dev-mcp__element_getInnerElements",
"mcp__weapp-dev-mcp__element_getWxml",
"mcp__weapp-dev-mcp__element_getStyles",
"mcp__weapp-dev-mcp__element_scrollTo",
"mcp__weapp-dev-mcp__element_getAttributes",
"mcp__weapp-dev-mcp__element_getBoundingClientRect"
]
}
}Note: The tool name format is
mcp__<server_name>__<tool_name>. Please ensure the server name matches the one in your MCP configuration.
Starting WeChat Developer Tools
Before using the MCP server, you must start the WeChat Developer Tools and enable the WebSocket service.
💡 Before you begin:
Open WeChat Developer Tools.
Go to Settings → Security Settings → Service Port.
Enable "HTTP Debugging" and "Automation Testing".
Start via Command Line
Use the command line to start WeChat Developer Tools and automatically enable the WebSocket service:
macOS/Linux:
/Applications/wechatwebdevtools.app/Contents/MacOS/cli auto --project /path/to/your/project --auto-port 9420Windows:
"C:\Program Files (x86)\Tencent\微信web开发者工具\cli.bat" auto --project C:\path\to\your\project --auto-port 9420Where:
--projectspecifies the path to the mini program project directory (please replace with the actual project path).--auto-portspecifies the WebSocket service port (default is 9420).
⚠️ Warning Due to sandbox mechanisms, some clients do not allow MCP to access the WeChat Developer Tools CLI outside of the project directory, so only the WebSocket service method is introduced here.
Environment Variable Configuration
Control how the automation tool connects to WeChat Developer Tools via environment variables:
Variable | Description |
| [Recommended] The WebSocket endpoint of the running Developer Tools. When set, the server uses |
| Path to the WeChat Developer Tools CLI (optional if the default path works). |
| Force |
| Preferred port when launching Developer Tools (falls back to an available port). |
| Launch timeout in milliseconds (default 30000). |
| Passed to |
| Passed to |
| Set to |
| Additional CLI arguments at launch (space-separated). |
| Working directory passed to the Developer Tools process. |
| Set to |
| Set to |
| Launch timeout in milliseconds (default 45000). |
| Connection timeout in milliseconds (default 45000). |
| Mini program project path (optional). |
Note: When launching Developer Tools (
launchmode), you must provide the mini program project directory via MCP tool parameters: provide it viaconnection.projectPathbefore performing operations (e.g., viamp_ensureConnection). Once established, this value will persist in subsequent calls.
Tool calls can override most of these defaults via the connection object.
Available Tools
Application Tools
mp_ensureConnection– Ensures the automation session is ready; optionally force reconnect or override connection settings.mp_navigate– Navigate within the mini program; supportsnavigateTo,redirectTo,reLaunch,switchTab, ornavigateBack.mp_screenshot– Capture a screenshot and return it (or save to disk).mp_callWx– Call WeChat Mini Program API methods (e.g.,wx.showToast).mp_getLogs– Retrieve mini program console logs, optionally clearing them after retrieval.mp_currentPage– Get current page information (path, query parameters, dimensions, scroll position); returns page data ifwithDatais true.mp_listProjects– List recent projects in WeChat Developer Tools for easy selection of project directories.mp_setDefaultProject– Set the default mini program project path; once set, the next connection will automatically use this project.
Page Tools
page_getElement– Get a page element via selector, returns element summary (tagName, text, value, size, offset); setwithWxml: trueto additionally return the full outerWxml; supports [index=N] syntax to select the Nth element.page_getElements– Get an array of page elements via selector, returns summary for each; setwithWxml: trueto additionally return the full outerWxml for each; supports [index=N] syntax.page_waitElement– Wait for an element to appear on the page (⚠️ not applicable to elements inside custom components); supports [index=N] syntax; adds timeout and retry interval parameters.page_waitTimeout– Wait for a specified number of milliseconds.page_getData– Get the data object of the current page, can specify a path (supports nested paths like 'user.name').page_setData– Update the current page's data usingsetData; adds a verify option to confirm if data was actually updated successfully.page_callMethod– Call a method exposed on the current page instance.
Element Tools
element_tap– Simulate a tap on a WXML element via CSS selector; supports [index=N] syntax to select the Nth element; supports x/y coordinate offset tapping; enhanced stability: waits for element interactivity, automatically verifies if the page path changed after tapping.element_input– Input text into an element (applicable toinputandtextareacomponents).element_callMethod– Call a method on a custom component instance.element_getData– Get rendering data of a custom component instance.element_setData– Set rendering data of a custom component instance.element_getInnerElement– Get an element inside an element (equivalent toelement.$(selector)), returns element summary; setwithWxml: trueto additionally return the full outerWxml.element_getInnerElements– Get an array of elements inside an element (equivalent toelement.$$(selector)), returns element summary; setwithWxml: trueto additionally return the full outerWxml for each.element_getWxml– Get element WXML (inner or outer).element_getStyles– Get CSS style values of an element,namesparameter is an array of style names (e.g.,['color', 'fontSize']).element_scrollTo– Scroll ascroll-viewcomponent to a specified position (x, y).element_getAttributes– Get attribute values of an element,namesparameter is an array of attribute names (e.g.,['class', 'id', 'data-index']).element_getBoundingClientRect– Get the bounding rectangle information of an element relative to the viewport (left, top, width, height, right, bottom), considering CSS transforms (currently only supports ID and class selectors).
Each tool accepts an optional connection block to override environment defaults (project path, CLI path, WebSocket endpoint, etc.).
Usage Tips
General Tips
Before connecting, enable automation in WeChat Developer Tools (
Settings → Security Settings → Service Port).It is recommended to call
mp_ensureConnectionfirst to verify the connection and view system/page details.Using
WEAPP_AUTOCLOSE=trueis suitable for stateless, one-off interactions.Always use absolute paths when navigating (starting with
/):/pages/mine/mine.Use
switchTabfor tabBar pages, andnavigateTofor regular pages.
Operating Custom Components
There are two ways to operate custom components:
Method 1: Use the innerSelector parameter (Recommended)
Applicable to tools like element_tap, element_input, element_getWxml, etc.:
{
"selector": "#my-component",
"innerSelector": ".inner-button"
}selector: The selector for the custom component.innerSelector: The selector for the element inside the component.
Method 2: Use element inner query tools
Applicable to element_getInnerElement and element_getInnerElements:
{
"selector": "#my-component",
"targetSelector": ".inner-button"
}Limitations
page_waitElementdoes not apply to elements inside custom components. Please usepage_waitTimeoutin conjunction with element query tools for polling checks.
AutoLaunch Feature
When WEAPP_AUTOLAUNCH=true is configured, the MCP server can automatically detect and launch WeChat Developer Tools:
Auto-detect port: Detects if a service is running on port 9420.
Launch if no service: If the port is not occupied, it automatically calls the CLI to launch the Developer Tools.
Project selection:
If a default project is configured, it is used automatically.
If no default project exists, it automatically lists recent projects for selection.
Supports entering a project number (e.g.,
1) or the full path.
Configuration Example
{
"mcpServers": {
"weapp-dev": {
"command": "npx",
"args": ["-y", "weapp-dev-mcp"],
"env": {
"WEAPP_AUTOLAUNCH": "true",
"WEAPP_PROJECT_PATH": "D:\\path\\to\\your\\project"
}
}
}
}Workflow
Upon first connection,
WEAPP_AUTOLAUNCH=trueis detected.Checks if a service is running on port 9420.
If no service, automatically launches Developer Tools (using
cli.bat auto --project <path> --auto-port 9420).Waits 45 seconds for the Developer Tools to be ready.
Establishes a WebSocket connection.
Subsequent connections automatically reuse the existing connection.
Tip: After setting a default project using
mp_setDefaultProject, you do not need to select the project again for the next connection.
Available Tools
27 toolselement_callMethodB
调用组件实例指定方法,仅自定义组件可以使用。
Inputs: selector (required), method (required), connection, innerSelector, +1 more.
element_getAttributesC
获取元素的特性值。names 为特性名数组(如 ['class', 'id', 'data-index'])。
Inputs: selector (required), names (required), connection, innerSelector.
element_getBoundingClientRectA
获取元素相对于视口的边界矩形信息(left、top、width、height、right、bottom)。此方法返回的是考虑 CSS transform 变换后的实际渲染尺寸和位置。支持跨组件查询:若需获取自定义组件内部元素,可将 selector 设为组件选择器,innerSelector 设为内部元素选择器。注意:目前仅支持 ID 选择器、类选择器。
Inputs: selector (required), connection, innerSelector.
element_getDataC
获取组件实例渲染数据,仅自定义组件可以使用。
Inputs: selector (required), connection, innerSelector, path.
element_getInnerElementD
在元素范围内获取元素,相当于 element.$(selector)。设置 withWxml 为 true 可额外返回每个元素的完整 outerWxml。
Inputs: selector (required), targetSelector (required), connection, innerSelector, +1 more.
element_getInnerElementsC
在元素范围内获取元素数组,相当于 element.$$(selector)。设置 withWxml 为 true 可额外返回每个元素的完整 outerWxml。
Inputs: selector (required), targetSelector (required), connection, innerSelector, +1 more.
element_getStylesC
获取元素的样式值。names 为样式名数组(如 ['color', 'fontSize', 'backgroundColor'])。
Inputs: selector (required), names (required), connection, innerSelector.
element_getWxmlC
获取元素 WXML。默认获取内部 WXML(element.wxml()),设置 outer 为 true 可获取包含元素本身的 WXML(element.outerWxml())。
Inputs: selector (required), connection, innerSelector, outer.
element_inputC
向指定元素输入文本。
Inputs: selector (required), value (required), connection, innerSelector.
element_scrollToA
滚动 scroll-view 组件到指定位置。仅适用于 scroll-view 组件。
Inputs: selector (required), x (required), y (required), connection, +1 more.
element_setDataB
设置组件实例渲染数据,仅自定义组件可以使用。
Inputs: selector (required), data (required), connection, innerSelector.
element_tapA
通过 CSS 选择器模拟点击 WXML 元素。支持 [index=N] 语法选择第 N 个元素。如需点击自定义组件内部的元素,请使用 innerSelector 参数:selector 设为组件 ID 选择器(如 #my-component)或标签选择器,innerSelector 设为组件内部元素的选择器。
Inputs: selector (required), connection, innerSelector, waitMs.
mp_callWxC
调用微信小程序 API 方法,(如 wx.pageScrollTo)。
Inputs: method (required), connection, args.
mp_currentPageA
获取当前页面的信息,包括路径、查询参数、尺寸和滚动位置。通常在 mp_ensureConnection 成功后立即调用,用于确认当前页面。withData 为 true 时额外返回页面数据。
Inputs: connection, withData.
mp_ensureConnectionA
检查小程序自动化会话是否就绪。先调用这个工具,再调用 mp_screenshot、page_* 或 element_* 工具。若失败,优先用 reconnect=true 重试一次;若返回项目选择提示,则传 projectSelection。
Inputs: connection, reconnect, projectSelection.
mp_getLogsC
获取小程序控制台日志。可选择在获取后清空日志。
Inputs: connection, clear.
mp_listProjectsB
列出微信开发者工具中的最近项目,方便在 mp_ensureConnection 返回项目选择提示后继续选择项目。
Inputs: no named parameters.
mp_screenshotA
截取当前小程序视口的截图。需要已有活动会话;若提示没有活动会话,请先调用 mp_ensureConnection。默认返回内联图片,或保存到文件路径。
Inputs: connection, path.
mp_setDefaultProjectA
设置默认的小程序项目路径,设置后下次连接会优先使用该项目。通常用于修复项目选择失败后的后续重试。
Inputs: projectPath (required).
page_callMethodC
调用当前页面实例上暴露的方法。参数可以作为数组提供。
Inputs: method (required), connection, args.
page_getDataC
获取当前页面的数据对象,可选择指定子数据路径。
Inputs: connection, path.
page_getElementB
通过选择器获取页面元素,相当于 page.$(selector)。返回每个元素的摘要信息(tagName、text、value、size、offset);设置 withWxml 为 true 可额外返回元素的完整 outerWxml。支持 [index=N] 语法选择第 N 个元素。
Inputs: selector (required), connection, innerSelector, withWxml.
page_getElementsA
通过选择器获取页面元素数组,相当于 page.$$(selector)。返回每个元素的摘要信息(tagName、text、value、size、offset);设置 withWxml 为 true 可额外返回每个元素的完整 outerWxml。支持 [index=N] 语法选择第 N 个元素。
Inputs: selector (required), connection, withWxml.
page_setDataC
使用 setData 更新当前页面的数据。
Inputs: data (required), connection.
page_waitElementC
等待指定选择器的元素出现在页面上。支持 [index=N] 语法选择第 N 个元素。增强版:增加了超时和重试间隔参数。
Inputs: selector (required), connection, timeout, retryInterval.
page_waitTimeoutC
等待指定的毫秒数。
Inputs: milliseconds (required), connection.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 27 tools
Each tool targets a distinct action within its category (element, mp, page). Within each group, operations like getAttributes, getBoundingClientRect, getData are clearly different. No two tools overlap in purpose.
All tools follow a consistent pattern: category_verbNoun (e.g., element_tap, mp_navigate, page_setData). Underscore separation and camelCase for the verb+noun are uniform across all 27 tools.
With 27 tools, the count is on the higher side but well-justified by the broad scope (element manipulation, page control, and mini-program API calls). It's reasonably scoped for a comprehensive development assistant.
The tool set covers core operations: element querying/interaction, page data management, and mini-program API invocation. Minor gaps like gesture simulation or file operations exist, but the essential CRUD and lifecycle actions are present.
Maintenance
Related MCP Connectors
Live browser debugging for AI assistants — DOM, console, network via MCP.
Control a real browser from AI agents: navigate, click, type, screenshot, read the page.
AI-powered web automation. Navigate websites using AI agents for one page or a thousand
AI-powered web automation. Navigate websites using AI agents for one page or a thousand
Related MCP Servers
- AlicenseBqualityCmaintenanceEnables automated testing of WeChat mini-programs via Model Context Protocol, providing tools for connecting to WeChat Developer Tools, querying and interacting with page elements, making assertions, navigating, and debugging.2032 npm78MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to automate WeChat mini-programs via launch or connect modes, providing a stable interaction tree for observation and operation.17 npmMIT
- AlicenseBqualityCmaintenanceEnables AI assistants to control WeChat mini-programs running in WeChat Developer Tools through MCP tools. Provides automation capabilities for launching, navigating, querying, and interacting with pages and elements.6126 npm1MIT
- -licenseNot gradedqualityNot gradedmaintenanceEnables AI agents to debug and control WeChat Mini Programs through WeChat DevTools, including direct automator operations and CLI-backed features like screenshots, logs, previews, and uploads.-