adb_swipe
Perform screen swipes on Android devices by specifying start and end coordinates, enabling automated touch gestures for testing and control.
Instructions
Swipe from one point to another on the device screen
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| x1 | Yes | Start X coordinate | |
| y1 | Yes | Start Y coordinate | |
| x2 | Yes | End X coordinate | |
| y2 | Yes | End Y coordinate | |
| duration | No | Swipe duration in milliseconds (default: 300) | |
| deviceId | No | Device ID (optional) |
Implementation Reference
- src/tools/screen.ts:139-188 (handler)The core handler function for the adb_swipe tool. It validates inputs, checks device connection, and executes the ADB shell 'input swipe' command.async swipe(options: SwipeOptions) { try { const { x1, y1, x2, y2, deviceId, duration = 300 } = options; if (x1 < 0 || y1 < 0 || x2 < 0 || y2 < 0) { return { success: false, error: 'Invalid coordinates', message: 'All coordinates must be positive numbers' }; } const connected = await this.adbClient.isDeviceConnected(deviceId); if (!connected) { return { success: false, error: 'Device not connected', message: 'Cannot perform swipe - device is not connected' }; } const command = `shell input swipe ${x1} ${y1} ${x2} ${y2} ${duration}`; const result = await this.adbClient.executeCommand(command, deviceId); if (!result.success) { return { success: false, error: result.error, message: 'Failed to perform swipe' }; } return { success: true, data: { from: { x: x1, y: y1 }, to: { x: x2, y: y2 }, duration, deviceId: deviceId || this.adbClient.getDefaultDevice() }, message: `Swiped from (${x1}, ${y1}) to (${x2}, ${y2})` }; } catch (error: any) { return { success: false, error: error.message, message: 'Failed to perform swipe' }; } }
- src/index.ts:131-162 (schema)Input schema definition for the adb_swipe tool, registered in the MCP server.name: 'adb_swipe', description: 'Swipe from one point to another on the device screen', inputSchema: { type: 'object', properties: { x1: { type: 'number', description: 'Start X coordinate', }, y1: { type: 'number', description: 'Start Y coordinate', }, x2: { type: 'number', description: 'End X coordinate', }, y2: { type: 'number', description: 'End Y coordinate', }, duration: { type: 'number', description: 'Swipe duration in milliseconds (default: 300)', }, deviceId: { type: 'string', description: 'Device ID (optional)', }, }, required: ['x1', 'y1', 'x2', 'y2'], },
- src/index.ts:445-446 (registration)Tool registration in the switch statement that delegates to ScreenTools.swipe method.case 'adb_swipe': return await this.handleToolCall(this.screenTools.swipe(args as any));
- src/types/index.ts:22-29 (schema)TypeScript interface defining the SwipeOptions used by the handler.export interface SwipeOptions { deviceId?: string; x1: number; y1: number; x2: number; y2: number; duration?: number; }