微信开发者工具MCP服务器
这是一个模型上下文协议(MCP)服务器,通过以下方式连接到微信开发者工具 miniprogram-automator它允许您从MCP客户端(如Claude Desktop或AI代理)控制IDE和小程序。
先决条件
- Node.js:建议使用18+版本(尽管它可能适用于带有一些polyfill的旧版本,但此项目是为现代Node设置的)。
- 微信开发者工具:必须安装并运行。
- 启用自动化:在微信开发者工具中,转到 设置->安全设置 并启用 服务端口 (CLI/HTTP调用)。
快速开始
与Claude Desktop一起使用(推荐)
将以下内容添加到您的 claude_desktop_config.json (例如。, ~/Library/Application Support/Claude/claude_desktop_config.json 在macOS上):
{
"mcpServers": {
"wechat-devtools": {
"command": "npx",
"args": [
"-y",
"wechat-dev-mcp"
]
}
}
}手动安装
要全局安装,请执行以下操作:
npm install -g wechat-dev-mcp然后配置:
{
"mcpServers": {
"wechat-devtools": {
"command": "wechat-dev-mcp",
"args": []
}
}
}本地开发
- 克隆仓库
- 安装依赖项:
npm install- 在本地构建和运行:
node index.js- 配置Claude Desktop以指向您的本地文件:
{
"mcpServers": {
"wechat-devtools": {
"command": "node",
"args": ["/absolute/path/to/wechat-dev-mcp/index.js"]
}
}
}可用工具
launch:启动并连接到一个小程序项目。
- projectPath:项目的绝对路径。 - cliPath:(可选)DevTools CLI的路径。
connect:连接到已运行的DevTools实例。
- wsEndpoint:WebSocket端点(例如。, ws://localhost:9420).
navigate_to:导航到页面(例如。,/pages/index/index).get_page_data:从当前页面获取数据。set_page_data:在当前页面上设置数据。get_element:获取元素的文本、属性或样式。tap_element:点击(单击)元素。input_text:在元素中输入文本。trigger_event:在元素上触发自定义事件。call_method:调用当前页面实例上的方法。evaluate:在AppService上下文中执行任意JavaScript。call_cloud_function:调用微信云功能(wx.cloud.callFunction).build_npm:构建NPM依赖关系(CLIbuild-npm).cloud_functions_deploy:部署云功能(CLIcloud functions deploy).cloud_functions_list:列出云功能(CLIcloud functions list).disconnect:断开自动化。
AI代理的最佳实践
为了确保在将此服务器与AI代理(如Cursor或Windsurf)一起使用时获得最佳体验,我们建议在您的项目中添加以下规则 .cursorrules 或系统提示:
ALWAYS run the `wechat-devtools_check_health` tool after making ANY changes to the codebase (editing files, creating files, etc.).
1. If `check_health` shows console errors, YOU MUST fix them immediately.
2. If `check_health` shows the page path is not what you expect, navigate to the correct page.
3. If `check_health` fails (not connected), you MUST run `wechat-devtools_launch` or `connect`.故障排除
- 连接被拒绝:确保微信开发者工具正在运行,并且在设置中启用了服务端口。
- 路径问题:使用绝对路径
projectPath.
