Skip to main content
Glama

get_contexts

Retrieve variable contexts (Local, Superglobals, 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

NameRequiredDescriptionDefault
stack_depthNoStack frame depth (0 = current frame)
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" }, "stack_depth": { "default": 0, "description": "Stack frame depth (0 = current frame)", "type": "integer" } }, "type": "object" }

Implementation Reference

  • MCP tool registration and handler for 'get_contexts'. Defines input schema (stack_depth, session_id), resolves the debug session, fetches contexts using session.getContexts(stack_depth), and returns formatted JSON list of context IDs and names or error.
    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), }), }, ], }; } } );
  • Zod input schema for the get_contexts tool: stack_depth (integer, default 0), optional session_id.
    { stack_depth: z .number() .int() .default(0) .describe('Stack frame depth (0 = current frame)'), session_id: z.string().optional().describe('Session ID'),
  • Supporting method in DebugSession class that sends the DBGP 'context_names' command for the specified stack depth and parses the response into Context objects.
    async getContexts(stackDepth: number = 0): Promise<Context[]> { const response = await this.connection.sendCommand('context_names', { d: stackDepth.toString(), }); return this.connection.parseContexts(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