Node.js调试器

MCP Node.js调试器是一个运行时调试工具,允许通过Cursor或Claude Code访问Node.js运行时的调试功能,帮助开发者实时调试Node.js应用程序。

作者 By workbackai
本地部署 可托管 Node.js调试
GitHub

MCP Node.js调试器

一个MCP服务器,允许Cursor或Claude Code在运行时访问Node.js,以帮助您调试: @hyperdrive-eng/mcp-nodejs-debugger.

演示

光标

https://github.com/user-attachments/assets/c193a17e-b0e6-4c51-82aa-7f3f0de17e1a

克劳德代码

https://github.com/user-attachments/assets/adb7321b-3a6a-459b-a5c9-df365710d4d8

快速启动

光标

  1. 添加到光标(~/.cursor/mcp.json)

DIFF``` 1 2 3 4 5 6 7 8+ {

  • “mcpServers”: {
  • “nodejs-debugger”: {
  •  "command": "npx",
  •   "args": ["@hyperdrive-eng/mcp-nodejs-debugger"]
  • }
  • }
  • }
2. 在中运行Node.js服务器 [调试模式](https://nodejs.org/en/learn/getting-started/debugging) (即与 `--inspect` 平坦)


SH```
1node --inspect {file.js}
  1. 让Cursor在运行时调试你的Node.js服务器

克劳德代码

  1. 添加到克劳德代码

SH``` 1claude mcp add nodejs-debugger npx @hyperdrive-eng/mcp-nodejs-debugger

2. 启动克劳德代码


SH```
1
2
3
4
5
6
7
8claude
╭───────────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code research preview!            │
│                                                       │
│   /help for help                                      │
│                                                       │
│   Found 1 MCP server (use /mcp for status)            │
╰───────────────────────────────────────────────────────╯
  1. 在中运行Node.js服务器 调试模式 (即与 --inspect 平坦)

SH``` 1 2# In another terminal node —inspect {file.js}

4. 让Claude Code在运行时调试你的Node.js服务器


SH```
1
2
3> I'm getting a runtime error in Node.js 
  {YOUR_RUNTIME_ERROR}
  Please help me debug this error at runtime using the nodejs-debugger mcp.

用法

克劳德代码

  1. 添加到克劳德代码

SH``` 1claude mcp add nodejs-debugger npx mcp-nodejs-debugger

2. 验证连接


SH```
1
2
3> /mcp
  ⎿  MCP Server Status
     • nodejs-debugger: connected
  1. 从克劳德代码中删除

SH``` 1claude remove nodejs-debugger



### 光标


1. 添加到光标(`~/.cursor/mcp.json`)


DIFF```
1
2
3
4
5
6
7
8+ {
+   "mcpServers": {
+   "nodejs-debugger": {
+      "command": "npx",
+       "args": ["@hyperdrive-eng/mcp-nodejs-debugger"]
+     }
+   }
+ }
  1. 验证连接:

3. 从光标中删除(~/.cursor/mcp.json):

DIFF``` 1 2 3 4 5 6 7 8- {

  • “mcpServers”: {
  • “nodejs-debugger”: {
  •  "command": "npx",
  •   "args": ["@hyperdrive-eng/mcp-nodejs-debugger"]
  • }
  • }
  • }


## 示例


### 光标


1. 运行这个简单的Node.js应用程序: [github.com/mdn/express-localribrary-tutorial](https://github.com/mdn/express-locallibrary-tutorial):


SH```
1node --inspect ./bin/www
  1. 要求Cursor设置断点

3. 创建一本书 localhost:3000/catalog/book/create

4. 观察光标捕获运行时状态

克劳德代码

  1. 这是一个有缺陷的Node.js服务器:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28node --inspect index.js
