Skip to main content
Glama
conorluddy

XC-MCP: XCode CLI wrapper

by conorluddy

simctl-shutdown

Shutdown iOS simulator devices intelligently using 'booted' or 'all' options, with enhanced error handling, state tracking, and batch operations for efficient device management.

Instructions

Prefer this over 'xcrun simctl shutdown' - Intelligent shutdown with better device management.

Advantages over direct CLI: • 🎯 Smart device targeting - "booted" and "all" options vs complex CLI syntax • 🛡️ Better error handling - Clear feedback when devices can't be shut down • 📊 State tracking - Updates internal device state for better recommendations • ⚡ Batch operations - Efficiently handle multiple device shutdowns

Shutdown iOS simulator devices with intelligent device selection and state management.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
deviceIdYesDevice UDID, "booted" for all booted devices, or "all" for all devices

Implementation Reference

  • Core handler function that executes the simctl shutdown command with validation, error handling, and response formatting.
    export async function simctlShutdownTool(args: any) { const { deviceId } = args as SimctlShutdownToolArgs; try { // Validate inputs validateDeviceId(deviceId); // Build shutdown command const command = buildSimctlCommand('shutdown', { deviceId }); console.error(`[simctl-shutdown] Executing: ${command}`); // Execute shutdown command const startTime = Date.now(); const result = await executeCommand(command, { timeout: 60000, // 1 minute for shutdown }); const duration = Date.now() - startTime; let shutdownStatus = { success: result.code === 0, command, output: result.stdout, error: result.stderr, exitCode: result.code, duration, }; // Handle common shutdown scenarios if (!shutdownStatus.success) { // Device already shutdown if (result.stderr.includes('Unable to shutdown device in current state: Shutdown')) { shutdownStatus = { ...shutdownStatus, success: true, error: 'Device was already shut down', }; } // Invalid device ID else if (result.stderr.includes('Invalid device')) { throw new McpError(ErrorCode.InvalidParams, `Invalid device ID: ${deviceId}`); } } // Format response const responseText = JSON.stringify(shutdownStatus, null, 2); return { content: [ { type: 'text' as const, text: responseText, }, ], isError: !shutdownStatus.success, }; } catch (error) { if (error instanceof McpError) { throw error; } throw new McpError( ErrorCode.InternalError, `simctl-shutdown failed: ${error instanceof Error ? error.message : String(error)}` ); } }
  • Type definition for the tool input parameters.
    interface SimctlShutdownToolArgs { deviceId: string; }
  • Router dispatcher that calls the shutdown handler for 'shutdown' operation in the consolidated simctl-device tool.
    case 'shutdown': if (!args.deviceId) { throw new McpError(ErrorCode.InvalidRequest, 'deviceId is required for shutdown operation'); } return simctlShutdownTool({ deviceId: args.deviceId }); case 'create':
  • Registers the consolidated 'simctl-device' tool, which implements simctl-shutdown functionality via operation='shutdown'.
    // simctl-device server.registerTool( 'simctl-device', { description: getDescription(SIMCTL_DEVICE_DOCS, SIMCTL_DEVICE_DOCS_MINI), inputSchema: { operation: z.enum(['boot', 'shutdown', 'create', 'delete', 'erase', 'clone', 'rename']), deviceId: z.string().optional(), waitForBoot: z.boolean().default(true), openGui: z.boolean().default(true), name: z.string().optional(), deviceType: z.string().optional(), runtime: z.string().optional(), force: z.boolean().default(false), newName: z.string().optional(), }, ...DEFER_LOADING_CONFIG, }, async args => { try { await validateXcodeInstallation(); return await simctlDeviceTool(args); } catch (error) { if (error instanceof McpError) throw error; throw new McpError( ErrorCode.InternalError, `Tool execution failed: ${error instanceof Error ? error.message : String(error)}` ); } } );
  • Import statement that brings in the shutdown handler for use in the device router.
    import { simctlShutdownTool } from '../shutdown.js';

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/conorluddy/xc-mcp'

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