diff --git a/README.md b/README.md index fd15fc6..e47fc59 100644 --- a/README.md +++ b/README.md @@ -19,12 +19,10 @@ List all connected Android devices with their IDs and status. ### `adb_screenshot(device_id?, local_filename?)` Take a screenshot and save it locally. -### `adb_input(action, device_id?)` -Send input events: -- `tap`: Tap at coordinates (x, y) -- `swipe`: Swipe from (x, y) to (x2, y2) -- `key`: Send key event (key_code) -- `text`: Type text +### `adb_input(action_type, ...parameters, device_id?)` +Send input events (key and text actions work reliably): +- `key`: Send key event - `adb_input(action_type="key", key_code="KEYCODE_BACK")` +- `text`: Type text - `adb_input(action_type="text", text="hello")` ### `adb_launch_app(package_name, device_id?)` Launch an app by package name. @@ -35,8 +33,14 @@ Open URL in default browser. ### `adb_list_packages(device_id?, filter_text?)` List installed packages, optionally filtered. -### `adb_shell_command(command, device_id?)` -Execute shell command on device. +### `adb_shell_command(command, device_id?)` - **RECOMMENDED for tap/swipe** +Execute shell commands including reliable input simulation: +- **Tap**: `adb_shell_command(command="input tap 400 600")` +- **Swipe**: `adb_shell_command(command="input swipe 100 200 300 400")` +- **Scroll down**: `adb_shell_command(command="input swipe 500 800 500 300")` +- **Key press**: `adb_shell_command(command="input keyevent KEYCODE_BACK")` +- **Type text**: `adb_shell_command(command="input text \"hello world\"")` +- Other commands: `ls /sdcard`, `pm list packages | grep chrome` ## Usage diff --git a/src/server.py b/src/server.py index 9808b2f..e79fc61 100644 --- a/src/server.py +++ b/src/server.py @@ -296,17 +296,44 @@ async def adb_list_packages( @mcp.tool() async def adb_shell_command( - command: str = Field(description="Shell command to execute (e.g., 'ls /sdcard', 'getprop ro.build.version.release')"), + command: str = Field( + description="Shell command to execute. Common input commands: 'input tap X Y' for tapping, 'input swipe X1 Y1 X2 Y2' for swiping, 'input keyevent KEYCODE' for keys, 'input text \"hello\"' for typing", + json_schema_extra={ + "examples": [ + "input tap 400 600", + "input swipe 100 200 300 400", + "input keyevent KEYCODE_BACK", + "input text \"hello world\"", + "ls /sdcard", + "getprop ro.build.version.release", + "pm list packages | grep chrome" + ] + } + ), device_id: Optional[str] = Field(None, description="Target device ID (if multiple devices connected)") ) -> Dict[str, Any]: """ - Execute arbitrary shell commands on the Android device. + Execute shell commands on Android device, including input simulation. - Runs commands in the Android shell environment. Use with caution as this - provides direct access to the device's command line interface. + This is the most reliable way to perform input actions on Android devices. + Runs commands in the Android shell environment with full access to input system. + + Common Input Commands: + - Tap: adb_shell_command(command="input tap 400 600") + - Swipe: adb_shell_command(command="input swipe 100 200 300 400") + - Key press: adb_shell_command(command="input keyevent KEYCODE_BACK") + - Type text: adb_shell_command(command="input text \"hello world\"") + - Scroll down: adb_shell_command(command="input swipe 500 800 500 300") + - Scroll up: adb_shell_command(command="input swipe 500 300 500 800") + + Other Useful Commands: + - List files: adb_shell_command(command="ls /sdcard") + - Get device info: adb_shell_command(command="getprop ro.build.version.release") + - Find packages: adb_shell_command(command="pm list packages | grep chrome") + - Screen brightness: adb_shell_command(command="settings get system screen_brightness") Args: - command: Shell command string to execute + command: Shell command string to execute (see examples above) device_id: Specific device to target (optional if only one device) Returns: