Skip to main content
Glama

ios_take_screenshot

Capture screenshots from iOS simulators by specifying device UDID and save path for development testing and debugging workflows.

Instructions

Take a screenshot of an iOS simulator

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
udidYesSimulator UDID
pathYesAbsolute path to save screenshot

Implementation Reference

  • Handler function that validates inputs, performs security and path checks, executes xcrun simctl to take screenshot, verifies file creation, and returns structured result.
    handler: async (args: any) => {
      checkMacOS();
    
      const validation = IosSimulatorScreenshotSchema.safeParse(args);
      if (!validation.success) {
        throw new Error(`Invalid request: ${validation.error.message}`);
      }
    
      const { udid, path: screenshotPath } = validation.data;
    
      // Validate UDID format
      if (!validateUDID(udid)) {
        throw new Error(`Invalid simulator UDID format. UDID must be in format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX: ${udid}`);
      }
    
      // Validate screenshot path - must be absolute and not contain dangerous patterns
      if (!path.isAbsolute(screenshotPath)) {
        throw new Error(`Screenshot path must be absolute. Path must start with /: ${screenshotPath}`);
      }
    
      // Security check - prevent path traversal and access to sensitive directories
      const normalizedPath = path.normalize(screenshotPath);
      const dangerousPaths = ['/etc', '/usr', '/System', '/private', '/var'];
      if (dangerousPaths.some(dangerous => normalizedPath.startsWith(dangerous))) {
        throw new Error(`Access to this path is not allowed. Path access denied for security reasons: ${normalizedPath}`);
      }
    
      // Ensure file has image extension
      const allowedExtensions = ['.png', '.jpg', '.jpeg'];
      const extension = path.extname(screenshotPath).toLowerCase();
      if (!allowedExtensions.includes(extension)) {
        throw new Error(`Screenshot file must have image extension. Allowed extensions: ${allowedExtensions.join(', ')}. Got: ${extension}`);
      }
    
      // Create directory if it doesn't exist
      const directory = path.dirname(screenshotPath);
      try {
        await fs.mkdir(directory, { recursive: true });
      } catch (mkdirError) {
        throw new Error(`Failed to create screenshot directory: ${mkdirError}`);
      }
    
      const result = await processExecutor.execute('xcrun', ['simctl', 'io', udid, 'screenshot', screenshotPath]);
    
      if (result.exitCode !== 0) {
        throw new Error(`Failed to capture screenshot: ${result.stderr}`);
      }
    
      // Verify screenshot was created
      let fileStats;
      try {
        fileStats = await fs.stat(screenshotPath);
      } catch {
        throw new Error(`Screenshot file was not created. Expected file: ${screenshotPath}`);
      }
    
      return {
        success: true,
        data: {
          udid,
          screenshotPath,
          fileSize: fileStats.size,
          status: 'captured',
          message: 'Screenshot captured successfully',
          output: result.stdout,
        },
      };
    }
  • Zod schema used for input validation in the handler, defining udid and path parameters.
     * Zod validation schema for ios_simulator_screenshot tool.
     *
     * @type {z.ZodObject}
     * @property {string} udid - Simulator UDID
     * @property {string} path - Output file path for screenshot
     */
    const IosSimulatorScreenshotSchema = z.object({
      udid: z.string().min(1),
      path: z.string().min(1),
    });
  • Registration of the tool in the createIOSTools function, including name, description, inputSchema (JSON schema for MCP), and reference to handler.
    tools.set('ios_take_screenshot', {
      name: 'ios_take_screenshot',
      description: 'Take a screenshot of an iOS simulator',
      inputSchema: {
        type: 'object',
        properties: {
          udid: { type: 'string', minLength: 1, description: 'Simulator UDID' },
          path: { type: 'string', minLength: 1, description: 'Absolute path to save screenshot' }
        },
        required: ['udid', 'path']
      },
      handler: async (args: any) => {
        checkMacOS();
    
        const validation = IosSimulatorScreenshotSchema.safeParse(args);
        if (!validation.success) {
          throw new Error(`Invalid request: ${validation.error.message}`);
        }
    
        const { udid, path: screenshotPath } = validation.data;
    
        // Validate UDID format
        if (!validateUDID(udid)) {
          throw new Error(`Invalid simulator UDID format. UDID must be in format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX: ${udid}`);
        }
    
        // Validate screenshot path - must be absolute and not contain dangerous patterns
        if (!path.isAbsolute(screenshotPath)) {
          throw new Error(`Screenshot path must be absolute. Path must start with /: ${screenshotPath}`);
        }
    
        // Security check - prevent path traversal and access to sensitive directories
        const normalizedPath = path.normalize(screenshotPath);
        const dangerousPaths = ['/etc', '/usr', '/System', '/private', '/var'];
        if (dangerousPaths.some(dangerous => normalizedPath.startsWith(dangerous))) {
          throw new Error(`Access to this path is not allowed. Path access denied for security reasons: ${normalizedPath}`);
        }
    
        // Ensure file has image extension
        const allowedExtensions = ['.png', '.jpg', '.jpeg'];
        const extension = path.extname(screenshotPath).toLowerCase();
        if (!allowedExtensions.includes(extension)) {
          throw new Error(`Screenshot file must have image extension. Allowed extensions: ${allowedExtensions.join(', ')}. Got: ${extension}`);
        }
    
        // Create directory if it doesn't exist
        const directory = path.dirname(screenshotPath);
        try {
          await fs.mkdir(directory, { recursive: true });
        } catch (mkdirError) {
          throw new Error(`Failed to create screenshot directory: ${mkdirError}`);
        }
    
        const result = await processExecutor.execute('xcrun', ['simctl', 'io', udid, 'screenshot', screenshotPath]);
    
        if (result.exitCode !== 0) {
          throw new Error(`Failed to capture screenshot: ${result.stderr}`);
        }
    
        // Verify screenshot was created
        let fileStats;
        try {
          fileStats = await fs.stat(screenshotPath);
        } catch {
          throw new Error(`Screenshot file was not created. Expected file: ${screenshotPath}`);
        }
    
        return {
          success: true,
          data: {
            udid,
            screenshotPath,
            fileSize: fileStats.size,
            status: 'captured',
            message: 'Screenshot captured successfully',
            output: result.stdout,
          },
        };
      }
    });
  • Helper function to validate UDID format, used in the handler.
    const validateUDID = (udid: string): boolean => {
      const uuidPattern = /^[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}$/i;
      return uuidPattern.test(udid);
    };
  • Helper function to ensure running on macOS, called at start of handler.
    const checkMacOS = (): void => {
      if (process.platform !== 'darwin') {
        throw new Error(`iOS development tools only work on macOS. Current platform: ${process.platform}`);
      }
    };
Behavior2/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 states the action but doesn't mention critical details like whether the simulator must be running, if it requires specific permissions, potential side effects (e.g., file overwriting), or error handling. This leaves significant gaps for a mutation tool.

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, direct sentence with zero wasted words. It's front-loaded with the core action and target, making it highly efficient and easy to parse, which is ideal for conciseness.

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?

For a tool that performs a mutation (screenshot capture) with no annotations and no output schema, the description is incomplete. It doesn't explain what happens on success (e.g., file saved confirmation) or failure, nor does it cover behavioral aspects like simulator state requirements, leaving the agent with insufficient context.

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?

The input schema has 100% description coverage, clearly documenting both parameters (UDID and path). The description adds no additional semantic context beyond implying these are needed, so it meets the baseline for high schema coverage without compensating value.

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 action ('Take a screenshot') and target ('of an iOS simulator'), which is specific and unambiguous. However, it doesn't differentiate from the sibling 'android_screenshot' tool, which performs a similar function for Android, so it doesn't fully distinguish from alternatives.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like 'android_screenshot' or 'ios_list_simulators' for checking available simulators. It lacks context about prerequisites (e.g., needing a booted simulator) or exclusions, offering minimal usage direction.

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/cristianoaredes/mcp-mobile-server'

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