Skip to main content
Glama

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

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

  • 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), }), }, ], }; } }
  • 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), }), }, ], }; } } );
  • Zod input schema for the get_stack_trace tool: optional session_id string.
    { session_id: z.string().optional().describe('Session ID'), },
  • 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); }

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