set_sim_appearance
Set the appearance mode (dark or light) of an iOS simulator using its UUID. Manage simulator visuals with ease for testing and development purposes.
Instructions
Sets the appearance mode (dark/light) of an iOS simulator.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mode | Yes | The appearance mode to set (either "dark" or "light") | |
| simulatorUuid | Yes | UUID of the simulator to use (obtained from list_simulators) |
Implementation Reference
- The core handler function `set_sim_appearanceLogic` that logs the operation and calls the helper to execute the `xcrun simctl ui <simulatorId> appearance <mode>` command.export async function set_sim_appearanceLogic( params: SetSimAppearanceParams, executor: CommandExecutor, ): Promise<ToolResponse> { log('info', `Setting simulator ${params.simulatorId} appearance to ${params.mode} mode`); return executeSimctlCommandAndRespond( params, ['ui', params.simulatorId, 'appearance', params.mode], 'Set Simulator Appearance', `Successfully set simulator ${params.simulatorId} appearance to ${params.mode} mode`, 'Failed to set simulator appearance', 'set simulator appearance', undefined, executor, ); }
- Zod schema defining the input parameters: simulatorId (UUID) and mode (dark or light).const setSimAppearanceSchema = z.object({ simulatorId: z .string() .uuid() .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")'), });
- Registers the tool with name 'set_sim_appearance', its description, public schema (omitting simulatorId), and a session-aware handler wrapping the logic function.export default { name: 'set_sim_appearance', description: 'Sets the appearance mode (dark/light) of an iOS simulator.', schema: publicSchemaObject.shape, // MCP SDK compatibility handler: createSessionAwareTool<SetSimAppearanceParams>({ internalSchema: setSimAppearanceSchema as unknown as z.ZodType<SetSimAppearanceParams>, logicFunction: set_sim_appearanceLogic, getExecutor: getDefaultCommandExecutor, requirements: [{ allOf: ['simulatorId'], message: 'simulatorId is required' }], }), };
- Helper utility to execute simctl commands via xcrun, handle success/error responses, logging, and return standardized ToolResponse.async function executeSimctlCommandAndRespond( params: SetSimAppearanceParams, simctlSubCommand: string[], operationDescriptionForXcodeCommand: string, successMessage: string, failureMessagePrefix: string, operationLogContext: string, extraValidation?: () => ToolResponse | undefined, executor: CommandExecutor = getDefaultCommandExecutor(), ): Promise<ToolResponse> { if (extraValidation) { const validationResult = extraValidation(); if (validationResult) { return validationResult; } } try { const command = ['xcrun', 'simctl', ...simctlSubCommand]; const result = await executor(command, operationDescriptionForXcodeCommand, true, undefined); if (!result.success) { const fullFailureMessage = `${failureMessagePrefix}: ${result.error}`; log( 'error', `${fullFailureMessage} (operation: ${operationLogContext}, simulator: ${params.simulatorId})`, ); return { content: [{ type: 'text', text: fullFailureMessage }], }; } log( 'info', `${successMessage} (operation: ${operationLogContext}, simulator: ${params.simulatorId})`, ); return { content: [{ type: 'text', text: successMessage }], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); const fullFailureMessage = `${failureMessagePrefix}: ${errorMessage}`; log( 'error', `Error during ${operationLogContext} for simulator ${params.simulatorId}: ${errorMessage}`, ); return { content: [{ type: 'text', text: fullFailureMessage }], }; } }