reset_simulator_location
Reset the location of a specified simulator to default using its UUID, simplifying testing workflows in XcodeBuildMCP.
Instructions
Resets the simulator's location to default.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| simulatorUuid | Yes | UUID of the simulator to use (obtained from list_simulators) |
Implementation Reference
- The main handler function that executes the reset simulator location logic by invoking the simctl command to clear the location via a generic executor helper.export async function reset_sim_locationLogic( params: ResetSimulatorLocationParams, executor: CommandExecutor, ): Promise<ToolResponse> { log('info', `Resetting simulator ${params.simulatorId} location`); return executeSimctlCommandAndRespond( params, ['location', params.simulatorId, 'clear'], 'Reset Simulator Location', `Successfully reset simulator ${params.simulatorId} location.`, 'Failed to reset simulator location', 'reset simulator location', executor, ); }
- Zod schema for input validation, requiring a simulatorId UUID.const resetSimulatorLocationSchema = z.object({ simulatorId: z .string() .uuid() .describe('UUID of the simulator to use (obtained from list_simulators)'), });
- Exports the tool object for registration in the MCP server, including name, description, schema, and a session-aware handler wrapping the core logic.export default { name: 'reset_sim_location', description: "Resets the simulator's location to default.", schema: publicSchemaObject.shape, // MCP SDK compatibility handler: createSessionAwareTool<ResetSimulatorLocationParams>({ internalSchema: resetSimulatorLocationSchema as unknown as z.ZodType<ResetSimulatorLocationParams>, logicFunction: reset_sim_locationLogic, getExecutor: getDefaultCommandExecutor, requirements: [{ allOf: ['simulatorId'], message: 'simulatorId is required' }], }), };
- Reusable helper function for executing simctl commands on simulators, handling responses, logging, and errors. Used by the reset location handler.async function executeSimctlCommandAndRespond( params: ResetSimulatorLocationParams, simctlSubCommand: string[], operationDescriptionForXcodeCommand: string, successMessage: string, failureMessagePrefix: string, operationLogContext: string, executor: CommandExecutor, extraValidation?: () => ToolResponse | undefined, ): Promise<ToolResponse> { if (extraValidation) { const validationResult = extraValidation(); if (validationResult) { return validationResult; } } try { const command = ['xcrun', 'simctl', ...simctlSubCommand]; const result = await executor(command, operationDescriptionForXcodeCommand, true, {}); 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 }], }; } }