脚本调试工具

MCP调试单元是一个允许编码代理在不修改源代码的情况下调试Node.js和Python脚本的服务,特别适用于单元测试和运行时值检查。

  • by gwythyr
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 gwythyr/nodejs-debug-mcp

使用说明

mcp调试单元

MCP服务器,使编码代理能够调试Node.js 和 Python脚本,无需修改源代码。

发布于npm mcp-debug-unit (以前 nodejs-debug-mcp).旧版CLI别名仍可用于向后兼容性。

为什么要安装这个

您的编码代理(Claude、Cursor等)可以在不修改代码的情况下检查运行时值。而不是要求代理添加 console.log 语句,它可以调用 debug-script 查看执行过程中任何一行发生了什么。

对于调试单元测试和通过了解运行时实际存在的值来帮助代理编写测试特别有用。

运作原理

代理人指定:

  • 要运行的Node.js命令
  • 断点位置(文件和行)
  • 要计算的表达式

该工具运行脚本,每次执行时暂停在该行,计算表达式,并在脚本完成时返回所有值。

参数

  • 命令: 要运行的可调试命令。对于Node.js pass --inspect-brk,对于Python运行 debugpy 随着 --listen + --wait-for-client.
  • 断点: { file: string, line: number }
  • 表达式: 表达式用于计算何时命中断点。适用于两种运行时。
  • 超时: 最大执行时间(毫秒)
  • 包括堆叠: (可选)在结果中包含调用堆栈帧
  • 运行时: (可选) 'node' (默认)或 'python'

设置

克劳德代码

claude mcp add --scope user --transport stdio mcp-debug-unit -- npx -y mcp-debug-unit

Codex CLI

codex mcp add mcp-debug-unit -- npx -y mcp-debug-unit

光标

添加到MCP设置配置文件中:

{
  "mcpServers": {
    "mcp-debug-unit": {
      "command": "npx",
      "args": ["-y", "mcp-debug-unit"]
    }
  }
}

发展

npx tsc                        # Build
node --test test/e2e.test.js  # Test

Python运行时要求

  • 安装 debugpy (例如。 python3 -m pip install debugpy)
  • MCP服务器引导程序 debugpy 自动进入您的用户缓存(例如。 ~/.cache/mcp-debug-unit/debugpy/<hash> 或 %LOCALAPPDATA%\mcp-debug-unit\cache\debugpy\<hash>)如果命令中引用的解释器无法导入它。请通过以下方式覆盖存储位置 MCP_DEBUG_UNIT_DEBUGPY_DIR (或遗产 NODEJS_DEBUG_MCP_DEBUGPY_DIR).
  • 通过以下方式启动脚本 python3 -m debugpy --listen 127.0.0.1:5678 --wait-for-client ./script.py
  • 呼叫 debug-script 随着 runtime: "python" 同样的 listen 主机:端口 command
  • 使用绝对或相对路径 breakpoint.file (它们将自动解决)

看 SPECIFICATION.md 了解实施细节。

发布

要将新版本发布到npm:

# Patch version (0.1.2 → 0.1.3)
npm version patch && git push --follow-tags

# Minor version (0.1.2 → 0.2.0)
npm version minor && git push --follow-tags

# Major version (0.1.2 → 1.0.0)
npm version major && git push --follow-tags

这会自动:

  • 更新package.json版本
  • 创建git commit和标签
  • 推送到GitHub
  • 触发发布工作流

许可证

麻省理工学院