Node.js调试器MCP
一个MCP服务器,使用Chrome DevTools协议提供全面的Node.js调试功能。该服务器使AI助手能够调试Node.js应用程序,并完全访问断点、步进、变量检查、调用堆栈、表达式求值和源映射。
为什么使用此MCP服务器?
当您需要AI协助调试Node.js应用程序时,此MCP服务器非常有用。它提供了对Chrome DevTools或VS Code中所有调试功能的编程访问,允许AI助手帮助您设置断点、检查变量、遍历代码和分析运行时行为。
特性
- 完整的Node.js调试器:设置断点、条件断点、日志点和异常暂停
- 步进控制:跨过/进入/退出,继续定位,重新启动帧
- 计量检验:探索当地/封闭范围,
this预览并深入查看对象属性 - 表达式计算:使用控制台输出捕获来评估当前调用帧中的JavaScript表达式
- 调用堆栈分析:检查呼叫堆栈和暂停状态信息
- 源地图支持:调试TypeScript和其他具有完整源代码映射支持的编译代码
- 控制台监控:在调试会话期间捕获和查看控制台输出
安装
npm install devtools-debugger-mcp配置
将服务器添加到MCP设置配置中:
{
"devtools-debugger-mcp": {
"command": "node",
"args": ["path/to/devtools-debugger-mcp/dist/index.js"]
}
}或者,如果全局安装,您可以使用CLI二进制文件:
{
"devtools-debugger-mcp": {
"command": "devtools-debugger-mcp"
}
}Node.js调试
此MCP服务器可以通过使用内置检查器启动脚本来调试Node.js程序(--inspect-brk=0)以及Chrome DevTools协议(CDP)。
运作原理
start_node_debug生成node --inspect-brk=0 your-script.js,等待WebSocket检查器,附加,并返回初始暂停(第一行)pauseId以及顶部呼叫帧。- 然后,您可以设置断点(通过文件路径或URL正则表达式),选择异常暂停,并继续/单步执行。每次暂停时,工具都可以检查作用域、计算表达式,并读取自上一步/恢复以来捕获的控制台输出。
- 当进程退出时,服务器会清理CDP会话并重置其状态。
快速启动(来自启用MCP的客户端)
- 启动调试会话
{ "tool": "start_node_debug", "params": { "scriptPath": "/absolute/path/to/app.js" } }- 设置断点(文件路径+1行)
{ "tool": "set_breakpoint", "params": { "filePath": "/absolute/path/to/app.js", "line": 42 } }- 运行到下一个暂停(可选包括控制台/堆栈)
{ "tool": "resume_execution", "params": { "includeConsole": true, "includeStack": true } }- 暂停检查
{ "tool": "inspect_scopes", "params": { "maxProps": 15 } }
{ "tool": "evaluate_expression", "params": { "expr": "user.name" } }- 步骤
{ "tool": "step_over" }
{ "tool": "step_into" }
{ "tool": "step_out" }- 完成
{ "tool": "stop_debug_session" }Node.js工具参考(摘要)
start_node_debug({ scriptPath, format? })--使用检查器启动Node并返回初始暂停。set_breakpoint({ filePath, line })--按文件路径的断点(从1开始的行)。set_breakpoint_condition({ filePath?, urlRegex?, line, column?, condition, format? })--条件断点或通过URL正则表达式。add_logpoint({ filePath?, urlRegex?, line, column?, message, format? })--通过条件断点记录并返回日志点false.set_exception_breakpoints({ state })—none | uncaught | all.blackbox_scripts({ patterns })--忽略匹配脚本URL中的帧。list_scripts()/get_script_source({ scriptId? | url? })--发现并获取脚本源。continue_to_location({ filePath, line, column? })--运行到特定的源位置。restart_frame({ frameIndex, pauseId?, format? })--重新运行所选帧。resume_execution({ includeScopes?, includeStack?, includeConsole?, format? })--继续下一次暂停或退出。step_over|step_into|step_out({ includeScopes?, includeStack?, includeConsole?, format? })--在结果中使用可选上下文。evaluate_expression({ expr, pauseId?, frameIndex?, returnByValue?, format? })--在暂停的帧中进行评估;默认为顶部框架。inspect_scopes({ maxProps?, pauseId?, frameIndex?, includeThisPreview?, format? })--局部/封闭和this总结。get_object_properties({ objectId, maxProps?, format? })--深入了解对象预览。list_call_stack({ depth?, pauseId?, includeThis?, format? })--前N帧摘要。get_pause_info({ pauseId?, format? })--暂停原因/位置摘要。read_console({ format? })--自上一步/恢复以来的控制台消息。stop_debug_session()--终止进程并分离。
备注
- 文件路径转换为
file://内部URL用于CDP兼容性。 line是1-基的;CDP内部以0为基础。- 服务器在暂停之间缓冲控制台输出;通过以下方式获取
includeConsole在步骤/恢复或与read_console. - 使用
set_output_format({ format: 'text' | 'json' | 'both' })设置默认响应格式。
可用工具
此MCP服务器提供以下Node.js调试工具。所有工具支持可选 format 参数('text' 或 'json')以控制响应格式。
会话管理
start_node_debug-启动启用调试的Node.js脚本stop_debug_session-终止调试会话并清理
断点管理
set_breakpoint-在特定文件和行设置断点set_breakpoint_condition-通过URL正则表达式设置条件断点或断点add_logpoint-添加一个日志点,在点击时记录消息set_exception_breakpoints-配置异常行为暂停
执行控制
resume_execution-继续执行到下一个断点或完成step_over-跨过当前线路step_into-进入函数调用step_out-退出当前功能continue_to_location-跑步直到到达特定位置restart_frame-从特定调用帧重新启动执行
检查和分析
inspect_scopes-检查局部变量、闭包和this上下文evaluate_expression-在当前上下文中计算JavaScript表达式get_object_properties-深入了解对象属性list_call_stack-查看当前调用堆栈get_pause_info-获取有关当前暂停状态的信息
公用事业
list_scripts-列出所有加载的脚本get_script_source-检索脚本的源代码blackbox_scripts-配置调试期间跳过的脚本read_console-读取调试期间捕获的控制台输出
有关详细的使用示例和参数说明,请参阅上面的“Node.js调试”部分。
许可证
麻省理工学院
