微信小程序自动化服务

一个基于MCP的微信小程序自动化服务,封装miniprogram-automator,支持通过stdio被Cursor/Codex等MCP客户端调用。

  • by ShohanPeng
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 ShohanPeng/wechat-miniprogram-mcp

使用说明

wechat-miniprogram-mcp

一个基于 MCP 的微信小程序自动化服务,封装 miniprogram-automator,支持通过 stdio 被 Cursor/Codex 等 MCP 客户端调用。

特性

  • TypeScript + Node.js 实现,支持 launch / connect / auto 三种连接模式
  • 会话复用、会话列表、定向关闭、空闲会话自动回收
  • 提供 mp_*、page_*、element_* 工具面
  • 已支持录制与基础重放能力(record_start / record_stop / record_listOperations / replay_run)

安装与运行

npm install
npm run check
npm run test
npm run build

开发模式启动:

npm run dev

已实现工具

  • mp_ensureConnection
  • mp_listSessions
  • mp_closeSession
  • mp_navigate
  • mp_currentPage
  • mp_getLogs
  • mp_screenshot
  • mp_callWx
  • page_callMethod
  • page_getData
  • page_setData
  • page_getElement
  • page_getElements
  • page_waitElement
  • page_waitTimeout
  • element_callMethod
  • element_getAttributes
  • element_getBoundingClientRect
  • element_getData
  • element_getInnerElement
  • element_getInnerElements
  • element_getStyles
  • element_getWxml
  • element_input
  • element_scrollTo
  • element_setData
  • element_tap
  • record_start
  • record_stop
  • record_listOperations
  • record_export
  • record_import
  • replay_run

录制与重放(v2)

  • record_start:开始录制,默认会先清空历史事件
  • record_stop:结束录制并返回录制到的事件
  • record_listOperations:查看当前内存中的事件列表
  • record_export:导出标准 JSON 结构(可保存到文件)
  • record_import:导入事件(replace 覆盖或 append 追加)
  • replay_run:执行重放(当前 v2 可稳定重放 mp_navigate / page_setData / page_waitTimeout / mp_callWx / page_callMethod / page_getElement / page_waitElement / element_tap / element_input / element_setData / element_scrollTo / element_callMethod)

注意:replay_run v2 会优先基于录制时 selector 重新定位 element;若页面结构变化导致 selector 失效,步骤会报错并在结果中返回原因。

连接参数(connection)

所有支持连接的工具均可接受 connection:

  • mode: auto | connect | launch
  • sessionId
  • wsEndpoint
  • port
  • projectPath
  • cliPath
  • cwd
  • args
  • timeout
  • autoClose
  • trustProject

auto 模式优先复用 sessionId,否则尝试 wsEndpoint/port,最后尝试 projectPath。

会话回收

默认 15 分钟空闲回收,可通过环境变量设置:

WEAPP_MCP_SESSION_IDLE_TIMEOUT_MS=900000

设置为 0 表示禁用自动回收。

客户端配置

见 docs/clients.md。

参考仓库