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
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mcp-server.js:1014-1082 (handler)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}` }] }; } } );
- src/mcp-server.js:1010-1083 (registration)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}` }] }; } } );
- src/mcp-server.js:1013-1013 (schema)Empty input schema for the 'get_location' tool (no parameters required).{},