Skip to main content
Glama

capture_snapshot

Capture a debug state snapshot to generate export reports for PHP applications during Xdebug debugging sessions.

Instructions

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

Input Schema

NameRequiredDescriptionDefault
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" } }, "type": "object" }

Implementation Reference

  • MCP tool handler for 'capture_snapshot': resolves debug session, evaluates watch expressions, calls SessionExporter.captureSnapshot, returns JSON response with success status, snapshot count, and current state.
    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, }), }, ], }; }
  • Input schema for the 'capture_snapshot' tool using Zod: optional session_id string.
    { session_id: z.string().optional().describe('Session ID'), },
  • Registration of the 'capture_snapshot' MCP tool on the server using server.tool() with name, description, schema, and handler.
    server.tool( '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, }), }, ], }; } );
  • SessionExporter.captureSnapshot helper method: core logic to capture debug snapshot (state, stack, vars, breakpoints, watches) and store it for export reports.
    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; }

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