Skip to main content
Glama

set_variable

Set variable values in PHP debugging sessions to modify program state during runtime analysis and testing.

Instructions

Set the value of a variable in the current scope

Input Schema

NameRequiredDescriptionDefault
nameYesVariable name (e.g., $x, $user->name)
valueYesNew value as a PHP literal (e.g., 42, "hello", true, null)
context_idNoContext ID
stack_depthNoStack frame depth
session_idNoSession ID

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "context_id": { "default": 0, "description": "Context ID", "type": "integer" }, "name": { "description": "Variable name (e.g., $x, $user->name)", "type": "string" }, "session_id": { "description": "Session ID", "type": "string" }, "stack_depth": { "default": 0, "description": "Stack frame depth", "type": "integer" }, "value": { "description": "New value as a PHP literal (e.g., 42, \"hello\", true, null)", "type": "string" } }, "required": [ "name", "value" ], "type": "object" }

Implementation Reference

  • MCP tool 'set_variable' handler: registers the tool, defines input schema with zod, and provides the execution logic that resolves the debug session and calls session.setVariable(name, value, options). Returns success status in MCP content format.
    server.tool( 'set_variable', 'Set the value of a variable in the current scope', { name: z.string().describe('Variable name (e.g., $x, $user->name)'), value: z.string().describe('New value as a PHP literal (e.g., 42, "hello", true, null)'), context_id: z.number().int().default(0).describe('Context ID'), stack_depth: z.number().int().default(0).describe('Stack frame depth'), session_id: z.string().optional().describe('Session ID'), }, async ({ name, value, 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 success = await session.setVariable(name, value, { contextId: context_id, stackDepth: stack_depth, }); return { content: [ { type: 'text', text: JSON.stringify({ success, name, value, message: success ? `Variable ${name} set to ${value}` : 'Failed to set variable', }), }, ], }; } catch (error) { return { content: [ { type: 'text', text: JSON.stringify({ error: 'Failed to set variable', message: error instanceof Error ? error.message : String(error), }), }, ], }; } } );
  • Core helper method in DebugSession that implements variable setting by sending the DBGP 'property_set' command with name, value, and optional context/stack options.
    async setVariable( name: string, value: string, options?: { contextId?: number; stackDepth?: number; type?: string; } ): Promise<boolean> { const args: Record<string, string> = { n: name, }; if (options?.contextId !== undefined) { args['c'] = options.contextId.toString(); } if (options?.stackDepth !== undefined) { args['d'] = options.stackDepth.toString(); } if (options?.type) { args['t'] = options.type; } const response = await this.connection.sendCommand('property_set', args, value); return response.success === true || !response.error; }
  • Top-level registration call in tools index that invokes registerInspectionTools, which includes the set_variable tool registration.
    registerInspectionTools(server, ctx.sessionManager);

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