shutdown_simulator
Shutdown a specified Xcode simulator using its device UDID or name. Integrates with MCP Xcode to manage simulators and streamline Apple platform development workflows.
Instructions
Shutdown a simulator
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| deviceId | Yes | Device UDID or name of the simulator to shutdown |
Implementation Reference
- Handler function that executes the shutdown_simulator MCP tool: parses args, validates, executes use case, handles errors and formats responseasync execute(args: unknown): Promise<{ content: Array<{ type: string; text: string }> }> { try { // Cast to expected shape const input = args as { deviceId: unknown }; // Create domain value object - will validate const deviceId = DeviceId.create(input.deviceId); // Create domain request const request = ShutdownRequest.create(deviceId); // Execute use case const result = await this.useCase.execute(request); // Format response return { content: [{ type: 'text', text: this.formatResult(result) }] }; } catch (error: any) { // Handle validation and other errors consistently const message = ErrorFormatter.format(error); return { content: [{ type: 'text', text: `❌ ${message}` }] }; } }
- Input schema definition for the shutdown_simulator toolget inputSchema() { return { type: 'object' as const, properties: { deviceId: { type: 'string' as const, description: 'Device UDID or name of the simulator to shutdown' } }, required: ['deviceId'] as const }; }
- src/index.ts:83-83 (registration)Creates the ShutdownSimulatorController instance for registration in the tools MapShutdownSimulatorControllerFactory.create(),
- Core use case execution logic: locates simulator, checks state, performs shutdown via adapterasync execute(request: ShutdownRequest): Promise<ShutdownResult> { // Find the simulator const simulator = await this.simulatorLocator.findSimulator(request.deviceId); if (!simulator) { return ShutdownResult.failed( request.deviceId, '', // No name available since simulator wasn't found new SimulatorNotFoundError(request.deviceId) ); } // Check simulator state if (simulator.state === SimulatorState.Shutdown) { return ShutdownResult.alreadyShutdown( simulator.id, simulator.name ); } // Handle ShuttingDown state - simulator is already shutting down if (simulator.state === SimulatorState.ShuttingDown) { return ShutdownResult.alreadyShutdown( simulator.id, simulator.name ); } // Shutdown the simulator (handles Booted and Booting states) try { await this.simulatorControl.shutdown(simulator.id); return ShutdownResult.shutdown( simulator.id, simulator.name ); } catch (error: any) { return ShutdownResult.failed( simulator.id, simulator.name, new ShutdownCommandFailedError(error.stderr || error.message || '') ); } }
- Factory method that wires all dependencies for the ShutdownSimulatorControllerstatic create(): MCPController { // Create the shell executor that all adapters will use const execAsync = promisify(exec); const executor = new ShellCommandExecutorAdapter(execAsync); // Create infrastructure adapters const simulatorLocator = new SimulatorLocatorAdapter(executor); const simulatorControl = new SimulatorControlAdapter(executor); // Create the use case with all dependencies const useCase = new ShutdownSimulatorUseCase( simulatorLocator, simulatorControl ); // Create the controller const controller = new ShutdownSimulatorController(useCase); // Create dependency checker const dependencyChecker = new DependencyChecker(executor); // Wrap with dependency checking decorator const decoratedController = new DependencyCheckingDecorator( controller, ['xcrun'], // simctl is part of xcrun dependencyChecker ); return decoratedController; }