Skip to content

Commit 44234ee

Browse files
rebornixcameroncooke
authored andcommitted
Support setting appearance
1 parent f51f856 commit 44234ee

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
registerInstallAppInSimulatorTool,
6060
registerLaunchAppInSimulatorTool,
6161
registerLaunchAppWithLogsInSimulatorTool,
62+
registerSetSimulatorAppearanceTool,
6263
} from './tools/simulator.js';
6364

6465
// Import bundle ID tools
@@ -134,6 +135,7 @@ async function main(): Promise<void> {
134135
// Register Simulator management tools
135136
registerBootSimulatorTool(server);
136137
registerOpenSimulatorTool(server);
138+
registerSetSimulatorAppearanceTool(server);
137139

138140
// Register App installation and launch tools
139141
registerInstallAppInSimulatorTool(server);

src/tools/simulator.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* - Opening the Simulator.app application
1111
* - Installing applications in simulators
1212
* - Launching applications in simulators by bundle ID
13+
* - Setting the appearance mode of simulators (dark/light)
1314
*/
1415

1516
import { z } from 'zod';
@@ -495,3 +496,62 @@ export function registerOpenSimulatorTool(server: McpServer): void {
495496
},
496497
);
497498
}
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

Comments
 (0)