Skip to main content
Glama

screenshot

Capture screenshots for visual verification during testing. Use this tool to document UI states and validate visual elements in simulators.

Instructions

Captures screenshot for visual verification. For UI coordinates, use describe_ui instead (don't determine coordinates from screenshots).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
simulatorUuidYes

Implementation Reference

  • The handler function that executes the screenshot tool: validates simulator UUID, runs 'xcrun simctl io <uuid> screenshot', encodes PNG to base64, and returns as image content.
    async (params): Promise<ToolResponse> => {
      const toolName = 'screenshot';
      const simUuidValidation = validateRequiredParam('simulatorUuid', params.simulatorUuid);
      if (!simUuidValidation.isValid) return simUuidValidation.errorResponse!;
    
      const { simulatorUuid } = params;
      const tempDir = os.tmpdir();
      const screenshotFilename = `screenshot_${uuidv4()}.png`;
      const screenshotPath = path.join(tempDir, screenshotFilename);
      // Use xcrun simctl to take screenshot
      const commandArgs = ['xcrun', 'simctl', 'io', simulatorUuid, 'screenshot', screenshotPath];
    
      log(
        'info',
        `${LOG_PREFIX}/${toolName}: Starting capture to ${screenshotPath} on ${simulatorUuid}`,
      );
    
      try {
        // Execute the screenshot command
        const result = await executeCommand(commandArgs, `${LOG_PREFIX}: screenshot`, false);
    
        if (!result.success) {
          throw new SystemError(`Failed to capture screenshot: ${result.error || result.output}`);
        }
    
        log('info', `${LOG_PREFIX}/${toolName}: Success for ${simulatorUuid}`);
    
        try {
          // Read the image file into memory
          const imageBuffer = await fs.readFile(screenshotPath);
    
          // Encode the image as a Base64 string
          const base64Image = imageBuffer.toString('base64');
    
          log('info', `${LOG_PREFIX}/${toolName}: Successfully encoded image as Base64`);
    
          // Clean up the temporary file
          await fs.unlink(screenshotPath).catch((err) => {
            log('warning', `${LOG_PREFIX}/${toolName}: Failed to delete temporary file: ${err}`);
          });
    
          // Return the image directly in the tool response
          return {
            content: [
              {
                type: 'image',
                data: base64Image,
                mimeType: 'image/png',
              },
            ],
          };
        } catch (fileError) {
          log('error', `${LOG_PREFIX}/${toolName}: Failed to process image file: ${fileError}`);
          return createErrorResponse(
            `Screenshot captured but failed to process image file: ${fileError instanceof Error ? fileError.message : String(fileError)}`,
            undefined,
            'FileProcessingError',
          );
        }
      } catch (_error) {
        log('error', `${LOG_PREFIX}/${toolName}: Failed - ${_error}`);
        if (_error instanceof SystemError) {
          return createErrorResponse(
            `System error executing screenshot: ${_error.message}`,
            _error.originalError?.stack,
            _error.name,
          );
        }
        return createErrorResponse(
          `An unexpected error occurred: ${_error instanceof Error ? _error.message : String(_error)}`,
          undefined,
          'UnexpectedError',
        );
      }
    },
  • Zod schema for input parameters: requires 'simulatorUuid' as a valid UUID string.
      simulatorUuid: z.string().uuid('Invalid Simulator UUID format'),
    },
  • Module-level registration function that calls server.tool('screenshot', description, schema, handler).
    export function registerScreenshotTool(server: McpServer): void {
      server.tool(
        'screenshot',
        "Captures screenshot for visual verification. For UI coordinates, use describe_ui instead (don't determine coordinates from screenshots).",
        {
          simulatorUuid: z.string().uuid('Invalid Simulator UUID format'),
        },
        async (params): Promise<ToolResponse> => {
          const toolName = 'screenshot';
          const simUuidValidation = validateRequiredParam('simulatorUuid', params.simulatorUuid);
          if (!simUuidValidation.isValid) return simUuidValidation.errorResponse!;
    
          const { simulatorUuid } = params;
          const tempDir = os.tmpdir();
          const screenshotFilename = `screenshot_${uuidv4()}.png`;
          const screenshotPath = path.join(tempDir, screenshotFilename);
          // Use xcrun simctl to take screenshot
          const commandArgs = ['xcrun', 'simctl', 'io', simulatorUuid, 'screenshot', screenshotPath];
    
          log(
            'info',
            `${LOG_PREFIX}/${toolName}: Starting capture to ${screenshotPath} on ${simulatorUuid}`,
          );
    
          try {
            // Execute the screenshot command
            const result = await executeCommand(commandArgs, `${LOG_PREFIX}: screenshot`, false);
    
            if (!result.success) {
              throw new SystemError(`Failed to capture screenshot: ${result.error || result.output}`);
            }
    
            log('info', `${LOG_PREFIX}/${toolName}: Success for ${simulatorUuid}`);
    
            try {
              // Read the image file into memory
              const imageBuffer = await fs.readFile(screenshotPath);
    
              // Encode the image as a Base64 string
              const base64Image = imageBuffer.toString('base64');
    
              log('info', `${LOG_PREFIX}/${toolName}: Successfully encoded image as Base64`);
    
              // Clean up the temporary file
              await fs.unlink(screenshotPath).catch((err) => {
                log('warning', `${LOG_PREFIX}/${toolName}: Failed to delete temporary file: ${err}`);
              });
    
              // Return the image directly in the tool response
              return {
                content: [
                  {
                    type: 'image',
                    data: base64Image,
                    mimeType: 'image/png',
                  },
                ],
              };
            } catch (fileError) {
              log('error', `${LOG_PREFIX}/${toolName}: Failed to process image file: ${fileError}`);
              return createErrorResponse(
                `Screenshot captured but failed to process image file: ${fileError instanceof Error ? fileError.message : String(fileError)}`,
                undefined,
                'FileProcessingError',
              );
            }
          } catch (_error) {
            log('error', `${LOG_PREFIX}/${toolName}: Failed - ${_error}`);
            if (_error instanceof SystemError) {
              return createErrorResponse(
                `System error executing screenshot: ${_error.message}`,
                _error.originalError?.stack,
                _error.name,
              );
            }
            return createErrorResponse(
              `An unexpected error occurred: ${_error instanceof Error ? _error.message : String(_error)}`,
              undefined,
              'UnexpectedError',
            );
          }
        },
      );
    }
  • Entry in toolRegistrations array that conditionally registers the screenshot tool based on XCODEBUILDMCP_TOOL_SCREENSHOT env var, in UI_TESTING and IOS_SIMULATOR_WORKFLOW groups.
    {
      register: registerScreenshotTool,
      groups: [ToolGroup.IOS_SIMULATOR_WORKFLOW, ToolGroup.UI_TESTING],
      envVar: 'XCODEBUILDMCP_TOOL_SCREENSHOT',
    },

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

