Skip to main content
Glama
yorifuji

MCP iOS Simulator Screenshot

by yorifuji

get_screenshot

Capture screenshots from iOS Simulator, save to a specified directory, and resize images to a defined width for efficient storage and usage.

Instructions

Capture a screenshot from iOS Simulator

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
device_idNoSpecify a simulator device (if not specified, the booted device will be used)
max_widthNoMaximum width for resizing (pixels)
output_directory_nameNoSubdirectory name for screenshots (if not specified, .screenshots will be used).screenshots
output_filenameNoOutput filename (if not specified, timestamp.png will be used)
resizeNoWhether to resize the image to approximately VGA size

Implementation Reference

  • Core handler function that executes the 'get_screenshot' tool logic: validates device, captures screenshot using xcrun simctl, saves to file, resizes, extracts metadata.
    public async captureScreenshot(options: ScreenshotOptions = {}): Promise<ScreenshotResult> { try { // Prepare file paths const { outputPath } = this.prepareFilePaths(options); // Validate device ID (only if specified) if (options.deviceId && options.deviceId !== 'booted') { const isValid = await this.deviceValidator.isValidDeviceId(options.deviceId); if (!isValid) { throw new Error(`Invalid device ID: ${options.deviceId}. Please use a valid device ID or 'booted'.`); } } // Capture screenshot from simulator const imageBuffer = await this.captureSimulatorScreenshot(options.deviceId); // Save the image await fs.writeFile(outputPath, imageBuffer); // Process the image (resize if needed) const finalPath = options.resize !== false ? await this.resizeImage(outputPath, options.maxWidth || config.screenshot.defaultMaxWidth) : outputPath; // Get image metadata const metadata = await this.getImageMetadata(finalPath); // Get command line arguments const outputDir = this.outputManager.isUsingRootDirectoryDirectly() ? this.outputManager.getRootDirectory() : undefined; return { success: true, message: 'iOS Simulator screenshot saved successfully', filePath: finalPath, metadata, serverConfig: { commandLineArgs: { outputDir } } }; } catch (error) { return this.createErrorResult(error); } }
  • Tool schema definition including input schema, properties, descriptions, and defaults for the 'get_screenshot' tool.
    private getScreenshotToolDefinition() { return { name: 'get_screenshot', description: 'Capture a screenshot from iOS Simulator', inputSchema: { type: 'object', properties: { output_filename: { type: 'string', description: 'Output filename (if not specified, timestamp.png will be used)' }, output_directory_name: { type: 'string', description: 'Subdirectory name for screenshots (if not specified, .screenshots will be used)', default: config.screenshot.defaultOutputDirName }, resize: { type: 'boolean', description: 'Whether to resize the image to approximately VGA size', default: true }, max_width: { type: 'integer', description: 'Maximum width for resizing (pixels)', default: config.screenshot.defaultMaxWidth }, device_id: { type: 'string', description: 'Specify a simulator device (if not specified, the booted device will be used)' } }, required: [] } }; }
  • src/index.ts:133-135 (registration)
    Registration of the 'get_screenshot' tool in the MCP ListTools request handler.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [this.getScreenshotToolDefinition()] }));
  • src/index.ts:138-147 (registration)
    Registration of the tool call handler that dispatches 'get_screenshot' requests to the implementation.
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => { if (request.params.name === 'get_screenshot') { return await this.handleScreenshotRequest(request); } else { throw new McpError( ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}` ); } });
  • Helper function that maps MCP tool arguments to ScreenshotOptions and calls the core captureScreenshot implementation, formats MCP response.
    private async handleScreenshotRequest(request: any): Promise<any> { try { const args = request.params.arguments as Record<string, unknown> || {}; // Map API parameters to internal options const options: ScreenshotOptions = { outputFileName: args.output_filename as string, outputDirectoryName: args.output_directory_name as string, resize: args.resize as boolean, maxWidth: args.max_width as number, deviceId: args.device_id as string }; // Capture screenshot const result = await this.screenshotService.captureScreenshot(options); // Return formatted response return this.createMcpResponse(result); } catch (error) { const err = error as Error; return this.createMcpResponse({ success: false, message: `Error: ${err.message}`, error: { code: 'UNEXPECTED_ERROR' } }); } }

Other Tools

Related 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/yorifuji/mcp-ios-simulator-screenshot'

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