Skip to main content
Glama

export_session

Export debug session reports in JSON or HTML format to document PHP debugging activities and results for analysis or sharing.

Instructions

Export the current debug session as a report

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNoExport formatjson
session_idNoSession ID

Implementation Reference

  • Registers the 'export_session' tool with input schema and handler. The handler resolves the session, captures a snapshot with watch values, and exports as JSON or HTML using SessionExporter.
    server.tool(
      'export_session',
      'Export the current debug session as a report',
      {
        format: z.enum(['json', 'html']).default('json').describe('Export format'),
        session_id: z.string().optional().describe('Session ID'),
      },
      async ({ format, session_id }) => {
        const session = ctx.sessionManager.resolveSession(session_id);
        if (!session) {
          return {
            content: [{ type: 'text', text: JSON.stringify({ error: 'No active session' }) }],
          };
        }
    
        // Capture final snapshot
        const watchResults = await ctx.watchManager.evaluateAll(session);
        await ctx.sessionExporter.captureSnapshot(session, {
          watchValues: watchResults,
        });
    
        const exported =
          format === 'html'
            ? ctx.sessionExporter.exportAsHtml(session)
            : ctx.sessionExporter.exportAsJson(session);
    
        return {
          content: [
            {
              type: 'text',
              text:
                format === 'html'
                  ? JSON.stringify({
                      format: 'html',
                      content: exported,
                      note: 'Save this content to a .html file to view the report',
                    })
                  : exported,
            },
          ],
        };
      }
    );
  • Core export methods of SessionExporter: exportAsJson serializes the session data to JSON, exportAsHtml generates an HTML report.
    exportAsJson(session: DebugSession): string {
      const exported = this.buildExportedSession(session);
      return JSON.stringify(exported, null, 2);
    }
    
    /**
     * Export session as HTML report
     */
    exportAsHtml(session: DebugSession): string {
      const exported = this.buildExportedSession(session);
      return this.generateHtmlReport(exported);
    }
  • SessionExporter.captureSnapshot method: captures current debug state including stack, variables, breakpoints, watches, etc., and stores snapshots for export.
    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;
    }
  • TypeScript interfaces defining the structure of DebugSnapshot and ExportedSession used in the export functionality.
    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[];
    }
    
    export interface ExportedSession {
      exportedAt: Date;
      sessionInfo: {
        id: string;
        startTime: Date;
        endTime?: Date;
        initialFile: string;
        ideKey: string;
      };
      snapshots: DebugSnapshot[];
      summary: {
        totalSnapshots: number;
        filesVisited: string[];
        breakpointsHit: number;
        totalSteps: number;
      };
    }

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