B3.4/5.0
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the tool captures screenshots for visual verification, implying a read-only operation that produces an image. However, it lacks details on permissions, output format (e.g., image type, size), side effects, or error conditions. For a tool with no annotations, this is a significant gap in transparency.

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 highly concise and well-structured: two sentences that efficiently convey the purpose and a key usage guideline. Every word serves a clear purpose, with no wasted text, making it easy to parse and understand quickly.

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

Completeness2/5

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

Given the tool's complexity (involving screenshot capture with a required parameter), lack of annotations, no output schema, and low schema description coverage, the description is incomplete. It misses critical details like parameter explanation, output format, and behavioral constraints, making it inadequate for full agent understanding without external context.

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

Parameters2/5

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

The input schema has 1 parameter (simulatorUuid) with 0% description coverage, meaning the schema provides no semantic context. The description does not mention this parameter at all, failing to explain what simulatorUuid is, why it's required, or how it relates to screenshot capture. This leaves the parameter's meaning undocumented.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Captures screenshot for visual verification.' It specifies the action (captures) and resource (screenshot) with a clear goal (visual verification). However, it doesn't explicitly differentiate from all sibling tools beyond the one mentioned alternative (describe_ui), leaving some ambiguity about its uniqueness in the broader context of the toolset.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use this tool vs. alternatives: 'For UI coordinates, use describe_ui instead (don't determine coordinates from screenshots).' This clearly defines a specific exclusion case and names the alternative tool, helping the agent avoid misuse.

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