get_stack_trace
Retrieve the current call stack to trace all function calls leading to the current execution point in PHP debugging sessions.
Instructions
Get the current call stack showing all function calls leading to the current position
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | No | Session ID |
Implementation Reference
- src/tools/inspection.ts:44-96 (handler)MCP tool handler for 'get_stack_trace': resolves debug session by ID, fetches stack trace via session.getStackTrace(), maps frames to simplified structure, returns JSON-formatted text content or error.async ({ session_id }) => { const session = sessionManager.resolveSession(session_id); if (!session) { return { content: [ { type: 'text', text: JSON.stringify({ error: 'No active debug session' }), }, ], }; } try { const frames = await session.getStackTrace(); return { content: [ { type: 'text', text: JSON.stringify( { stack: frames.map((frame) => ({ level: frame.level, file: frame.filename, line: frame.lineno, where: frame.where || '(main)', type: frame.type, })), depth: frames.length, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: 'text', text: JSON.stringify({ error: 'Failed to get stack trace', message: error instanceof Error ? error.message : String(error), }), }, ], }; } } );
- src/tools/inspection.ts:41-43 (schema)Input schema definition using Zod for the get_stack_trace tool: optional session_id parameter.{ session_id: z.string().optional().describe('Session ID'), },
- src/tools/inspection.ts:38-96 (registration)Primary registration of the 'get_stack_trace' tool on the MCP server within registerInspectionTools function, including name, description, input schema, and handler.server.tool( 'get_stack_trace', 'Get the current call stack showing all function calls leading to the current position', { session_id: z.string().optional().describe('Session ID'), }, async ({ session_id }) => { const session = sessionManager.resolveSession(session_id); if (!session) { return { content: [ { type: 'text', text: JSON.stringify({ error: 'No active debug session' }), }, ], }; } try { const frames = await session.getStackTrace(); return { content: [ { type: 'text', text: JSON.stringify( { stack: frames.map((frame) => ({ level: frame.level, file: frame.filename, line: frame.lineno, where: frame.where || '(main)', type: frame.type, })), depth: frames.length, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: 'text', text: JSON.stringify({ error: 'Failed to get stack trace', message: error instanceof Error ? error.message : String(error), }), }, ], }; } } );
- src/tools/index.ts:58-58 (registration)Higher-level registration call in registerAllTools that invokes registerInspectionTools, thereby registering get_stack_trace among inspection tools.registerInspectionTools(server, ctx.sessionManager);
- src/session/session.ts:344-352 (helper)DebugSession helper method getStackTrace that sends DBGP 'stack_get' command (optionally with depth), parses response into StackFrame array. Called by the tool handler.async getStackTrace(depth?: number): Promise<StackFrame[]> { const args: Record<string, string> = {}; if (depth !== undefined) { args['d'] = depth.toString(); } const response = await this.connection.sendCommand('stack_get', args); return this.connection.parseStackFrames(response); }