npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

weixin-devtools-mcp

v0.1.0

Published

WeChat Mini Program automation MCP server with intelligent connection, page interaction, assertion validation and network monitoring

Downloads

86

Readme

微信开发者工具自动化 MCP 服务器

强大的微信小程序自动化测试解决方案,基于 Model Context Protocol 实现

Version License TypeScript

✨ 核心特性

  • 🚀 27个专业工具(full profile) - 覆盖连接、查询、交互、断言、导航、调试等完整测试场景
  • 🤖 智能连接 - 支持 auto/launch/connect 三种模式,自动端口检测,无需手动配置
  • 🔍 自动网络监控 - 连接时自动启动,实时拦截 wx.request/uploadFile/downloadFile
  • 完整断言体系 - 5类断言工具,验证元素存在、可见性、文本、属性、状态
  • 📸 丰富调试能力 - 支持页面截图、Console 监听、网络请求追踪、诊断工具
  • 🏗️ 模块化架构 - 基于 chrome-devtools-mcp 架构模式,易于扩展和维护
  • 🧩 可配置工具暴露 - 默认 core profile(17个工具),支持按类别开启 Console/Network/Debug
  • 🧪 全面测试覆盖 - 单元测试 + 集成测试,测试覆盖率 >80%

📦 安装

方式一:使用 npx(推荐)

无需安装,直接使用,npx 会自动下载并运行最新版本:

# 无需执行任何安装命令
# 直接在 Claude Desktop 配置中使用即可

方式二:全局安装

如果需要频繁使用或离线使用,可以全局安装:

npm install -g weixin-devtools-mcp

方式三:开发者安装(从源码)

如果需要修改源代码或参与开发:

# 克隆项目
git clone https://github.com/yourusername/weixin-devtools-mcp.git
cd weixin-devtools-mcp

# 安装依赖
npm install

# 构建项目
npm run build

⚙️ 配置

在 Claude Desktop 配置文件中添加 MCP 服务器:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%/Claude/claude_desktop_config.json

配置方式一:使用 npx(推荐)

优点:无需安装,自动使用最新版本

{
  "mcpServers": {
    "weixin-devtools-mcp": {
      "command": "npx",
      "args": ["-y", "weixin-devtools-mcp"]
    }
  }
}

配置方式二:全局安装后使用

如果已全局安装,可以直接使用命令名:

{
  "mcpServers": {
    "weixin-devtools-mcp": {
      "command": "weixin-devtools-mcp"
    }
  }
}

配置方式三:开发者本地路径

如果从源码安装,使用绝对路径:

{
  "mcpServers": {
    "weixin-devtools-mcp": {
      "command": "/path/to/weixin-devtools-mcp/build/server.js"
    }
  }
}

工具 Profile 配置(v0.4+)

服务器支持按 profile 控制暴露工具,降低默认工具数量:

  • core(默认):17 个核心自动化工具
  • full:27 个完整工具
  • minimal:9 个最小工具

也支持按类别增减:

  • --enable-categories=console,network,debug
  • --disable-categories=console,network,debug,core

npx 配置示例(启用 full):

{
  "mcpServers": {
    "weixin-devtools-mcp": {
      "command": "npx",
      "args": ["-y", "weixin-devtools-mcp", "--tools-profile=full"]
    }
  }
}

本地二进制示例(在 core 基础上启用 network + debug):

{
  "mcpServers": {
    "weixin-devtools-mcp": {
      "command": "/path/to/weixin-devtools-mcp/build/server.js",
      "args": ["--enable-categories=network,debug"]
    }
  }
}

🚀 快速开始

第一个自动化测试

// 1. 连接微信开发者工具(auto 策略)
connect_devtools({
  projectPath: "/path/to/your/miniprogram",
  strategy: "auto",
  verbose: true
})

// 2. 查找登录按钮
$({ selector: "button.login-btn" })

// 3. 点击登录按钮
click({ uid: "button.login-btn" })

// 4. 等待登录成功
waitFor({ selector: ".welcome-message", timeout: 5000 })

// 5. 验证登录成功
assert_text({ uid: ".welcome-message", text: "欢迎回来" })

// 6. 获取页面截图(需在服务启动参数中启用 --enable-categories=debug)
screenshot({ path: "/tmp/login-success.png" })

🛠️ 功能概览

当前工具暴露采用 profile 机制:

  • core(默认,20个):
    • 连接/页面:connect_devtoolsreconnect_devtoolsdisconnect_devtoolsget_connection_statusget_current_pageget_page_snapshot$waitFor
    • 交互:clickinput_textget_valueset_form_control
    • 断言:assert_textassert_attributeassert_state
    • 导航:navigate_tonavigate_backswitch_tabrelaunch
    • 脚本:evaluate_script
  • 可选类别(默认关闭):
    • consolelist_console_messagesget_console_message
    • networkget_network_requestsstop_network_monitoringclear_network_requests
    • debugscreenshotdiagnose_connectioncheck_environmentdebug_page_elementsdebug_connection_flow
  • full profile:暴露全部 30 个工具。

