/ 目录 / 演练场 / DebugMCP
● 官方 microsoft ⚡ 即开即用

DebugMCP

作者 microsoft · microsoft/DebugMCP

微软的 DebugMCP 让 Claude 完全接管 VS Code 调试器——断点、单步执行、变量检查,覆盖 9 种语言。

DebugMCP 是微软官方出品的 VS Code 扩展,将编辑器的调试器以 MCP tool 形式暴露出来。AI 助手可以自主启动调试会话、按代码内容设置断点(不依赖容易漂移的行号)、单步执行并检查变量——支持 Python、TypeScript、Java、C#、C++、Go、Rust、PHP 和 Ruby。纯本地运行,无外部调用,监听 3001 端口。

为什么要用

核心特性

实时演示

实际使用效果

debug-mcp-microsoft.replay ▶ 就绪
0/0

安装

选择你的客户端

~/Library/Application Support/Claude/claude_desktop_config.json  · Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "debug-mcp-microsoft": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "http://localhost:3001/mcp"
      ]
    }
  }
}

打开 Claude Desktop → Settings → Developer → Edit Config。保存后重启应用。

~/.cursor/mcp.json · .cursor/mcp.json
{
  "mcpServers": {
    "debug-mcp-microsoft": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "http://localhost:3001/mcp"
      ]
    }
  }
}

Cursor 使用与 Claude Desktop 相同的 mcpServers 格式。项目级配置优先于全局。

VS Code → Cline → MCP Servers → Edit
{
  "mcpServers": {
    "debug-mcp-microsoft": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "http://localhost:3001/mcp"
      ]
    }
  }
}

点击 Cline 侧栏中的 MCP Servers 图标,然后选 "Edit Configuration"。

~/.codeium/windsurf/mcp_config.json
{
  "mcpServers": {
    "debug-mcp-microsoft": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "http://localhost:3001/mcp"
      ]
    }
  }
}

格式与 Claude Desktop 相同。重启 Windsurf 生效。

~/.continue/config.json
{
  "mcpServers": [
    {
      "name": "debug-mcp-microsoft",
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "http://localhost:3001/mcp"
      ]
    }
  ]
}

Continue 使用服务器对象数组,而非映射。

~/.config/zed/settings.json
{
  "context_servers": {
    "debug-mcp-microsoft": {
      "command": {
        "path": "npx",
        "args": [
          "-y",
          "mcp-remote",
          "http://localhost:3001/mcp"
        ]
      }
    }
  }
}

加入 context_servers。Zed 保存后热重载。

claude mcp add debug-mcp-microsoft -- npx -y mcp-remote http://localhost:3001/mcp

一行命令搞定。用 claude mcp list 验证,claude mcp remove 卸载。

使用场景

实战用法: DebugMCP

让 Claude 单步调试失败的测试,而不是靠 print 大法

👤 后端 / 应用开发者 ⏱ ~15 min beginner

何时使用: 测试失败但没有明显的调用栈——靠 print 调试要花很长时间。

前置条件
  • VS Code 中安装 DebugMCP — 扩展市场搜索 ozzafar.debugmcpextension
  • 对应语言的调试扩展(如 Python 的 .py) — VS Code 首次运行时会自动提示安装
步骤
  1. 设置断点
    Use debugmcp. Add a breakpoint on the line assert result == expected in tests/test_orders.py.✓ 已复制
    → 断点设置成功;已按代码内容匹配行
  2. 运行
    Start debugging tests/test_orders.py with the failing test.✓ 已复制
    → 会话在断点处暂停
  3. 检查变量
    Show me all local variables. What's result actually contain?✓ 已复制
    → 返回变量列表及具体值
  4. 单步 + 定位原因
    Step into the function that built result. Tell me where it diverged from expected.✓ 已复制
    → 定位到具体代码位置的根本原因

结果: 靠单步调试定位 bug,而不是靠猜——几分钟而非一小时。

