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',
    },
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. It mentions the purpose and a usage constraint but lacks behavioral details such as what the screenshot captures (e.g., simulator screen), output format (e.g., image file), permissions needed, or error conditions. The description adds minimal context beyond the basic action.

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 extremely concise with only two sentences, both of which add value: the first states the purpose, and the second provides critical usage guidance. It is front-loaded with the core function and wastes no words.

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 complexity (a tool that captures screenshots likely involves visual output and simulator interaction), lack of annotations, no output schema, and poor parameter documentation, the description is incomplete. It doesn't cover what the tool returns, how the screenshot is accessed, or details about the simulatorUuid parameter, leaving significant gaps for an agent to use it effectively.

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 information. The description does not mention this parameter at all, failing to explain what simulatorUuid is or how it relates to screenshot capture. This leaves the parameter's purpose 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, though it does mention one alternative (describe_ui).

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.

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/SampsonKY/XcodeBuildMCP'

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