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_ensureConnectionmp_listSessionsmp_closeSessionmp_navigatemp_currentPagemp_getLogsmp_screenshotmp_callWxpage_callMethodpage_getDatapage_setDatapage_getElementpage_getElementspage_waitElementpage_waitTimeoutelement_callMethodelement_getAttributeselement_getBoundingClientRectelement_getDataelement_getInnerElementelement_getInnerElementselement_getStyleselement_getWxmlelement_inputelement_scrollToelement_setDataelement_taprecord_startrecord_stoprecord_listOperationsrecord_exportrecord_importreplay_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 | launchsessionIdwsEndpointportprojectPathcliPathcwdargstimeoutautoClosetrustProject
auto 模式优先复用 sessionId,否则尝试 wsEndpoint/port,最后尝试 projectPath。
会话回收
默认 15 分钟空闲回收,可通过环境变量设置:
WEAPP_MCP_SESSION_IDLE_TIMEOUT_MS=900000设置为 0 表示禁用自动回收。
客户端配置
见 docs/clients.md。
