simulator.shutdown
Shut down an iOS simulator device to free system resources or prepare for development environment changes. Specify a device name or UDID, or use the currently booted device.
Instructions
Shut down an iOS simulator device
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| device | No | Device name or UDID. If not specified, shuts down the booted device. |
Implementation Reference
- src/simulator/devices.ts:138-164 (handler)Core handler function shutdownDevice that locates the simulator device, checks its state, calls simctl to shutdown, handles errors, and updates the global state manager.export async function shutdownDevice(nameOrUdid: string): Promise<void> { logger.info("simulator", `Shutting down simulator: ${nameOrUdid}`); const device = await findDevice(nameOrUdid); if (!device) { throw createError("SIM_NOT_FOUND", `Simulator not found: ${nameOrUdid}`, { details: "Use simulator.list_devices to see available simulators", }); } if (device.state === "Shutdown") { logger.info("simulator", `Device ${device.name} is already shut down`); stateManager.updateSimulator({ state: "shutdown" }); return; } const result = await simctl(["shutdown", device.udid]); if (result.exitCode !== 0) { const { code, message } = parseSimctlError(result.stderr); throw createError(code, message, { details: result.stderr }); } stateManager.updateSimulator({ state: "shutdown", udid: undefined, deviceName: undefined }); logger.info("simulator", `Device ${device.name} shut down successfully`); }
- src/mcp/schemas.ts:20-22 (schema)Zod schema defining the input for simulator.shutdown tool: optional 'device' string parameter.export const SimulatorShutdownInputSchema = z.object({ device: z.string().optional().describe("Device name or UDID. If not specified, shuts down the booted device."), });
- src/mcp/server.ts:114-144 (registration)MCP server.tool registration for 'simulator.shutdown', providing description, input schema, and async handler wrapper that determines device (from args, state, or booted), calls shutdownDevice, and formats MCP response.server.tool( "simulator.shutdown", "Shut down an iOS simulator device", SimulatorShutdownInputSchema.shape, async (args) => { try { const device = args.device ?? stateManager.getSimulator().udid; if (!device) { const booted = await getBootedDevice(); if (!booted) { return { content: [{ type: "text", text: JSON.stringify({ success: true, message: "No simulator is running" }) }], }; } await shutdownDevice(booted.udid); } else { await shutdownDevice(device); } return { content: [ { type: "text", text: JSON.stringify({ success: true, state: stateManager.getSimulator() }, null, 2), }, ], }; } catch (error) { return handleToolError(error); } } );