Skip to main content
Glama

xcresult_get_screenshot

Extract screenshots from failed Xcode test videos to diagnose issues by specifying a timestamp before the failure occurs.

Instructions

Get screenshot from a failed test at specific timestamp - extracts frame from video attachment using ffmpeg

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
xcresult_pathYesAbsolute path to the .xcresult file
test_idYesTest ID or index number to get screenshot for
timestampYesTimestamp in seconds when to extract the screenshot. WARNING: Use a timestamp BEFORE the failure (e.g., if failure is at 30.71s, use 30.69s) as failure timestamps often show the home screen after the app has crashed or reset.

Implementation Reference

  • Core handler function implementing the xcresult_get_screenshot tool. Parses XCResult file, locates test attachments, prefers video attachments (extracts frame using ffmpeg at given timestamp) or falls back to closest direct image attachment.
    public static async xcresultGetScreenshot(
      xcresultPath: string,
      testId: string,
      timestamp: number
    ): Promise<McpResult> {
      // Validate xcresult path
      if (!existsSync(xcresultPath)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          `XCResult file not found: ${xcresultPath}`
        );
      }
    
      if (!xcresultPath.endsWith('.xcresult')) {
        throw new McpError(
          ErrorCode.InvalidParams,
          `Path must be an .xcresult file: ${xcresultPath}`
        );
      }
    
      // Check if xcresult is readable
      if (!XCResultParser.isXCResultReadable(xcresultPath)) {
        throw new McpError(
          ErrorCode.InternalError,
          `XCResult file is not readable or incomplete: ${xcresultPath}`
        );
      }
    
      if (!testId || testId.trim() === '') {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Test ID or index is required'
        );
      }
    
      try {
        const parser = new XCResultParser(xcresultPath);
        
        // First find the test node to get the actual test identifier
        const testNode = await parser.findTestNode(testId);
        if (!testNode) {
          throw new McpError(
            ErrorCode.InvalidParams,
            `Test '${testId}' not found. Run xcresult_browse "${xcresultPath}" to see all available tests`
          );
        }
    
        if (!testNode.nodeIdentifier) {
          throw new McpError(
            ErrorCode.InvalidParams,
            `Test '${testId}' does not have a valid identifier for attachment retrieval`
          );
        }
    
        // Get test attachments
        const attachments = await parser.getTestAttachments(testNode.nodeIdentifier);
        
        if (attachments.length === 0) {
          throw new McpError(
            ErrorCode.InvalidParams,
            `No attachments found for test '${testNode.name}'. This test may not have failed or may not have generated screenshots/videos.`
          );
        }
    
        Logger.info(`Found ${attachments.length} attachments for test ${testNode.name}`);
    
        // Look for video attachment first (gives us actual PNG images)
        const videoAttachment = this.findVideoAttachment(attachments);
        if (videoAttachment) {
          const screenshotPath = await this.extractScreenshotFromVideo(parser, videoAttachment, testNode.name, timestamp);
          return { 
            content: [{ 
              type: 'text', 
              text: `Screenshot extracted from video for test '${testNode.name}' at ${timestamp}s: ${screenshotPath}` 
            }] 
          };
        }
    
        // Look for direct image attachment (PNG or JPEG) as fallback
        const closestImageResult = this.findClosestImageAttachment(attachments, timestamp);
        if (closestImageResult) {
          const screenshotPath = await this.exportScreenshotAttachment(parser, closestImageResult.attachment);
          const timeDiff = closestImageResult.timeDifference;
          const timeDiffText = timeDiff === 0 
            ? 'at exact timestamp' 
            : timeDiff > 0 
              ? `${timeDiff.toFixed(2)}s after requested time` 
              : `${Math.abs(timeDiff).toFixed(2)}s before requested time`;
              
          return { 
            content: [{ 
              type: 'text', 
              text: `Screenshot exported for test '${testNode.name}' (${timeDiffText}): ${screenshotPath}` 
            }] 
          };
        }
    
        // No suitable attachments found
        const attachmentTypes = attachments.map(a => a.uniform_type_identifier || a.uniformTypeIdentifier || 'unknown').join(', ');
        throw new McpError(
          ErrorCode.InvalidParams,
          `No screenshot or video attachments found for test '${testNode.name}'. Available attachment types: ${attachmentTypes}`
        );
    
      } catch (error) {
        if (error instanceof McpError) {
          throw error;
        }
    
        const errorMessage = error instanceof Error ? error.message : String(error);
        
        if (errorMessage.includes('xcresulttool')) {
          throw new McpError(
            ErrorCode.InternalError,
            `XCResult parsing failed. Make sure Xcode Command Line Tools are installed: ${errorMessage}`
          );
        }
        
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to get screenshot: ${errorMessage}`
        );
      }
    }
  • Primary input schema definition for the xcresult_get_screenshot tool, used by the MCP server for validation.
    name: 'xcresult_get_screenshot',
    description: 'Get screenshot from a failed test at specific timestamp - extracts frame from video attachment using ffmpeg',
    inputSchema: {
      type: 'object',
      properties: {
        xcresult_path: {
          type: 'string',
          description: 'Absolute path to the .xcresult file',
        },
        test_id: {
          type: 'string',
          description: 'Test ID or index number to get screenshot for',
        },
        timestamp: {
          type: 'number',
          description: 'Timestamp in seconds when to extract the screenshot. WARNING: Use a timestamp BEFORE the failure (e.g., if failure is at 30.71s, use 30.69s) as failure timestamps often show the home screen after the app has crashed or reset.',
        },
      },
      required: ['xcresult_path', 'test_id', 'timestamp'],
    },
  • Tool registration in MCP server request handler: switch case dispatching 'xcresult_get_screenshot' calls to XCResultTools handler.
    case 'xcresult_get_screenshot':
      if (!args.xcresult_path) {
        throw new McpError(ErrorCode.InvalidParams, `Missing required parameter: xcresult_path`);
      }
      if (!args.test_id) {
        throw new McpError(ErrorCode.InvalidParams, `Missing required parameter: test_id`);
      }
      if (args.timestamp === undefined) {
        throw new McpError(ErrorCode.InvalidParams, `Missing required parameter: timestamp`);
      }
      return await XCResultTools.xcresultGetScreenshot(
        args.xcresult_path as string,
        args.test_id as string,
        args.timestamp as number
      );
  • Key helper function that runs ffmpeg to extract a single PNG frame from video attachments at the specified timestamp.
    private static async runFFmpeg(videoPath: string, outputPath: string, timestamp: number): Promise<void> {
      return new Promise((resolve, reject) => {
        // Try common ffmpeg paths
        const ffmpegPaths = [
          '/opt/homebrew/bin/ffmpeg',  // Homebrew on Apple Silicon
          '/usr/local/bin/ffmpeg',     // Homebrew on Intel
          'ffmpeg'                     // System PATH
        ];
    
        let ffmpegPath = 'ffmpeg';
        for (const path of ffmpegPaths) {
          if (existsSync(path)) {
            ffmpegPath = path;
            break;
          }
        }
    
        Logger.info(`Using ffmpeg at: ${ffmpegPath}`);
        Logger.info(`Extracting frame from: ${videoPath} at ${timestamp}s`);
        Logger.info(`Output path: ${outputPath}`);
    
        // Extract a frame at the specific timestamp as PNG
        const process = spawn(ffmpegPath, [
          '-i', videoPath,           // Input video
          '-ss', timestamp.toString(), // Seek to specific timestamp
          '-frames:v', '1',          // Extract only 1 frame
          '-q:v', '2',               // High quality
          '-y',                      // Overwrite output file
          outputPath                 // Output PNG file
        ], {
          stdio: ['pipe', 'pipe', 'pipe']
        });
    
        let stderr = '';
        
        process.stderr.on('data', (data) => {
          stderr += data.toString();
        });
    
        process.on('close', (code) => {
          if (code === 0) {
            Logger.info(`ffmpeg completed successfully`);
            
            // Add a small delay to ensure file is written
            setTimeout(() => {
              if (existsSync(outputPath)) {
                resolve();
              } else {
                reject(new Error(`Screenshot file not found after ffmpeg completion: ${outputPath}`));
              }
            }, 100);
          } else {
            Logger.error(`ffmpeg failed with code ${code}`);
            Logger.error(`ffmpeg stderr: ${stderr}`);
            reject(new Error(`ffmpeg failed with code ${code}: ${stderr}`));
          }
        });
    
        process.on('error', (error) => {
          Logger.error(`ffmpeg execution error: ${error.message}`);
          reject(new Error(`Failed to run ffmpeg: ${error.message}. Make sure ffmpeg is installed (brew install ffmpeg)`));
        });
      });
    }
  • Additional registration in direct callTool method for CLI compatibility: identical switch case dispatching to the same handler.
    case 'xcresult_get_screenshot':
      if (!args.xcresult_path) {
        throw new McpError(ErrorCode.InvalidParams, `Missing required parameter: xcresult_path`);
      }
      if (!args.test_id) {
        throw new McpError(ErrorCode.InvalidParams, `Missing required parameter: test_id`);
      }
      if (args.timestamp === undefined) {
        throw new McpError(ErrorCode.InvalidParams, `Missing required parameter: timestamp`);
      }
      return await XCResultTools.xcresultGetScreenshot(
        args.xcresult_path as string,
        args.test_id as string,
        args.timestamp as number
      );
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes the tool's behavior: it extracts a frame from a video attachment using ffmpeg, which implies it processes files and may have dependencies. However, it doesn't mention potential errors, performance characteristics, or output format details, leaving some behavioral aspects unclear.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose ('Get screenshot from a failed test') and adds essential implementation detail ('extracts frame from video attachment using ffmpeg'). Every word earns its place with zero waste.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 3 parameters, 100% schema coverage, and no output schema, the description provides adequate context about what the tool does and how it works. However, it lacks details about the output (e.g., file format, location, or error handling), which would be helpful given the absence of an output schema and annotations.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all three parameters thoroughly. The description doesn't add any additional meaning beyond what's in the schema (e.g., it doesn't explain parameter interactions or provide examples). This meets the baseline of 3 when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Get screenshot'), target resource ('from a failed test'), and method ('extracts frame from video attachment using ffmpeg'). It distinguishes itself from sibling tools like xcresult_browse, xcresult_summary, or xcresult_get_ui_hierarchy by focusing on screenshot extraction rather than browsing, summarizing, or UI analysis.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context ('from a failed test') and the input schema provides a critical warning about timestamp selection, but it doesn't explicitly state when to use this tool versus alternatives like xcresult_export_attachment or xcresult_list_attachments. The guidance is helpful but not comprehensive about tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/lapfelix/XcodeMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server