android_input_text
Input text into focused fields on Android devices using ADB commands. This tool enables automated text entry for testing or automation workflows.
Instructions
Input text into the currently focused field on the Android device via ADB
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | Text to input. Spaces will be automatically handled. | |
| deviceSerial | No | Specific device serial number to target (optional) |
Implementation Reference
- src/index.ts:416-433 (registration)Registration of the 'android_input_text' tool including name, description, and input schema definition.{ name: 'android_input_text', description: 'Input text into the currently focused field on the Android device via ADB', inputSchema: { type: 'object', properties: { text: { type: 'string', description: 'Text to input. Spaces will be automatically handled.', }, deviceSerial: { type: 'string', description: 'Specific device serial number to target (optional)', }, }, required: ['text'], }, },
- src/index.ts:504-505 (registration)Dispatch case in the MCP tool handler switch statement that routes 'android_input_text' calls to the handleInputText function.case 'android_input_text': return await handleInputText(this.adb, args as any);
- src/handlers.ts:701-717 (handler)Main handler function for the 'android_input_text' tool. Extracts arguments, calls the ADB wrapper's inputText method, and returns a success response.export async function handleInputText(adb: ADBWrapper, args: InputTextArgs): Promise<{ content: Array<{ type: string; text: string }> }> { const { text, deviceSerial } = args; try { await adb.inputText(text, deviceSerial); return { content: [ { type: 'text', text: `Text input sent: "${text}"`, }, ], }; } catch (error) { throw new Error(`Failed to input text: ${error instanceof Error ? error.message : String(error)}`); } }
- src/handlers.ts:696-699 (schema)TypeScript interface defining the input arguments for the android_input_text handler.interface InputTextArgs { text: string; deviceSerial?: string; }
- src/adb-wrapper.ts:406-411 (helper)Core implementation in ADB wrapper that executes the 'adb shell input text' command with space escaping (%s), performing the actual text input on the Android device.async inputText(text: string, deviceSerial?: string): Promise<void> { const device = await this.getTargetDevice(deviceSerial); // Escape spaces and special characters const escapedText = text.replace(/ /g, '%s'); await this.exec(['shell', 'input', 'text', escapedText], device); }