get_variables
Retrieve variables at the current execution point in PHP debugging, including local variables, superglobals, and user constants by specifying context and stack depth.
Instructions
Get all variables at the current execution point. Use context_id to switch between local variables, superglobals, etc.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context_id | No | Context ID: 0=Local variables, 1=Superglobals, 2=User constants | |
| 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": {
"context_id": {
"default": 0,
"description": "Context ID: 0=Local variables, 1=Superglobals, 2=User constants",
"type": "integer"
},
"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:162-226 (handler)Full MCP tool definition for 'get_variables' including description, input schema, and execution handler that fetches variables from the session and formats the output.server.tool( 'get_variables', 'Get all variables at the current execution point. Use context_id to switch between local variables, superglobals, etc.', { context_id: z .number() .int() .default(0) .describe('Context ID: 0=Local variables, 1=Superglobals, 2=User constants'), stack_depth: z .number() .int() .default(0) .describe('Stack frame depth (0 = current frame)'), session_id: z.string().optional().describe('Session ID'), }, async ({ context_id, 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 variables = await session.getVariables(context_id, stack_depth); return { content: [ { type: 'text', text: JSON.stringify( { variables: variables.map((v) => formatProperty(v)), count: variables.length, context_id, stack_depth, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: 'text', text: JSON.stringify({ error: 'Failed to get variables', message: error instanceof Error ? error.message : String(error), }), }, ], }; } } );
- src/tools/inspection.ts:165-177 (schema)Zod input schema defining parameters for the get_variables tool: context_id, stack_depth, and optional session_id.{ context_id: z .number() .int() .default(0) .describe('Context ID: 0=Local variables, 1=Superglobals, 2=User constants'), stack_depth: z .number() .int() .default(0) .describe('Stack frame depth (0 = current frame)'), session_id: z.string().optional().describe('Session ID'), },
- src/tools/index.ts:58-58 (registration)High-level registration call that invokes registerInspectionTools, which registers the get_variables tool among others on the MCP server.registerInspectionTools(server, ctx.sessionManager);
- src/tools/inspection.ts:12-31 (helper)Utility function to recursively format DBGP Property objects into a JSON-friendly structure for tool responses, used in get_variables output.function formatProperty(prop: Property, depth: number = 0): Record<string, unknown> { const result: Record<string, unknown> = { name: prop.name, type: prop.type, }; if (prop.classname) result.classname = prop.classname; if (prop.value !== undefined) result.value = prop.value; if (prop.numchildren !== undefined && prop.numchildren > 0) { result.numchildren = prop.numchildren; } if (prop.constant) result.constant = true; // Include nested properties if present and not too deep if (prop.properties && prop.properties.length > 0 && depth < 3) { result.children = prop.properties.map((p) => formatProperty(p, depth + 1)); } return result; }
- src/session/session.ts:363-372 (helper)Core DebugSession method implementing variable retrieval via DBGP 'context_get' command, called by the tool handler.async getVariables( contextId: number = 0, stackDepth: number = 0 ): Promise<Property[]> { const response = await this.connection.sendCommand('context_get', { c: contextId.toString(), d: stackDepth.toString(), }); return this.connection.parseProperties(response); }