Skip to main content
Glama

shutdown_simulator

Shut down iOS, macOS, or other Apple platform simulators by device ID or name to manage Xcode development resources and optimize workflow efficiency.

Instructions

Shutdown a simulator

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
deviceIdYesDevice UDID or name of the simulator to shutdown

Implementation Reference

  • The execute method implements the core handler logic for the 'shutdown_simulator' MCP tool, handling input validation, use case execution, error handling, and response formatting.
    async 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}`
          }]
        };
      }
    }
  • Defines the input schema for the shutdown_simulator tool, requiring a 'deviceId' string parameter.
    get 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)
    The ShutdownSimulatorController is instantiated via its factory during tool registration in the main server setup.
    ShutdownSimulatorControllerFactory.create(),
  • The use case execute method contains the business logic for shutting down a simulator, including locator, state checks, and control operations.
    async 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 ShutdownSimulatorController, including adapters, use case, and decorators.
    static 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;
    }

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/Stefan-Nitu/mcp-xcode'

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