get_location
Obtain the current execution location when the NodeJS debugger is paused, helping developers understand exactly where the code stopped.
Instructions
Gets the current execution location when paused
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_location"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mcp-server.js:1009-1082 (registration)Tool registration for 'get_location' on line 1010 using server.tool(), with empty schema on line 1013.
// Get current location tool 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:1014-1081 (handler)Handler function that gets current execution location when paused - reads call frame location, builds callstack, retrieves source context, and returns JSON with url, lineNumber, columnNumber, callstack, and sourceContext.
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 schema object (no parameters) for the get_location tool.
{},