注意事项
  • 按行号设置的断点在源码编辑后会漂移 — 使用代码内容匹配(DebugMCP 原生支持此特性)
搭配使用: filesystem

用条件断点锁定灵异 bug(Heisenbug)

👤 面对偶发性 bug 的开发者 ⏱ ~25 min intermediate

何时使用: bug 只在特定输入下复现——需要在该条件下才触发停止。

步骤
  1. 设置条件断点
    Add a breakpoint at the process(order) call that fires only when order.id starts with 'EXP-'.✓ 已复制
    → 条件断点已安装
  2. 驱动复现
    Run the integration suite. When we stop, evaluate the order DTO and the request headers.✓ 已复制
    → 精确捕获到触发失败的输入

结果: 灵异 bug 变成普通 bug。

注意事项
  • 条件表达式拖慢循环 — 收窄条件;保持表达式纯净(无副作用)

用调试器替代文档,理解陌生代码的执行流程

👤 接手某个服务的新成员 ⏱ ~30 min beginner

何时使用: 你接手了一个服务,但数据流完全不透明。

步骤
  1. 追踪入口
    Set a breakpoint at the HTTP handler for /orders. Run a sample request and step through every call until response is returned. Narrate as you go.✓ 已复制
    → 带 file:line 注释的逐步追踪报告

结果: 任何架构图都无法呈现的服务行为地图。

注意事项
  • 追踪路径太深 — 对已知的无聊帧用 step_over,只对有价值的帧用 step_into

组合

与其他 MCP 搭配,撬动十倍杠杆

debug-mcp-microsoft + filesystem

单步执行的同时读取源码,决定下一步操作

Step into the call. While paused, show me the surrounding function via filesystem.✓ 已复制
debug-mcp-microsoft + github

调试验证修复方案后,直接开 PR

We confirmed the bug. Open a PR with the fix and reference the debug session in the description.✓ 已复制

工具

此 MCP 暴露的能力

工具输入参数何时调用成本
start_debugging fileFullPath, workingDirectory, testName?, configurationName? 启动调试会话 free
add_breakpoint fileFullPath, lineContent 按代码内容标记暂停点 free
step_over (none) 前进一行源码 free
step_into (none) 进入被调用函数 free
get_variables_values scope: 'local'|'global'|'all' 检查当前暂停点的状态 free
evaluate_expression expression: str 无需重新运行即可验证假设 free
list_breakpoints (none) 查看当前所有断点 free

成本与限制

运行它的成本

API 配额
本地运行——无配额限制
每次调用 Token 数
每次调试操作 100-500 token
费用
免费(MIT 许可)
提示
单步调试消耗的 token 远少于反复 print-debug 循环迭代;用 token 换取更快的诊断速度

安全

权限、密钥、影响范围

最小权限: Local file read for source mapping
凭据存储: 无——不需要任何凭证
数据出站: 无——完全本地运行
切勿授予: Network exposure of port 3001

故障排查

常见错误与修复

MCP server not detected after install

重启 VS Code;确认扩展已启用且 3001 端口未被占用

验证: curl http://localhost:3001/mcp
Language not supported

先安装对应的 VS Code 语言调试扩展(如 Python 用 ms-python.python)

验证: 在 VS Code UI 中手动运行调试,确认可以正常工作
Breakpoint never hits

source map 不匹配——确认调试的是你刚编辑的那份产物

验证: 检查 launch.json 中的 `program` 路径

替代方案

DebugMCP 对比其他方案

替代方案何时用它替代权衡
Print / log statements快速一次性排查,没有挂载 IDE成本低但迭代慢;会污染代码库
Language-specific REPL只需要事后检查,不需要实时单步无法实时单步;功能不如完整调试器丰富

更多

资源

📖 阅读 GitHub 上的官方 README

🐙 查看未解决的 issue

🔍 浏览全部 400+ MCP 服务器和 Skills