Skip to main content
Glama

get_contexts

Retrieve variable contexts including Local, Superglobals, and User-defined constants at the current debugging position to inspect PHP application state during debugging sessions.

Instructions

Get available variable contexts (Local, Superglobals, User-defined constants) at the current position

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
stack_depthNoStack frame depth (0 = current frame)
session_idNoSession ID

Implementation Reference

  • Registration of the 'get_contexts' MCP tool, including input schema (stack_depth, session_id) and complete handler logic that resolves the debug session and retrieves contexts via session.getContexts()
    server.tool( 'get_contexts', 'Get available variable contexts (Local, Superglobals, User-defined constants) at the current position', { stack_depth: z .number() .int() .default(0) .describe('Stack frame depth (0 = current frame)'), session_id: z.string().optional().describe('Session ID'), }, async ({ stack_depth, session_id }) => { const session = sessionManager.resolveSession(session_id); if (!session) { return { content: [ { type: 'text', text: JSON.stringify({ error: 'No active debug session' }), }, ], }; } try { const contexts = await session.getContexts(stack_depth); return { content: [ { type: 'text', text: JSON.stringify( { contexts: contexts.map((ctx) => ({ id: ctx.id, name: ctx.name, })), hint: 'Use context_id in get_variables to get variables from a specific context', }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: 'text', text: JSON.stringify({ error: 'Failed to get contexts', message: error instanceof Error ? error.message : String(error), }), }, ], }; } } );
  • Core handler implementation in DebugSession class: sends DBGP 'context_names' command with stack depth and parses the response into Context[]
    async getContexts(stackDepth: number = 0): Promise<Context[]> { const response = await this.connection.sendCommand('context_names', { d: stackDepth.toString(), }); return this.connection.parseContexts(response); }
  • Top-level registration call that invokes registerInspectionTools, thereby registering the get_contexts tool among inspection tools
    registerInspectionTools(server, ctx.sessionManager);
  • Zod input schema for the get_contexts tool parameters
    { stack_depth: z .number() .int() .default(0) .describe('Stack frame depth (0 = current frame)'), session_id: z.string().optional().describe('Session ID'),

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