get_stack_trace
Retrieve the current call stack to trace all function calls leading to the current execution point during PHP debugging sessions.
Instructions
Get the current call stack showing all function calls leading to the current position
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | No | Session ID |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"session_id": {
"description": "Session ID",
"type": "string"
}
},
"type": "object"
}
Implementation Reference
- src/tools/inspection.ts:44-95 (handler)The main handler function for the 'get_stack_trace' MCP tool. It resolves the debug session, calls session.getStackTrace() to fetch the stack frames, maps them to a simplified JSON structure (level, file, line, where, type), and returns as text content, with error handling.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:38-96 (registration)Registration of the 'get_stack_trace' tool on the McpServer using server.tool(), including name, description, input schema, and handler function.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/inspection.ts:41-43 (schema)Zod input schema for the get_stack_trace tool: optional session_id string.{ session_id: z.string().optional().describe('Session ID'), },
- src/session/session.ts:344-352 (helper)Helper method in Session class that implements getStackTrace by sending DBGP 'stack_get' command (with optional depth) and parsing the response into StackFrame[]. 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); }