Show HN:我们制作了一个 MCP 服务器,以便 Cursor 能够自行调试 Node.js
Show HN: We made an MCP server so Cursor can debug Node.js on its own

原始链接: https://www.npmjs.com/package/@hyperdrive-eng/mcp-nodejs-debugger

`mcp-nodejs-debugger` 包允许 Claude Code 在运行时调试 NodeJS 应用程序。要使用它,请使用 `claude mcp add nodejs-debugger npx @hyperdrive-eng/mcp-nodejs-debugger` 将调试器添加到 Claude Code,然后使用 `node --inspect {your_file.js}` 以调试模式启动你的 NodeJS 服务器。Claude 连接后,你可以要求它调试运行时错误。 例如,如果你遇到 Mongoose 连接错误,请指示 Claude 使用 `nodejs-debugger mcp` 进行调试。然后,Claude 可以搜索相关文件,设置断点,列出现有断点,并通过 `nodejs_inspect` 执行代码片段以检查连接变量。它会显示控制台输出,其中包含当前的 Mongoose 版本、连接状态和经过掩码处理的连接字符串。根据输出,Claude 会建议一些解决方案,例如使用本地 MongoDB 实例或使用正确的凭据和白名单 IP 地址配置 MongoDB Atlas。

代码编辑器Cursor有时会陷入调试循环中。为此,Hyperdrive Engineering的开发者创建了一个原型MCP(机器控制协议)服务器,允许Cursor直接在运行时调试Node.js应用程序。这避免了Cursor仅仅依靠插入`console.log`语句的需要,虽然有时这很有帮助,但并不总是高效的。该项目已在GitHub上开源 (github.com/hyperdrive-eng/mcp-nodejs-debugger),旨在为Cursor提供对应用程序行为更深入的洞察,帮助其摆脱这些低效的循环。开发者正在寻求对该原型的反馈,希望对改进Cursor的调试能力感兴趣的用户能够参与。他们试图解决的问题是Cursor容易陷入重复性、低效的调试循环,这是一个在在线论坛中经常被强调的常见问题。

原文

@hyperdrive-eng/mcp-nodejs-debugger

0.2.1 • Public • Published

An MCP server that gives Claude Code access to NodeJS at runtime to help you debug: mcp-nodejs-debugger.

  1. Add to Claude Code:

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

    claude
    ╭───────────────────────────────────────────────────────╮
    │ ✻ Welcome to Claude Code research preview!            │
    │                                                       │
    │   /help for help                                      │
    │                                                       │
    │   Found 1 MCP server (use /mcp for status)            │
    ╰───────────────────────────────────────────────────────╯
  3. Run a NodeJS server in debug mode (i.e. with the --inspect flat)

    # In another terminal
    node --inspect {your_file.js}
  4. Ask Claude Code to debug your NodeJS server at runtime

    > I'm getting a runtime error in NodeJS. 
    
      {YOUR_RUNTIME_ERROR}
      
      Please help me debug this error at runtime using the nodejs-debugger mcp.
  1. Add to Claude Code:

    claude mcp add nodejs-debugger npx mcp-nodejs-debugger
  2. Verify connection

    > /mcp
      ⎿  MCP Server Status
    
         • nodejs-debugger: connected
  3. Remove from Claude Code:

    claude remove nodejs-debugger
  1. Here is a buggy NodeJS server:

    node --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
    }
    
  2. Claude Code debugs the NodeJS server at runtime:

    > 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:[email protected]/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:[email protected]/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?

Package Sidebar

Install

npm i @hyperdrive-eng/mcp-nodejs-debugger

Weekly Downloads

联系我们 contact @ memedata.com