Skip to main content
Glama
workbackai

MCP NodeJS Debugger

by workbackai

get_location

Retrieves the current execution point when debugging is paused in a NodeJS server, showing where code execution has stopped for inspection.

Instructions

Gets the current execution location when paused

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'get_location' tool. It checks if the debugger is paused, retrieves the current call frame location, builds the call stack, fetches surrounding source code for context, and returns this information as JSON.
      async () => {
        try {
          // Ensure debugger is enabled
          if (!inspector.debuggerEnabled) {
            await inspector.enableDebugger();
          }
          
          if (!inspector.paused || inspector.currentCallFrames.length === 0) {
            return {
              content: [{
                type: "text",
                text: "Debugger is not paused at a breakpoint"
              }]
            };
          }
          
          const frame = inspector.currentCallFrames[0];
          const { url, lineNumber, columnNumber } = frame.location;
          
          // Get call stack
          const callstack = inspector.currentCallFrames.map(frame => {
            return {
              functionName: frame.functionName || '(anonymous)',
              url: frame.url,
              lineNumber: frame.location.lineNumber + 1,
              columnNumber: frame.location.columnNumber
            };
          });
          
          // Get source code for context
          let sourceContext = '';
          try {
            const scriptSource = await inspector.getScriptSource(frame.location.scriptId);
            if (scriptSource) {
              const lines = scriptSource.split('\n');
              const startLine = Math.max(0, lineNumber - 3);
              const endLine = Math.min(lines.length - 1, lineNumber + 3);
              
              for (let i = startLine; i <= endLine; i++) {
                const prefix = i === lineNumber ? '> ' : '  ';
                sourceContext += `${prefix}${i + 1}: ${lines[i]}\n`;
              }
            }
          } catch (err) {
            sourceContext = 'Unable to retrieve source code';
          }
          
          return {
            content: [{
              type: "text",
              text: JSON.stringify({
                url,
                lineNumber: lineNumber + 1,
                columnNumber,
                callstack,
                sourceContext
              }, null, 2)
            }]
          };
        } catch (err) {
          return {
            content: [{
              type: "text",
              text: `Error getting location: ${err.message}`
            }]
          };
        }
      }
    );
  • Registration of the 'get_location' tool with server.tool, including name, description, empty input schema, and inline handler function.
    server.tool(
      "get_location",
      "Gets the current execution location when paused",
      {},
      async () => {
        try {
          // Ensure debugger is enabled
          if (!inspector.debuggerEnabled) {
            await inspector.enableDebugger();
          }
          
          if (!inspector.paused || inspector.currentCallFrames.length === 0) {
            return {
              content: [{
                type: "text",
                text: "Debugger is not paused at a breakpoint"
              }]
            };
          }
          
          const frame = inspector.currentCallFrames[0];
          const { url, lineNumber, columnNumber } = frame.location;
          
          // Get call stack
          const callstack = inspector.currentCallFrames.map(frame => {
            return {
              functionName: frame.functionName || '(anonymous)',
              url: frame.url,
              lineNumber: frame.location.lineNumber + 1,
              columnNumber: frame.location.columnNumber
            };
          });
          
          // Get source code for context
          let sourceContext = '';
          try {
            const scriptSource = await inspector.getScriptSource(frame.location.scriptId);
            if (scriptSource) {
              const lines = scriptSource.split('\n');
              const startLine = Math.max(0, lineNumber - 3);
              const endLine = Math.min(lines.length - 1, lineNumber + 3);
              
              for (let i = startLine; i <= endLine; i++) {
                const prefix = i === lineNumber ? '> ' : '  ';
                sourceContext += `${prefix}${i + 1}: ${lines[i]}\n`;
              }
            }
          } catch (err) {
            sourceContext = 'Unable to retrieve source code';
          }
          
          return {
            content: [{
              type: "text",
              text: JSON.stringify({
                url,
                lineNumber: lineNumber + 1,
                columnNumber,
                callstack,
                sourceContext
              }, null, 2)
            }]
          };
        } catch (err) {
          return {
            content: [{
              type: "text",
              text: `Error getting location: ${err.message}`
            }]
          };
        }
      }
    );
  • Empty input schema for the 'get_location' tool (no parameters required).
    {},

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