Skip to main content
Glama

capture_snapshot

Capture the current debug state including variables, stack traces, and breakpoints to generate an export report for PHP debugging sessions.

Instructions

Capture a snapshot of the current debug state for the export report

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idNoSession ID

Implementation Reference

  • Primary MCP tool handler for 'capture_snapshot': resolves the debug session (optionally by ID), evaluates all watch expressions, invokes the SessionExporter to capture the current debug state snapshot, and returns success status with snapshot count and current state.
    'capture_snapshot', 'Capture a snapshot of the current debug state for the export report', { session_id: z.string().optional().describe('Session ID'), }, async ({ session_id }) => { const session = ctx.sessionManager.resolveSession(session_id); if (!session) { return { content: [{ type: 'text', text: JSON.stringify({ error: 'No active session' }) }], }; } const watchResults = await ctx.watchManager.evaluateAll(session); const snapshot = await ctx.sessionExporter.captureSnapshot(session, { watchValues: watchResults, }); return { content: [ { type: 'text', text: JSON.stringify({ success: true, snapshotCount: ctx.sessionExporter.snapshotCount, currentState: snapshot.state, }), }, ], }; } ); }
  • Core helper method in SessionExporter class that implements the snapshot capture logic: retrieves session state, stack trace, variables, breakpoints; incorporates optional watch values/request context/log entries; stores and returns the DebugSnapshot.
    async captureSnapshot( session: DebugSession, additionalData?: { watchValues?: Array<{ expression: string; value: Property | null; error?: string }>; requestContext?: RequestContext; logEntries?: LogEntry[]; } ): Promise<DebugSnapshot> { const state = session.getState(); let stackTrace: StackFrame[] = []; let variables: Record<string, Property> = {}; let breakpoints: Breakpoint[] = []; try { stackTrace = await session.getStackTrace(); } catch { // May fail if session is not in break state } try { const vars = await session.getVariables(0, 0); for (const v of vars) { variables[v.name] = v; } } catch { // May fail } try { breakpoints = await session.listBreakpoints(); } catch { // May fail } if (state.filename) { this.filesVisited.add(state.filename); } this.totalSteps++; const snapshot: DebugSnapshot = { timestamp: new Date(), sessionId: session.id, state, stackTrace, variables, watchValues: additionalData?.watchValues || [], breakpoints, requestContext: additionalData?.requestContext, logEntries: additionalData?.logEntries, }; this.snapshots.push(snapshot); return snapshot; }
  • Input schema validation using Zod for the capture_snapshot tool: optional session_id string.
    { session_id: z.string().optional().describe('Session ID'), },
  • TypeScript interface defining the structure of a DebugSnapshot, used by the captureSnapshot implementation.
    export interface DebugSnapshot { timestamp: Date; sessionId: string; state: SessionState; stackTrace: StackFrame[]; variables: Record<string, Property>; watchValues: Array<{ expression: string; value: Property | null; error?: string }>; breakpoints: Breakpoint[]; requestContext?: RequestContext; logEntries?: LogEntry[]; }
  • Registration of the capture_snapshot tool on the MCP server in advanced tools module.
    'capture_snapshot', 'Capture a snapshot of the current debug state for the export report', { session_id: z.string().optional().describe('Session ID'), }, async ({ session_id }) => { const session = ctx.sessionManager.resolveSession(session_id); if (!session) { return { content: [{ type: 'text', text: JSON.stringify({ error: 'No active session' }) }], }; } const watchResults = await ctx.watchManager.evaluateAll(session); const snapshot = await ctx.sessionExporter.captureSnapshot(session, { watchValues: watchResults, }); return { content: [ { type: 'text', text: JSON.stringify({ success: true, snapshotCount: ctx.sessionExporter.snapshotCount, currentState: snapshot.state, }), }, ], }; } ); }

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