🚀 Node.js Debugger MCP
Node.js Debugger MCP是一個MCP服務器,它藉助Chrome DevTools協議,為Node.js應用程序提供全面的調試功能。該服務器使AI助手能夠對Node.js應用程序進行調試,可全面使用斷點設置、單步執行、變量檢查、調用棧分析、表達式求值以及源映射等功能。
🚀 快速開始
此MCP服務器在需要AI協助調試Node.js應用程序時十分有用。它以編程方式提供了在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服務器可以通過使用內置檢查器(--inspect-brk=0
)啟動腳本並使用Chrome DevTools協議(CDP)來調試Node.js程序。
工作原理
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調試”部分。
📄 許可證
MIT