diff --git a/src/index.ts b/src/index.ts index 9ca6d2f8..3293235f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -59,6 +59,7 @@ import { registerInstallAppInSimulatorTool, registerLaunchAppInSimulatorTool, registerLaunchAppWithLogsInSimulatorTool, + registerSetSimulatorAppearanceTool, } from './tools/simulator.js'; // Import bundle ID tools @@ -134,6 +135,7 @@ async function main(): Promise { // Register Simulator management tools registerBootSimulatorTool(server); registerOpenSimulatorTool(server); + registerSetSimulatorAppearanceTool(server); // Register App installation and launch tools registerInstallAppInSimulatorTool(server); diff --git a/src/tools/simulator.ts b/src/tools/simulator.ts index 8b31a3d8..9ea2fc62 100644 --- a/src/tools/simulator.ts +++ b/src/tools/simulator.ts @@ -10,6 +10,7 @@ * - Opening the Simulator.app application * - Installing applications in simulators * - Launching applications in simulators by bundle ID + * - Setting the appearance mode of simulators (dark/light) */ import { z } from 'zod'; @@ -495,3 +496,62 @@ export function registerOpenSimulatorTool(server: McpServer): void { }, ); } + +export function registerSetSimulatorAppearanceTool(server: McpServer): void { + server.tool( + 'set_simulator_appearance', + 'Sets the appearance mode (dark/light) of an iOS simulator.', + { + simulatorUuid: z + .string() + .describe('UUID of the simulator to use (obtained from list_simulators)'), + mode: z + .enum(['dark', 'light']) + .describe('The appearance mode to set (either "dark" or "light")'), + }, + async (params): Promise => { + const simulatorUuidValidation = validateRequiredParam('simulatorUuid', params.simulatorUuid); + if (!simulatorUuidValidation.isValid) { + return simulatorUuidValidation.errorResponse!; + } + + log('info', `Setting simulator ${params.simulatorUuid} appearance to ${params.mode} mode`); + + try { + const command = ['xcrun', 'simctl', 'ui', params.simulatorUuid, 'appearance', params.mode]; + const result = await executeXcodeCommand(command, 'Set Simulator Appearance'); + + if (!result.success) { + return { + content: [ + { + type: 'text', + text: `Failed to set simulator appearance: ${result.error}`, + }, + ], + }; + } + + return { + content: [ + { + type: 'text', + text: `Successfully set simulator ${params.simulatorUuid} to ${params.mode} mode`, + }, + ], + }; + } catch (error) { + const errorMessage = error instanceof Error ? error.message : String(error); + log('error', `Error setting simulator appearance: ${errorMessage}`); + return { + content: [ + { + type: 'text', + text: `Failed to set simulator appearance: ${errorMessage}`, + }, + ], + }; + } + }, + ); +}