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
| Name | Required | Description | Default |
|---|---|---|---|
| stack_depth | No | Stack frame depth (0 = current frame) | |
| 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"
},
"stack_depth": {
"default": 0,
"description": "Stack frame depth (0 = current frame)",
"type": "integer"
}
},
"type": "object"
}
Implementation Reference
- src/tools/inspection.ts:99-159 (handler)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), }), }, ], }; } } );
- src/tools/inspection.ts:102-108 (schema)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'),
- src/session/session.ts:356-361 (helper)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); }