Skip to main content
Glama
WeChat Mini Program Dev MCP

WeChat Mini Program Dev MCP

by yfmeii

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 npm installed 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-mcp

Install globally or in a project

npm install -g @yfme/weapp-dev-mcp
weapp-dev-mcp

Or as a project dependency:

npm install --save-dev @yfme/weapp-dev-mcp
npx weapp-dev-mcp

Only when developing within this repository is it recommended to run node dist/index.js directly. 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:

  1. Open WeChat Developer Tools.

  2. Go to Settings → Security Settings → Service Port.

  3. 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 9420

Windows:

"C:\Program Files (x86)\Tencent\微信web开发者工具\cli.bat" auto --project C:\path\to\your\project --auto-port 9420

Where:

  • --project specifies the path to the mini program project directory (please replace with the actual project path).

  • --auto-port specifies 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

WEAPP_WS_ENDPOINT

[Recommended] The WebSocket endpoint of the running Developer Tools. When set, the server uses connect mode instead of launching a new instance. Example: ws://localhost:9420

WECHAT_DEVTOOLS_CLI_PATH

Path to the WeChat Developer Tools CLI (optional if the default path works).

WEAPP_AUTOMATOR_MODE

Force launch or connect mode. Defaults to launch unless WEAPP_WS_ENDPOINT is provided.

WEAPP_DEVTOOLS_PORT

Preferred port when launching Developer Tools (falls back to an available port).

WEAPP_DEVTOOLS_TIMEOUT

Launch timeout in milliseconds (default 30000).

WEAPP_AUTO_ACCOUNT

Passed to --auto-account for automatic login.

WEAPP_DEVTOOLS_TICKET

Passed to --ticket at launch.

WEAPP_TRUST_PROJECT

Set to true to include --trust-project at launch.

WEAPP_DEVTOOLS_ARGS

Additional CLI arguments at launch (space-separated).

WEAPP_DEVTOOLS_CWD

Working directory passed to the Developer Tools process.

WEAPP_AUTOCLOSE

Set to true to close the Developer Tools session after each tool call.

WEAPP_AUTOLAUNCH

Set to true to automatically detect and launch Developer Tools.

WEAPP_LAUNCH_TIMEOUT

Launch timeout in milliseconds (default 45000).

WEAPP_CONNECT_TIMEOUT

Connection timeout in milliseconds (default 45000).

WEAPP_PROJECT_PATH

Mini program project path (optional).

Note: When launching Developer Tools (launch mode), you must provide the mini program project directory via MCP tool parameters: provide it via connection.projectPath before performing operations (e.g., via mp_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; supports navigateTo, redirectTo, reLaunch, switchTab, or navigateBack.

  • 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 if withData is 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); set withWxml: true to 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; set withWxml: true to 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 using setData; 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 to input and textarea components).

  • 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 to element.$(selector)), returns element summary; set withWxml: true to additionally return the full outerWxml.

  • element_getInnerElements – Get an array of elements inside an element (equivalent to element.$$(selector)), returns element summary; set withWxml: true to additionally return the full outerWxml for each.

  • element_getWxml – Get element WXML (inner or outer).

  • element_getStyles – Get CSS style values of an element, names parameter is an array of style names (e.g., ['color', 'fontSize']).

  • element_scrollTo – Scroll a scroll-view component to a specified position (x, y).

  • element_getAttributes – Get attribute values of an element, names parameter 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_ensureConnection first to verify the connection and view system/page details.

  • Using WEAPP_AUTOCLOSE=true is suitable for stateless, one-off interactions.

  • Always use absolute paths when navigating (starting with /): /pages/mine/mine.

  • Use switchTab for tabBar pages, and navigateTo for 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_waitElement does not apply to elements inside custom components. Please use page_waitTimeout in 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:

  1. Auto-detect port: Detects if a service is running on port 9420.

  2. Launch if no service: If the port is not occupied, it automatically calls the CLI to launch the Developer Tools.

  3. 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

  1. Upon first connection, WEAPP_AUTOLAUNCH=true is detected.

  2. Checks if a service is running on port 9420.

  3. If no service, automatically launches Developer Tools (using cli.bat auto --project <path> --auto-port 9420).

  4. Waits 45 seconds for the Developer Tools to be ready.

  5. Establishes a WebSocket connection.

  6. 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 tools
element_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_navigateC

在小程序内导航,支持 navigateTo、redirectTo、reLaunch、switchTab 和 navigateBack。

Inputs: connection, path, query, transition, +1 more.

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

    B3/5.0

    Scored across 27 tools

    Disambiguation5/5

    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.

    Naming Consistency5/5

    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.

    Tool Count4/5

    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.

    Completeness4/5

    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

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      C
      maintenance
      Enables 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.
      20
      32 npm
      78
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to automate WeChat mini-programs via launch or connect modes, providing a stable interaction tree for observation and operation.
      17 npm
      MIT
    • A
      license
      B
      quality
      C
      maintenance
      Enables 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.
      61
      26 npm
      1
      MIT
    • -
      license
      Not graded
      quality
      Not graded
      maintenance
      Enables 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.
      -