Skip to main content
Glama
workbackai

MCP NodeJS Debugger

by workbackai

nodejs_inspect

Execute JavaScript code directly inside the debugged Node.js process to inspect variables and test live changes during debugging sessions.

Instructions

Executes JavaScript code in the debugged process

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
js_codeYesJavaScript code to execute

Implementation Reference

  • Registration of the 'nodejs_inspect' tool with the MCP server, including the schema definition for the 'js_code' input parameter.
    server.tool(
      "nodejs_inspect",
      "Executes JavaScript code in the debugged process",
      {
        js_code: z.string().describe("JavaScript code to execute")
      },
  • Handler function for the 'nodejs_inspect' tool. It executes JavaScript code in the debugged Node.js process via the Inspector protocol's Runtime.evaluate method, captures console output, handles complex object serialization via getProperties, and returns results as text content.
    async ({ js_code }) => {
      try {
        // Ensure debugger is enabled
        if (!inspector.debuggerEnabled) {
          await inspector.enableDebugger();
        }
        
        // Capture the current console output length to know where to start capturing new output
        const consoleStartIndex = inspector.consoleOutput.length;
        
        // Wrap the code in a try-catch with explicit console logging for errors
        let codeToExecute = `
          try {
            ${js_code}
          } catch (e) {
            e;  // Return the error
          }
        `;
        
        const response = await inspector.send('Runtime.evaluate', {
          expression: codeToExecute,
          contextId: 1,
          objectGroup: 'console',
          includeCommandLineAPI: true,
          silent: false,
          returnByValue: true,
          generatePreview: true,
          awaitPromise: true  // This will wait for promises to resolve
        });
        
        // Give some time for console logs to be processed
        await new Promise(resolve => setTimeout(resolve, 200));
        
        // Get any console output that was generated during execution
        const consoleOutputs = inspector.consoleOutput.slice(consoleStartIndex);
        const consoleText = consoleOutputs.map(output => 
          `[${output.type}] ${output.message}`
        ).join('\n');
        
        // Process the return value
        let result;
        if (response.result) {
          if (response.result.type === 'object') {
            if (response.result.value) {
              // If we have a value, use it
              result = response.result.value;
            } else if (response.result.objectId) {
              // If we have an objectId but no value, the object was too complex to serialize directly
              // Get more details about the object
              try {
                const objectProps = await inspector.getProperties(response.result.objectId);
                const formattedObject = {};
                
                for (const prop of objectProps.result) {
                  if (prop.value) {
                    if (prop.value.type === 'object' && prop.value.subtype !== 'null') {
                      // For nested objects, try to get their details too
                      if (prop.value.objectId) {
                        try {
                          const nestedProps = await inspector.getProperties(prop.value.objectId);
                          const nestedObj = {};
                          for (const nestedProp of nestedProps.result) {
                            if (nestedProp.value) {
                              if (nestedProp.value.value !== undefined) {
                                nestedObj[nestedProp.name] = nestedProp.value.value;
                              } else {
                                nestedObj[nestedProp.name] = nestedProp.value.description || 
                                  `[${nestedProp.value.subtype || nestedProp.value.type}]`;
                              }
                            }
                          }
                          formattedObject[prop.name] = nestedObj;
                        } catch (nestedErr) {
                          formattedObject[prop.name] = prop.value.description || 
                            `[${prop.value.subtype || prop.value.type}]`;
                        }
                      } else {
                        formattedObject[prop.name] = prop.value.description || 
                          `[${prop.value.subtype || prop.value.type}]`;
                      }
                    } else if (prop.value.type === 'function') {
                      formattedObject[prop.name] = '[function]';
                    } else if (prop.value.value !== undefined) {
                      formattedObject[prop.name] = prop.value.value;
                    } else {
                      formattedObject[prop.name] = `[${prop.value.type}]`;
                    }
                  }
                }
                
                result = formattedObject;
              } catch (propErr) {
                // If we can't get properties, at least show the object description
                result = response.result.description || `[${response.result.subtype || response.result.type}]`;
              }
            } else {
              // Fallback for objects without value or objectId
              result = response.result.description || `[${response.result.subtype || response.result.type}]`;
            }
          } else if (response.result.type === 'undefined') {
            result = undefined;
          } else if (response.result.value !== undefined) {
            result = response.result.value;
          } else {
            result = `[${response.result.type}]`;
          }
        }
        
        let responseContent = [];
        
        // Add console output if there was any
        if (consoleText.length > 0) {
          responseContent.push({
            type: "text", 
            text: `Console output:\n${consoleText}`
          });
        }
        
        // Add the result
        responseContent.push({
          type: "text",
          text: `Code executed successfully. Result: ${JSON.stringify(result, null, 2)}`
        });
        
        return { content: responseContent };
      } catch (err) {
        return {
          content: [{
            type: "text",
            text: `Error executing code: ${err.message}`
          }]
        };
      }
    }
  • Input schema for nodejs_inspect: requires a 'js_code' string parameter describing JavaScript code to execute.
    {
      js_code: z.string().describe("JavaScript code to execute")
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It only states 'executes' but does not disclose side effects, destructiveness, permissions, or state modifications. For a code execution tool, this is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is one sentence, concise but under-specified. It lacks detail that could be added without significant length, so conciseness does not fully compensate for gaps.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a code execution tool, the description is incomplete. It does not mention return values, error handling, security implications, or any output format. Given no output schema or annotations, the description should provide more context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, and the parameter description 'JavaScript code to execute' adds little beyond the schema. The baseline of 3 is appropriate as the description does not compensate with additional semantic guidance.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it executes JavaScript code in the debugged process, using specific verb and resource. However, it does not differentiate from sibling tool 'evaluate', which may also execute code expressions.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives, nor any when-not-to-use conditions. This leaves the agent without context for appropriate invocation.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/workbackai/mcp-nodejs-debugger'

If you have feedback or need assistance with the MCP directory API, please join our Discord server