💡 使用示例

示例 1:用户登录流程

// 连接到开发者工具
connect_devtools({
  projectPath: "/path/to/miniprogram",
  strategy: "auto"
})

// 输入用户名
$({ selector: "input#username" })
input_text({ uid: "input#username", text: "testuser" })

// 输入密码
$({ selector: "input#password" })
input_text({ uid: "input#password", text: "password123" })

// 点击登录按钮
$({ selector: "button.login" })
click({ uid: "button.login" })

// 等待登录成功
waitFor({ selector: ".welcome", timeout: 5000 })

// 验证欢迎消息
assert_text({ uid: ".welcome", textContains: "欢迎" })

// 检查网络请求(需在服务启动参数中启用 --enable-categories=network)
get_network_requests({ urlPattern: "/api/login", successOnly: true })

示例 2:表单填写和提交

// 填写文本输入框
input_text({ uid: "input#name", text: "张三" })
input_text({ uid: "input#email", text: "[email protected]" })

// 选择下拉框
set_form_control({ uid: "picker#city", value: "北京" })

// 切换开关
set_form_control({ uid: "switch#agree", value: true })

// 设置滑块
set_form_control({ uid: "slider#age", value: 25 })

// 提交表单
click({ uid: "button.submit" })

// 等待提交成功
waitFor({ selector: ".success-toast", timeout: 3000 })

// 验证提交结果
assert_visible({ uid: ".success-toast", visible: true })
assert_text({ uid: ".success-toast", text: "提交成功" })

// 截图保存结果
screenshot({ path: "/tmp/form-submit-success.png" })

📚 文档

🔧 开发指南

构建和测试

项目采用分层测试架构,分为协议测试、工具测试和集成测试:

# 开发模式(监听文件变化)
npm run watch

# 运行单元测试(224个测试:协议 + 工具 + 工具类)
npm test

# 分类运行单元测试
npm run test:protocol      # 协议层测试(19个)
npm run test:tools         # 工具逻辑测试(196个)

# 运行集成测试(需要微信开发者工具,46个测试)
npm run test:integration

# 推荐:复用现有 DevTools 会话,避免反复重启项目(默认)
INTEGRATION_CLEANUP_MODE=reuse npm run test:integration

# 如需强制隔离环境(CI 或排查端口脏状态)
INTEGRATION_CLEANUP_MODE=force npm run test:integration

# 禁用跨 suite 会话复用(仅调试时建议)
INTEGRATION_REUSE_SESSION=false npm run test:integration

# 如需每个 suite 结束后强制断开(默认不强制)
INTEGRATION_FORCE_DISCONNECT_AFTER_EACH_SUITE=true npm run test:integration

# 运行所有测试(单元 + 集成)
npm run test:all

# 生成测试覆盖率报告
npm run test:coverage

# 使用 MCP Inspector 调试
npm run inspector

添加新工具

  1. src/tools/ 下创建或修改工具模块
  2. 使用 ToolDefinition 框架定义工具
  3. src/tools/index.ts 中导出工具
  4. 编写单元测试(tests/tools/*.test.tstests/protocol/*.test.ts
  5. 编写集成测试(tests/integration/*.integration.test.ts
  6. 更新文档

详细开发指南请参考 CLAUDE.md

测试架构

项目采用三层测试架构(参考 chrome-devtools-mcp):

  • 协议层测试 (tests/protocol/) - 测试 MCP 服务器协议实现
  • 工具逻辑测试 (tests/tools/) - 直接测试工具 handler,无需服务器
  • 集成测试 (tests/integration/) - 端到端测试,需要真实环境

集成测试支持以下运行模式:

  • INTEGRATION_CLEANUP_MODE=reuse:复用已有 DevTools 实例(默认)
  • INTEGRATION_CLEANUP_MODE=smart:优雅关闭后重连
  • INTEGRATION_CLEANUP_MODE=force:强制清理全部实例
  • INTEGRATION_REUSE_SESSION=true/false:控制跨 suite 连接复用
  • INTEGRATION_FORCE_DISCONNECT_AFTER_EACH_SUITE=true/false:控制每个 suite 结束后是否强制断连(默认 false

📋 系统要求

  • Node.js >= 16.0.0
  • 微信开发者工具 已安装并开启自动化功能
  • 操作系统 macOS / Windows
  • Claude Desktop 用于运行 MCP 服务器

🤝 贡献指南

欢迎贡献代码、报告问题或提出建议!

  1. Fork 本项目
  2. 创建特性分支 (git checkout -b feature/AmazingFeature)
  3. 提交更改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 开启 Pull Request

📄 许可证

本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情

🙏 致谢

📞 联系方式


⭐ 如果这个项目对你有帮助,欢迎给个 Star!