|
10 | 10 | * - Opening the Simulator.app application |
11 | 11 | * - Installing applications in simulators |
12 | 12 | * - Launching applications in simulators by bundle ID |
| 13 | + * - Setting the appearance mode of simulators (dark/light) |
13 | 14 | */ |
14 | 15 |
|
15 | 16 | import { z } from 'zod'; |
@@ -495,3 +496,62 @@ export function registerOpenSimulatorTool(server: McpServer): void { |
495 | 496 | }, |
496 | 497 | ); |
497 | 498 | } |
| 499 | + |
| 500 | +export function registerSetSimulatorAppearanceTool(server: McpServer): void { |
| 501 | + server.tool( |
| 502 | + 'set_simulator_appearance', |
| 503 | + 'Sets the appearance mode (dark/light) of an iOS simulator.', |
| 504 | + { |
| 505 | + simulatorUuid: z |
| 506 | + .string() |
| 507 | + .describe('UUID of the simulator to use (obtained from list_simulators)'), |
| 508 | + mode: z |
| 509 | + .enum(['dark', 'light']) |
| 510 | + .describe('The appearance mode to set (either "dark" or "light")'), |
| 511 | + }, |
| 512 | + async (params): Promise<ToolResponse> => { |
| 513 | + const simulatorUuidValidation = validateRequiredParam('simulatorUuid', params.simulatorUuid); |
| 514 | + if (!simulatorUuidValidation.isValid) { |
| 515 | + return simulatorUuidValidation.errorResponse!; |
| 516 | + } |
| 517 | + |
| 518 | + log('info', `Setting simulator ${params.simulatorUuid} appearance to ${params.mode} mode`); |
| 519 | + |
| 520 | + try { |
| 521 | + const command = ['xcrun', 'simctl', 'ui', params.simulatorUuid, 'appearance', params.mode]; |
| 522 | + const result = await executeXcodeCommand(command, 'Set Simulator Appearance'); |
| 523 | + |
| 524 | + if (!result.success) { |
| 525 | + return { |
| 526 | + content: [ |
| 527 | + { |
| 528 | + type: 'text', |
| 529 | + text: `Failed to set simulator appearance: ${result.error}`, |
| 530 | + }, |
| 531 | + ], |
| 532 | + }; |
| 533 | + } |
| 534 | + |
| 535 | + return { |
| 536 | + content: [ |
| 537 | + { |
| 538 | + type: 'text', |
| 539 | + text: `Successfully set simulator ${params.simulatorUuid} to ${params.mode} mode`, |
| 540 | + }, |
| 541 | + ], |
| 542 | + }; |
| 543 | + } catch (error) { |
| 544 | + const errorMessage = error instanceof Error ? error.message : String(error); |
| 545 | + log('error', `Error setting simulator appearance: ${errorMessage}`); |
| 546 | + return { |
| 547 | + content: [ |
| 548 | + { |
| 549 | + type: 'text', |
| 550 | + text: `Failed to set simulator appearance: ${errorMessage}`, |
| 551 | + }, |
| 552 | + ], |
| 553 | + }; |
| 554 | + } |
| 555 | + }, |
| 556 | + ); |
| 557 | +} |
0 commit comments