返回市场
mcp-节点调试器

mcp-节点调试器

作者:workbackai287 星标更新:2025-11-13

项目介绍

MCP Node.js 调试器

一个MCP服务器,提供Cursor或Claude Code在运行时访问Node.js的能力,帮助您进行调试:@hyperdrive-eng/mcp-nodejs-debugger

示例

Cursor

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

Claude Code

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

快速开始

Cursor

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

    image

    + {
    +   "mcpServers": {
    +   "nodejs-debugger": {
    +      "command": "npx",
    +       "args": ["@hyperdrive-eng/mcp-nodejs-debugger"]
    +     }
    +   }
    + }
    
  2. 调试模式下运行Node.js服务器(即使用--inspect标志)

    node --inspect {file.js}
    
  3. 请求Cursor在运行时调试您的Node.js服务器

    image

Claude Code

  1. 添加到Claude Code

    claude mcp add nodejs-debugger npx @hyperdrive-eng/mcp-nodejs-debugger
    
  2. 启动Claude Code

    claude
    ╭───────────────────────────────────────────────────────╮
    │ ✻ 欢迎使用Claude Code研究预览!                        │
    │                                                       │
    │   /help 获取帮助                                       │
    │                                                       │
    │   发现了1个MCP服务器(使用/mcp查看状态)                │
    ╰───────────────────────────────────────────────────────╯
    
  3. 调试模式下运行Node.js服务器(即使用--inspect标志)

    # 在另一个终端中
    node --inspect {file.js}
    
  4. 请求Claude Code在运行时调试您的Node.js服务器

    > 我在Node.js中遇到了运行时错误
    
      {YOUR_RUNTIME_ERROR}
    
      请帮我使用nodejs-debugger mcp在运行时调试此错误。
    

使用方法

Claude Code

  1. 添加到Claude Code

    claude mcp add nodejs-debugger npx mcp-nodejs-debugger
    
  2. 验证连接

    > /mcp
      ⎿  MCP服务器状态
    
         • nodejs-debugger: 已连接
    
  3. 从Claude Code移除

    claude remove nodejs-debugger
    

Cursor

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

    + {
    +   "mcpServers": {
    +   "nodejs-debugger": {
    +      "command": "npx",
    +       "args": ["@hyperdrive-eng/mcp-nodejs-debugger"]
    +     }
    +   }
    + }
    
  2. 验证连接:

    image

  3. 从Cursor移除 (~/.cursor/mcp.json):

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

示例

Cursor

  1. 运行这个简单的Node.js应用:github.com/mdn/express-locallibrary-tutorial

    node --inspect ./bin/www
    
  2. 请求Cursor设置断点

    image

    image

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

    image

  4. 观察Cursor捕获运行时状态

    image

Claude Code

  1. 这是一个有bug的Node.js服务器:

    node --inspect index.js
    
    调试器正在监听ws://127.0.0.1:9229/2862f5a2-8618-4516-8429-1248b397e9b4
    
    #######################
    ## 运行时错误 ##
    #######################
    MongooseServerSelectionError: 无法连接到MongoDB Atlas集群中的任何服务器。一个常见原因是您尝试从未被列入白名单的IP地址访问数据库。确保您的当前IP地址已添加到Atlas集群的IP白名单中: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
    }
    
  2. Claude Code在运行时调试Node.js服务器:

    > 我在连接到mongoose时遇到了运行时错误。请帮我通过检查运行时的mongodb配置值来调试。
    
      ⏺ 我会帮您使用Node.js调试器来调试mongoose连接问题。让我们首先了解MongoDB连接在哪里配置。
    
      ⏺ 搜索(pattern: "**/*.js")...
        ⎿  找到了100个文件
    
      ⏺ 让我们在mongoose连接点设置一个断点并继续:
    
      ⏺ nodejs-debugger:set_breakpoint (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
    
      ⏺ 让我们列出所有断点:
    
      ⏺ 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"
             }
           ]
    
      ⏺ 让我们尝试执行一段特定代码以检查连接变量:
    
      ⏺ nodejs-debugger:nodejs_inspect (MCP)(js_code: "// 获取mongoose模块并检查连接\nconst mongoose = …
                                            require('mongoose');\nconsole.log('当前mongoose版本:',
                                            mongoose.version);\nconsole.log('当前mongoose连接状态:',
                                            mongoose.connection.readyState);\n// 安全地记录连接字符串(不包括密码)\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('连接字符串(屏蔽):', connectionString.replace(/(?<=mongodb\\+srv:\\/\\/\\w+:)(.+?)(?=@)/,
                                             '*****'));")
    
       ⎿  控制台输出:
           [log] 当前mongoose版本:8.9.5
           [log] 当前mongoose连接状态:0
           [log] 连接字符串(屏蔽):mongodb+srv://cooluser:coolpassword@cluster0.cojoign.mongodb.net/local_library?retryWri
           tes=true&w=majority&appName=Cluster0
    
      ⏺ 您的应用程序中看到的运行时错误与MongoDB Atlas连接问题有关。根据您的错误消息,问题是:
    
        1. 您使用的是占位符凭据("cooluser:coolpassword")
    
        要解决这个问题,您有两个选择:
    
        1. 使用本地MongoDB实例,更改app.js中的第29-30行:
        const dev_db_url = "mongodb://127.0.0.1:27017/local_library";
        2. 或正确设置MongoDB Atlas:
          - 登录到Atlas:https://cloud.mongodb.com
          - 前往网络访问并添加您的当前IP到白名单
          - 创建正确的数据库凭据
          - 使用真实凭据更新连接字符串
    
        您希望采取哪个选项?