simulator.screenshot
Capture screenshots from iOS Simulator during React Native/Expo development to document app states, debug UI issues, and create visual records.
Instructions
Take a screenshot of the booted simulator
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | No | Name prefix for the screenshot file. | screenshot |
Implementation Reference
- src/simulator/screenshots.ts:19-65 (handler)Core handler function that takes a screenshot of the booted simulator using simctl, handles errors, manages artifacts, and updates state.export async function takeScreenshot(name: string = "screenshot"): Promise<ScreenshotResult> { logger.info("simulator", `Taking screenshot: ${name}`); // Check if simulator is booted if (!stateManager.isSimulatorReady()) { const bootedDevice = await getBootedDevice(); if (!bootedDevice) { throw createError("SIM_NOT_BOOTED", "No simulator is currently booted", { details: "Boot a simulator first using simulator.boot", }); } stateManager.updateSimulator({ state: "booted", udid: bootedDevice.udid, deviceName: bootedDevice.name, }); } const screenshotPath = await artifactManager.getScreenshotPath(name); // Use 'booted' to target the currently booted simulator const result = await simctl(["io", "booted", "screenshot", screenshotPath], { timeoutMs: 30000, }); if (result.exitCode !== 0) { throw createError("SIMCTL_FAILED", "Failed to take screenshot", { details: result.stderr, evidence: [logger.formatForEvidence("simulator", 50)], }); } const timestamp = new Date().toISOString(); artifactManager.registerArtifact({ type: "screenshot", path: screenshotPath, metadata: { name, captureMethod: "simctl" }, }); logger.info("simulator", `Screenshot saved to ${screenshotPath}`); return { path: screenshotPath, timestamp, }; }
- src/mcp/server.ts:167-187 (registration)MCP server.tool registration for 'simulator.screenshot', providing description, input schema, and thin wrapper handler calling takeScreenshot.server.tool( "simulator.screenshot", "Take a screenshot of the booted simulator", SimulatorScreenshotInputSchema.shape, async (args) => { try { const result = await takeScreenshot(args.name); return { content: [ { type: "text", text: JSON.stringify({ success: true, ...result }, null, 2), }, ], }; } catch (error) { return handleToolError(error); } } );
- src/mcp/schemas.ts:28-30 (schema)Zod input schema defining optional 'name' parameter with default 'screenshot'.export const SimulatorScreenshotInputSchema = z.object({ name: z.string().optional().default("screenshot").describe("Name prefix for the screenshot file."), });
- src/mcp/server.ts:750-752 (helper)Helper usage of takeScreenshot in the toolExecutor switch for flow.run tool.case "simulator.screenshot": const screenshot = await takeScreenshot(input.name as string | undefined); return { success: true, result: screenshot };