input_scroll
Simulate scroll actions on Android devices for automation and testing using natural language commands. Specify direction (up, down, left, right) to control device interactions via ADB.
Instructions
Perform scroll action
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| direction | Yes | Direction to scroll |
Implementation Reference
- src/tools/handlers.ts:207-235 (handler)The main handler function for the 'input_scroll' tool. It takes a direction (up, down, left, right), executes the corresponding ADB swipe command, captures updated UI, and returns a response with status and UI content.input_scroll: async (args: any) => { const { direction } = args as { direction: string }; const scrollCommands = { up: 'adb shell input swipe 500 800 500 400', down: 'adb shell input swipe 500 400 500 800', left: 'adb shell input swipe 800 500 400 500', right: 'adb shell input swipe 400 500 800 500', }; const command = scrollCommands[direction as keyof typeof scrollCommands]; if (!command) { throw new McpError(ErrorCode.InvalidParams, `Invalid direction: ${direction}`); } await executeCommand(command); const uiContent = await captureUIContent(false); return { content: [ { type: 'text', text: `Scroll executed: ${direction}`, }, ...uiContent, ], }; },
- src/tools/definitions.ts:117-131 (schema)The input schema definition for the 'input_scroll' tool, specifying the expected 'direction' parameter with allowed values.{ name: 'input_scroll', description: 'Perform scroll action', inputSchema: { type: 'object', properties: { direction: { type: 'string', enum: ['up', 'down', 'left', 'right'], description: 'Direction to scroll', }, }, required: ['direction'], }, },
- src/index.ts:26-30 (registration)Registers all tool definitions (including 'input_scroll') for the ListTools MCP request.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: toolDefinitions, }; });
- src/index.ts:32-46 (registration)Registers dynamic handler execution for tools (including 'input_scroll') via lookup in toolHandlers object for CallTool MCP request.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { const handler = toolHandlers[name as keyof typeof toolHandlers]; if (!handler) { throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`); } return await handler(args); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); throw new McpError(ErrorCode.InternalError, `Tool execution failed: ${errorMessage}`); } });
- src/tools/handlers.ts:8-46 (helper)Helper function used by input_scroll (and other tools) to capture and format current UI hierarchy after the action.const captureUIContent = async (includeRawXML: boolean = true) => { await executeCommand('adb shell uiautomator dump /sdcard/window_dump.xml'); const xmlContent = await executeCommand('adb shell "cat /sdcard/window_dump.xml"'); try { const processedUI = await parseUIAutomatorXML(xmlContent); const formattedOutput = formatElementsForDisplay(processedUI); const result = [ { type: 'text', text: formattedOutput, }, ]; if (includeRawXML) { result.push({ type: 'text', text: `\n=== RAW XML UI Automator ===\n${xmlContent}`, }); } return result; } catch (error) { const result = [ { type: 'text', text: `Error processing UI dump: ${error}`, }, { type: 'text', text: `\n=== RAW XML DATA ===\n${xmlContent}`, } ]; return result; } };