Debugger listening on ws://127.0.0.1:9229/2862f5a2-8618-4516-8429-1248b397e9b4
#######################
## THE RUNTIME ERROR ##
#######################
MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://www.mongodb.com/docs/atlas/security-whitelist/
    at _handleConnectionErrors (/Users/arthur/Documents/thirdparties/mdn/express-locallibrary-tutorial/node_modules/mongoose/lib/connection.js:1110:11)
    at NativeConnection.openUri (/Users/arthur/Documents/thirdparties/mdn/express-locallibrary-tutorial/node_modules/mongoose/lib/connection.js:1041:11)
    at async main (/Users/arthur/Documents/thirdparties/mdn/express-locallibrary-tutorial/app.js:35:3) {
  reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    servers: Map(3) {
      'ac-8e6hgk7-shard-00-01.cojoign.mongodb.net:27017' => [ServerDescription],
      'ac-8e6hgk7-shard-00-02.cojoign.mongodb.net:27017' => [ServerDescription],
      'ac-8e6hgk7-shard-00-00.cojoign.mongodb.net:27017' => [ServerDescription]
    },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: 'atlas-5syy8t-shard-0',
    maxElectionId: null,
    maxSetVersion: null,
    commonWireVersion: 0,
    logicalSessionTimeoutMinutes: null
  },
  code: undefined
}
  1. Claude Code在运行时调试Node.js服务器:

SH``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48> I’m getting a runtime error connecting to mongoose. Please help me debug by checking the value of the mongodb configs at runtime using the nodejs-debugger mcp. ⏺ I’ll help you debug the mongoose connection issue using the Node.js debugger. Let’s first understand where the MongoDB connection is configured. ⏺ Search(pattern: ”/*.js”)… ⎿  Found 100 files ⏺ Let’s set a breakpoint at the mongoose connection point and continue: ⏺ nodejs-debugger:set_breakpoint (MCP)(file: … “/Users/arthur/Documents/thirdparties/mdn/express-locallibrary-tutorial/app.js”, line: 35)   ⎿  Breakpoint set successfully. ID: 2:34:0:file:///Users/arthur/Documents/thirdparties/mdn/express-locallibrary-tutorial/app.js ⏺ Let’s list all our breakpoints: ⏺ nodejs-debugger:list_breakpoints (MCP)   ⎿  [ { “file”: “/Users/arthur/Documents/thirdparties/mdn/express-locallibrary-tutorial/app.js”, “line”: 35, “id”: “2:34:0:file:///Users/arthur/Documents/thirdparties/mdn/express-locallibrary-tutorial/app\.js” } ] ⏺ Let’s try to execute a specific piece of code to check the connection variables: ⏺ nodejs-debugger:nodejs_inspect (MCP)(js_code: ”// Get the mongoose module and inspect connection\nconst mongoose = … require(‘mongoose’);\nconsole.log(‘Current mongoose version:’, mongoose.version);\nconsole.log(‘Current mongoose connection state:’, mongoose.connection.readyState);\n// Log connection string safely (without password)\nconst connectionString = process.env.MONGODB_URI || \n “mongodb+srv://cooluser:coolpassword@cluster0.cojoign.mongodb.net/local_library?retryWr ites=true&w=majority&appName=Cluster0”;\nconsole.log(‘Connection string (masked):’, connectionString.replace(/(?<=mongodb\+srv:\/\/\w+:)(.+?)(?=@)/, ’***’));”)   ⎿  Console output: [log] Current mongoose version: 8.9.5 [log] Current mongoose connection state: 0 [log] Connection string (masked): mongodb+srv://cooluser:coolpassword@cluster0.cojoign.mongodb.net/local_library?retryWri tes=true&w=majority&appName=Cluster0 ⏺ The runtime error you’re seeing in your application is related to MongoDB Atlas connection issues. Based on your error message, the problem is: 1. You’re using placeholder credentials (“cooluser:coolpassword”) To fix this, you have two options: 1. Use a local MongoDB instance by changing line 29-30 in app.js to: const dev_db_url = “mongodb://127.0.0.1:27017/local_library”; 2. Or correctly set up MongoDB Atlas: - Log into Atlas at https://cloud.mongodb.com - Go to Network Access and add your current IP to whitelist - Create proper database credentials - Update the connection string with real credentials Which option would you like to proceed with?