Skip to main content

MCP server for Android device automation via uiautomator2

Project description

uiautomator2-mcp

MCP (Model Context Protocol) server for Android device automation via uiautomator2.

Enables AI agents (Claude, etc.) to control Android devices — tap, swipe, type text, take screenshots, manage apps, and more.

Prerequisites

  • Python 3.10+
  • uv (recommended) or pip
  • Android device with USB debugging enabled (or an emulator)
  • ADB installed and device visible via adb devices

Quick Start

Claude Code — one command to add & auto-run:

claude mcp add uiautomator2 -- uvx uiautomator2-mcp

That's it. Claude will auto-launch the server when needed.

Claude Desktop

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "uiautomator2": {
      "command": "uvx",
      "args": ["uiautomator2-mcp"]
    }
  }
}

Codex CLI

Option 1 — add via CLI:

codex mcp add uiautomator2 -- uvx uiautomator2-mcp

Option 2 — add to ~/.codex/config.toml (or project .codex/config.toml):

[mcp_servers.uiautomator2]
command = "uvx"
args = ["uiautomator2-mcp"]

Alternative methods

# Using pipx
pipx run uiautomator2-mcp

# Using pip (global install)
pip install uiautomator2-mcp
uiautomator2-mcp

# Using python -m
pip install uiautomator2-mcp
python -m uiautomator2_mcp

# From source
git clone https://github.com/stayer147/uiautomator2mcp.git
cd uiautomator2mcp
pip install -e .
uiautomator2-mcp

Available Tools (45)

Connection

Tool Description
list_devices List devices visible to ADB and whether they are connected in the MCP session
list_avds List configured Android Virtual Devices
start_emulator Start an Android emulator in the background
connect Connect to a device by serial/IP or auto-detect
disconnect Disconnect one connected device from the MCP session
device_info Get device model, screen size, Android version

UI Interaction

Tool Description
tap Tap at screen coordinates
multi_tap Tap the same coordinates multiple times
double_tap Double-tap at coordinates
long_tap Long-press at coordinates
swipe Swipe between two points
drag Drag between two points
input_text Type text into the focused field
press_key Press a device key (home, back, enter, etc.)

Compound Actions

Tool Description
tap_and_wait Tap an element, wait for the next UI state, and return a fresh hierarchy snapshot
tap_sequence Execute a validated sequence of taps, waits, typing, key presses, and swipes

Element Operations

Tool Description
find_element Find element by text, resource ID, class, description, or XPath
tap_element Find and tap an element
double_tap_element Find and double-tap an element by selector or XPath
set_element_text Set text in an input field
element_exists Check if an element exists
wait_element Wait for an element to appear

Screenshots & UI Hierarchy

Tool Description
screenshot Take a screenshot as a saved file or inline JSON/base64 image payload
dump_hierarchy Get XML UI hierarchy or a compact text summary
get_ui_tree Get a richer JSON UI tree with element state for agent analysis

Agent-friendly analysis outputs

  • screenshot(inline=True) returns a JSON object with base64-encoded image data, MIME type, dimensions, and byte size so MCP clients can render the image without opening a filesystem path.
  • screenshot(save_path="/tmp/screen.jpg", quality=70, max_width=1280) keeps the original save-to-disk workflow while allowing resize/compression controls.
  • get_ui_tree() returns a structured JSON array of UI elements with text, resource_id, class_name, content_desc, bounds, clickable, enabled, focused, selected, checked, scrollable, and index.
  • dump_hierarchy(compact=True) remains available as the lightweight one-line-per-element snapshot, while dump_hierarchy(compact=False) still returns raw XML.

App Management

Tool Description
app_start Launch an app
app_stop Force-stop an app
app_install Install an APK
app_uninstall Uninstall an app
app_clear Clear app data
app_info Get app information
app_list_running List running apps
current_app Get current foreground app

Device Control

Tool Description
screen_on Wake up the device
screen_off Turn off the screen
unlock Unlock the device
open_notification Open notification panel
open_quick_settings Open quick settings
get_clipboard Get clipboard content
set_clipboard Set clipboard content

Diagnostics

Tool Description
clear_logs Clear logcat buffers on the device
get_logs Read filtered logcat output by package, level, timestamp, and line count

Shell & Files

Tool Description
shell Run a shell command on the device
push_file Push a file to the device
pull_file Pull a file from the device

Example Workflow

When only one device is connected in the MCP session, tools can omit device_id. If you connect multiple devices, pass device_id explicitly. Multi-device targeting is now supported consistently across the interactive UI, app-management, device-control, watcher, clipboard, and file-transfer tools, in addition to diagnostics tools like clear_logs and get_logs.

  1. List available devices: list_devices()
  2. Connect to one device: connect("emulator-5554")
  3. Optionally connect a second device: connect("emulator-5556")
  4. Inspect a specific device: device_info(device_id="emulator-5554")
  5. Take a screenshot to see the current screen: screenshot(device_id="emulator-5554") or request inline JSON/base64 output with screenshot(inline=True, max_width=1080, device_id="emulator-5554")
  6. Dump hierarchy to understand the lightweight UI structure: dump_hierarchy(device_id="emulator-5554")
  7. Get a richer UI tree when state matters: get_ui_tree(device_id="emulator-5554")
  8. Tap elements by text or resource ID
  9. Double-tap directly via XPath when needed, e.g. double_tap_element(xpath="//android.widget.TextView[@text='Gallery']")
  10. Type text into input fields
  11. Take another screenshot to verify results

Example bug-report workflow

  1. Clear old logs: clear_logs()
  2. Reproduce the bug using the UI interaction tools
  3. Capture error logs: get_logs(level="E", package="com.example.app")
  4. Take a screenshot of the failing state, optionally inline for vision analysis
  5. Dump hierarchy for a lightweight snapshot or get_ui_tree() for richer element state

Example login in one tool call

tap_sequence(
  steps=[
    {"action": "tap_element", "resource_id": "com.example:id/email"},
    {"action": "input_text", "text": "user@example.com"},
    {"action": "tap_element", "resource_id": "com.example:id/password"},
    {"action": "input_text", "text": "correct horse battery staple"},
    {"action": "tap_element", "resource_id": "com.example:id/sign_in"},
    {"action": "wait", "resource_id": "com.example:id/home_feed", "timeout": 15}
  ]
)

Publishing to PyPI

uv build
uv publish

After publishing, uvx uiautomator2-mcp will work out of the box.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uiautomator2_mcp-0.1.1.tar.gz (26.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uiautomator2_mcp-0.1.1-py3-none-any.whl (25.8 kB view details)

Uploaded Python 3

File details

Details for the file uiautomator2_mcp-0.1.1.tar.gz.

File metadata

  • Download URL: uiautomator2_mcp-0.1.1.tar.gz
  • Upload date:
  • Size: 26.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for uiautomator2_mcp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e708b3f9503437920bfea8163f9e22cc0dd8252b276401e5c8ca847a2e9104cb
MD5 1e042a30a2bb8ad90a0248d9a48245a4
BLAKE2b-256 8b9c1f49a497a1835f5d0d782d95cf2690a354fc0b6875813cd98145f3f338c5

See more details on using hashes here.

File details

Details for the file uiautomator2_mcp-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: uiautomator2_mcp-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 25.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for uiautomator2_mcp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d8b3fd0cbe75d9fa2802c30cccd554b46654b7ddfb2e80779041bd15f572858a
MD5 6be36c03826df92e61e3ca34bbf5aecd
BLAKE2b-256 1180be1c274169eb05a0e00ff175e011e21cc6bc7e52ee051402304f14e92370

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page