button
Simulate hardware button presses on iOS simulators, including apple-pay, home, lock, side-button, and siri, via XcodeBuildMCP for precise testing and control.
Instructions
Press hardware button on iOS simulator. Supported buttons: apple-pay, home, lock, side-button, siri
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| buttonType | Yes | ||
| duration | No | ||
| simulatorUuid | Yes |
Implementation Reference
- src/mcp/tools/ui-testing/button.ts:33-74 (handler)The core handler function `buttonLogic` that parses parameters, constructs the AXE command to press the specified hardware button on the iOS simulator, executes it, handles various error types, and returns appropriate responses.export async function buttonLogic( params: ButtonParams, executor: CommandExecutor, axeHelpers: AxeHelpers = { getAxePath, getBundledAxeEnvironment, createAxeNotAvailableResponse, }, ): Promise<ToolResponse> { const toolName = 'button'; const { simulatorId, buttonType, duration } = params; const commandArgs = ['button', buttonType]; if (duration !== undefined) { commandArgs.push('--duration', String(duration)); } log('info', `${LOG_PREFIX}/${toolName}: Starting ${buttonType} button press on ${simulatorId}`); try { await executeAxeCommand(commandArgs, simulatorId, 'button', executor, axeHelpers); log('info', `${LOG_PREFIX}/${toolName}: Success for ${simulatorId}`); return createTextResponse(`Hardware button '${buttonType}' pressed successfully.`); } catch (error) { log('error', `${LOG_PREFIX}/${toolName}: Failed - ${error}`); if (error instanceof DependencyError) { return axeHelpers.createAxeNotAvailableResponse(); } else if (error instanceof AxeError) { return createErrorResponse( `Failed to press button '${buttonType}': ${error.message}`, error.axeOutput, ); } else if (error instanceof SystemError) { return createErrorResponse( `System error executing axe: ${error.message}`, error.originalError?.stack, ); } return createErrorResponse( `An unexpected error occurred: ${error instanceof Error ? error.message : String(error)}`, ); } }
- Zod schema `buttonSchema` validating input parameters: required simulatorId (UUID), buttonType (enum of supported buttons), and optional duration (non-negative number).const buttonSchema = z.object({ simulatorId: z.string().uuid('Invalid Simulator UUID format'), buttonType: z.enum(['apple-pay', 'home', 'lock', 'side-button', 'siri']), duration: z.number().min(0, 'Duration must be non-negative').optional(), });
- src/mcp/tools/ui-testing/button.ts:76-94 (registration)Default export registering the 'button' tool with name, description, public schema (omitting simulatorId), and a session-aware handler wrapping the buttonLogic function.const publicSchemaObject = buttonSchema.omit({ simulatorId: true } as const).strict(); export default { name: 'button', description: 'Press hardware button on iOS simulator. Supported buttons: apple-pay, home, lock, side-button, siri', schema: publicSchemaObject.shape, // MCP SDK compatibility handler: createSessionAwareTool<ButtonParams>({ internalSchema: buttonSchema as unknown as z.ZodType<ButtonParams>, logicFunction: (params: ButtonParams, executor: CommandExecutor) => buttonLogic(params, executor, { getAxePath, getBundledAxeEnvironment, createAxeNotAvailableResponse, }), getExecutor: getDefaultCommandExecutor, requirements: [{ allOf: ['simulatorId'], message: 'simulatorId is required' }], }), };