Skip to main content
Glama
workbackai

MCP NodeJS Debugger

by workbackai

inspect_variables

Inspect variables in current scope to debug NodeJS server code by examining local or global values during execution.

Instructions

Inspects variables in current scope

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scopeNoScope to inspect (local/global)

Implementation Reference

  • The handler function that implements the core logic of the 'inspect_variables' tool. It handles both global and local scope inspection using the Node.js debugger protocol. For local scopes when paused, it iterates through the scope chain of the top call frame, fetches properties using getProperties, and formats the variables for output.
    async ({ scope = 'local' }) => {
      try {
        // Ensure debugger is enabled
        if (!inspector.debuggerEnabled) {
          await inspector.enableDebugger();
        }
        
        if (scope === 'global' || !inspector.paused) {
          // For global scope or when not paused, use Runtime.globalProperties
          const response = await inspector.send('Runtime.globalLexicalScopeNames', {});
          
          // Get global object properties for a more complete picture
          const globalObjResponse = await inspector.send('Runtime.evaluate', {
            expression: 'this',
            contextId: 1,
            returnByValue: true
          });
          
          return {
            content: [{
              type: "text",
              text: JSON.stringify({
                lexicalNames: response.names,
                globalThis: globalObjResponse.result.value
              }, null, 2)
            }]
          };
        } else {
          // For local scope when paused, get variables from the current call frame
          if (inspector.currentCallFrames.length === 0) {
            return {
              content: [{
                type: "text",
                text: "No active call frames. Debugger is not paused at a breakpoint."
              }]
            };
          }
          
          const frame = inspector.currentCallFrames[0]; // Get top frame
          const scopeChain = frame.scopeChain;
          
          // Create a formatted output of variables in scope
          const result = {};
          
          for (const scopeObj of scopeChain) {
            const { scope, type, name } = scopeObj;
            
            if (type === 'global') continue; // Skip global scope for local inspection
            
            const objProperties = await inspector.getProperties(scope.object.objectId);
            const variables = {};
            
            for (const prop of objProperties.result) {
              if (prop.value && prop.configurable) {
                if (prop.value.type === 'object' && prop.value.subtype !== 'null') {
                  variables[prop.name] = `[${prop.value.subtype || prop.value.type}]`;
                } else if (prop.value.type === 'function') {
                  variables[prop.name] = '[function]';
                } else if (prop.value.value !== undefined) {
                  variables[prop.name] = prop.value.value;
                } else {
                  variables[prop.name] = `[${prop.value.type}]`;
                }
              }
            }
            
            result[type] = variables;
          }
          
          return {
            content: [{
              type: "text",
              text: JSON.stringify(result, null, 2)
            }]
          };
        }
      } catch (err) {
        return {
          content: [{
            type: "text",
            text: `Error inspecting variables: ${err.message}`
          }]
        };
      }
    }
  • The registration of the 'inspect_variables' tool using server.tool(), including name, description, input schema, and handler reference.
    server.tool(
      "inspect_variables",
      "Inspects variables in current scope",
      {
        scope: z.string().optional().describe("Scope to inspect (local/global)")
      },
      async ({ scope = 'local' }) => {
        try {
          // Ensure debugger is enabled
          if (!inspector.debuggerEnabled) {
            await inspector.enableDebugger();
          }
          
          if (scope === 'global' || !inspector.paused) {
            // For global scope or when not paused, use Runtime.globalProperties
            const response = await inspector.send('Runtime.globalLexicalScopeNames', {});
            
            // Get global object properties for a more complete picture
            const globalObjResponse = await inspector.send('Runtime.evaluate', {
              expression: 'this',
              contextId: 1,
              returnByValue: true
            });
            
            return {
              content: [{
                type: "text",
                text: JSON.stringify({
                  lexicalNames: response.names,
                  globalThis: globalObjResponse.result.value
                }, null, 2)
              }]
            };
          } else {
            // For local scope when paused, get variables from the current call frame
            if (inspector.currentCallFrames.length === 0) {
              return {
                content: [{
                  type: "text",
                  text: "No active call frames. Debugger is not paused at a breakpoint."
                }]
              };
            }
            
            const frame = inspector.currentCallFrames[0]; // Get top frame
            const scopeChain = frame.scopeChain;
            
            // Create a formatted output of variables in scope
            const result = {};
            
            for (const scopeObj of scopeChain) {
              const { scope, type, name } = scopeObj;
              
              if (type === 'global') continue; // Skip global scope for local inspection
              
              const objProperties = await inspector.getProperties(scope.object.objectId);
              const variables = {};
              
              for (const prop of objProperties.result) {
                if (prop.value && prop.configurable) {
                  if (prop.value.type === 'object' && prop.value.subtype !== 'null') {
                    variables[prop.name] = `[${prop.value.subtype || prop.value.type}]`;
                  } else if (prop.value.type === 'function') {
                    variables[prop.name] = '[function]';
                  } else if (prop.value.value !== undefined) {
                    variables[prop.name] = prop.value.value;
                  } else {
                    variables[prop.name] = `[${prop.value.type}]`;
                  }
                }
              }
              
              result[type] = variables;
            }
            
            return {
              content: [{
                type: "text",
                text: JSON.stringify(result, null, 2)
              }]
            };
          }
        } catch (err) {
          return {
            content: [{
              type: "text",
              text: `Error inspecting variables: ${err.message}`
            }]
          };
        }
      }
    );
  • Zod input schema defining the optional 'scope' parameter for local or global variable inspection.
    {
      scope: z.string().optional().describe("Scope to inspect (local/global)")
    },
  • Helper method in the Inspector class used by the tool to retrieve detailed properties of scope objects during local variable inspection.
    async getProperties(objectId, ownProperties = true) {
    	try {
    		return await this.send('Runtime.getProperties', {
    			objectId,
    			ownProperties,
    			accessorPropertiesOnly: false,
    			generatePreview: true
    		});
    	} catch (err) {
    		throw err;
    	}
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It doesn't disclose behavioral traits such as whether this is a read-only operation, if it requires a debugger session, what happens if no variables exist, or potential rate limits. The description is minimal and lacks essential context for safe invocation.

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

Conciseness4/5

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

The description is a single, efficient sentence with zero waste, making it appropriately sized and front-loaded. However, it's overly concise to the point of under-specification, slightly reducing its effectiveness for clarity.

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?

Given the complexity (debugging tool with no annotations or output schema), the description is incomplete. It doesn't explain return values, error conditions, or dependencies (e.g., requires active debugging). For a tool in a debugging context with siblings like 'set_breakpoint', more detail is needed to guide the agent effectively.

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?

The input schema has 1 parameter with 100% description coverage ('Scope to inspect (local/global)'), so the schema does the heavy lifting. The description adds no meaning beyond this, as it doesn't explain parameter usage, defaults, or implications. Baseline 3 is appropriate given high schema coverage.

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

Purpose3/5

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

The description 'Inspects variables in current scope' clearly states the verb ('inspects') and resource ('variables'), but it's vague about what 'inspects' entails (e.g., listing, viewing details). It distinguishes from siblings like 'evaluate' or 'get_console_output' by focusing on variables, but lacks specificity on scope or output format.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., debugging context), exclusions, or compare to siblings like 'evaluate' (which might handle expressions) or 'get_location' (which provides context). Usage is implied by the name but not explicitly stated.

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