mobile_type_keys
Type text into focused elements on mobile devices for automation testing. Specify device identifier, text content, and submission option to simulate user input in iOS and Android applications.
Instructions
Type text into the focused element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| device | Yes | The device identifier to use. Use mobile_list_available_devices to find which devices are available to you. | |
| text | Yes | The text to type | |
| submit | Yes | Whether to submit the text. If true, the text will be submitted as if the user pressed the enter key. |
Implementation Reference
- src/server.ts:365-382 (registration)Registration of the 'mobile_type_keys' tool, including inline schema definition and handler function that uses the selected robot to send keys and optionally press ENTER.tool( "mobile_type_keys", "Type text into the focused element", { text: z.string().describe("The text to type"), submit: z.boolean().describe("Whether to submit the text. If true, the text will be submitted as if the user pressed the enter key."), }, async ({ text, submit }) => { requireRobot(); await robot!.sendKeys(text); if (submit) { await robot!.pressButton("ENTER"); } return `Typed text: ${text}`; } );
- src/server.ts:372-381 (handler)Handler implementation for 'mobile_type_keys': requires a selected robot, sends the provided text via robot.sendKeys(), and if submit is true, presses the ENTER button.async ({ text, submit }) => { requireRobot(); await robot!.sendKeys(text); if (submit) { await robot!.pressButton("ENTER"); } return `Typed text: ${text}`; }
- src/server.ts:369-370 (schema)Zod schema for 'mobile_type_keys' tool parameters: text (required string), submit (boolean).text: z.string().describe("The text to type"), submit: z.boolean().describe("Whether to submit the text. If true, the text will be submitted as if the user pressed the enter key."),
- src/server.ts:52-77 (helper)Helper function 'tool()' used to register all tools, including error handling wrapper around the provided callback.const tool = (name: string, description: string, paramsSchema: ZodRawShape, cb: (args: z.objectOutputType<ZodRawShape, ZodTypeAny>) => Promise<string>) => { const wrappedCb = async (args: ZodRawShape): Promise<CallToolResult> => { try { trace(`Invoking ${name} with args: ${JSON.stringify(args)}`); const response = await cb(args); trace(`=> ${response}`); return { content: [{ type: "text", text: response }], }; } catch (error: any) { if (error instanceof ActionableError) { return { content: [{ type: "text", text: `${error.message}. Please fix the issue and try again.` }], }; } else { // a real exception trace(`Tool '${description}' failed: ${error.message} stack: ${error.stack}`); return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true, }; } } }; server.tool(name, description, paramsSchema, args => wrappedCb(args));