Skip to main content
Glama

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
NameRequiredDescriptionDefault
session_idNoSession ID

Implementation Reference

  • 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), }), }, ], }; } } );
  • Input schema definition using Zod for the get_stack_trace tool: optional session_id parameter.
    { session_id: z.string().optional().describe('Session ID'), },
  • 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), }), }, ], }; } } );
  • Higher-level registration call in registerAllTools that invokes registerInspectionTools, thereby registering get_stack_trace among inspection tools.
    registerInspectionTools(server, ctx.sessionManager);
  • 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); }

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/kpanuragh/xdebug-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server