Skip to main content
Glama

droidpilot

An MCP server for driving an Android emulator from an LLM agent, built to be fast and to not mislead the agent about what is on screen.

  • UI tree from uiautomator2 (on-device server, ~30 ms per dump), compressed into a short numbered element list (~20x smaller than the raw XML).

  • Frames and touch through the Android Emulator's own gRPC endpoint: a 108 px frame in ~2 ms, a 540 px screenshot in ~8 ms, and multi-touch gestures (pinch, drag).

  • Waits like a person: every action waits until the screen has responded and stopped changing (and until page-load bars are gone), then returns the new element list. One round trip per step.

Real devices work too (everything falls back to uiautomator2); the gRPC fast paths are emulator-only.

Setup

git clone https://github.com/WaziXuan/droidpilot && cd droidpilot
python -m venv .venv && .venv/bin/pip install -e .      # Windows: .venv\Scripts\pip install -e .

Start the emulator with the gRPC endpoint enabled:

emulator -avd <your_avd> -grpc 8554

Register the server with your MCP client, e.g. Claude Code:

claude mcp add droidpilot -- /path/to/droidpilot/.venv/bin/python -m droidpilot

Options (flags or environment variables):

Flag

Env

Default

--serial

DROIDPILOT_SERIAL

only connected device

adb serial

--grpc

DROIDPILOT_GRPC

127.0.0.1:8554; off when --serial is a real device

emulator gRPC address, '' to disable

--min-interval-ms

DROIDPILOT_MIN_INTERVAL_MS

300

minimum gap between actions

--transport / --port

stdio / 8765

streamable-http keeps one server (and its handles) alive across clients

--agent

DROIDPILOT_AGENT

off

host[:port] of the on-phone agent; replaces adb (see below)

Wireless, reboot-proof: the on-phone agent

adb over TCP is lost on every reboot, and on Android 10 and older only a USB cable turns it back on. agent/ is a small app (no dependencies, built with the plain SDK tools) that runs as an accessibility service: Android restarts it by itself after a reboot, so a phone left somewhere stays drivable with nobody next to it. It serves the UI tree (in uiautomator's format, so the parser is shared), screenshots (MediaProjection), gestures, text entry and app launching over HTTP on port 8790, protected by a token only processes on the phone can read.

python scripts/build_agent.py                                  # -> agent/build/droidpilot-agent.apk
python scripts/setup_agent.py --serial SERIAL --check PHONE_IP # once, over USB: install, enable, grant, save token
python -m droidpilot --agent PHONE_IP --transport streamable-http --port 8766

PHONE_IP is any address the PC can reach, e.g. the phone's Tailscale IP. The token is saved to ~/.droidpilot/agent_token (or set DROIDPILOT_AGENT_TOKEN). Keep agent/build/agent.keystore: updates signed with another key must uninstall first.

Requirements and limits: no PIN/pattern lock (Android starts no apps after a reboot until the first unlock; a swipe lock is passed automatically). Without adb there is no force-stop (app_stop goes home and kills the background app) and keys are limited to home, back, recents, notifications, power, wakeup, sleep and delete; press_key enter still works by tapping the keyboard's action key. If Tailscale's split tunneling excludes an app (say Termux, so its traffic keeps using the local connection), that app can't answer connections over the tailnet. The agent stays inside the VPN and can forward for it, accepting only on the Tailscale address; forwards are saved and come back after a reboot:

curl -H "X-Token: $TOKEN" -d '{"listen":8023,"target":8022}' http://PHONE_IP:8790/forwards  # tailnet :8023 -> 127.0.0.1:8022
curl -H "X-Token: $TOKEN" -d '{"listen":8023,"remove":true}' http://PHONE_IP:8790/forwards

Measured on an Xperia XZ1 Compact (Android 9) over Tailscale: observe ≈0.13 s, 540 px screenshot ≈0.1 s; back up about a minute after adb reboot.

Related MCP server: android-agent-mcp

What the agent sees

package: com.android.settings  elements: 12  keyboard: shown (covers y>=1517)
[e1] ImageButton "Back" @(63,219) 126x147 click
[e2] EditText "dark" #open_search_view_edit_text @(529,220) 807x126 click,long,edit,focused
[e5] LinearLayout "Dark theme | Display" @(540,414) 1080x214 click
[e6] Switch #switch_widget @(944,414) 188x214 click,unchecked
[e11] LinearLayout "Bedtime mode" @(540,1549) 1080x214 click,under-keyboard
[e12] Key "Search" @(994,2196) 161x156 click,ime-action

[handle] Class "label" #resource-id @(center) WxH flags. Handles are valid for the latest list only. The list leaves out status-bar icons, keyboard keys (except the action key), items scrolled under a toolbar or out of their container, slivers too thin to tap, page-sized click targets, and wrappers that repeat their child. The header adds loading while a spinner or page-load bar is visible.

Tools

Tool

observe(screenshot=False)

element list, optionally with a screenshot

screenshot(width=540)

JPEG of the screen

tap(target) / long_press(target)

target is a handle (e7) or x,y device pixels

tap_text(text, exact=False)

tap the best element whose label matches

swipe(start, end, duration_ms, hold_ms)

hold_ms > 0 makes it a drag

scroll(direction, target, distance=0.6, fling=False)

pages overlap by default

pinch(zoom, target)

two-finger zoom in/out (gRPC)

type_text(text, clear=False)

into the focused field; any Unicode

press_key(key)

back, home, recent, ...; enter taps the keyboard's action key

rotate(orientation)

portrait / landscape / reverse_*, by turning the device

wait_for(text, resource_id) / wait_idle()

wait for an element / for loading to finish

app_launch, app_stop, app_current, app_list

app management

status()

backends in use

Action tools return the settled element list (observe_after=True), with how long settling took.

Design notes

Measured on an x86_64 Android 14 emulator (software rendering) on a Ryzen 7 7800X3D:

Operation

Median

gRPC frame, 540 px wide

8 ms

gRPC frame, full size

32 ms

uiautomator2 hierarchy dump

30 ms

adb exec-out uiautomator dump

136 ms

adb exec-out screencap

238 ms

type_text (accessibility set-text)

~300 ms

uiautomator2 send_keys (clipboard paste)

~2.8 s

uiautomator2 app_current() vs dumpsys

5.1 s vs 35 ms

  • Settling. Dumping the hierarchy blocks while an app animates (~0.5 s per dump mid-transition), so settling polls tiny frames and dumps once at the end. A tap's ripple happens inside the tapped element and is not the response: a cold-started screen can sit still for ~0.4 s between ripple and transition, so only changes outside the touched element count. Settling continues while a progress bar is indeterminate or advancing (browser page loads), and stops for static gauges.

  • Typing uses the accessibility set-text action: no clipboard (which raises the Android 13+ clipboard overlay), no switching the user's input method, and the app's text watchers still fire.

  • Submitting. Search boxes often ignore KEYCODE_ENTER; press_key enter taps the keyboard's action key, found in the keyboard's accessibility tree. KEYCODE_SEARCH is not used: it opens the Google app.

  • Scrolling pauses the finger before lifting so lists move by the requested distance instead of flinging past items.

  • Rotation. uiautomator reports coordinates for the current display rotation. On the emulator, touch events always use natural (unrotated) coordinates, while gRPC frames come in the orientation of the emulator's body, i.e. its window. Frames are turned by (display − body) quarter turns, which matched uiautomator2's own screenshots in all nine combinations tried, and touch points are mapped to natural coordinates. The rotation comes from each hierarchy dump at no extra cost.

  • The window stays upright for whoever is watching. When the display rotates without the body (an app locking landscape, or a forced rotation setting), the content would show sideways in the emulator window. droidpilot then turns the emulator's body to match, as a person turns the phone to watch a landscape video. rotate likewise turns the body instead of forcing a system setting; if the app refuses the new orientation, the body is turned back. Disable with --no-follow-rotation.

  • Loading bars are waited out for at most 2 s once the picture is still (pages often keep a bar up for a resource that never arrives); the element list still says loading, and wait_idle waits for as long as you allow.

  • Pacing. A minimum gap between actions (300 ms) keeps taps from landing on half-drawn screens.

Limitations

  • Content without accessibility information (games, canvas, some WebViews) needs screenshot.

  • The gRPC endpoint is unauthenticated on localhost; don't expose it.

Development

pip install -e .[dev]
pytest                                         # offline tests for the element list
python scripts/bench.py                        # latency of each backend
python scripts/settle_trace.py "540,1355"      # frame-by-frame response to a tap
python scripts/mcp_call.py observe             # call tools like an MCP client
python scripts/gen_proto.py                    # regenerate gRPC stubs from proto/

License

MIT. proto/droidpilot/_proto/emulator_controller.proto and the generated stubs come from the Android Emulator and are Apache-2.0; see LICENSE.

Available Tools

18 tools
app_currentC

Foreground package and activity.

Inputs: no named parameters.

app_launchB

Launch an app by package name (see app_list).

Inputs: package (required), max_wait_ms, observe_after. Returns: result

app_listC

Installed packages, optionally filtered by substring.

Inputs: contains. Returns: result

app_stopC

Force-stop an app.

Inputs: package (required). Returns: result

long_pressC

Press and hold an element handle or "x,y".

Inputs: target (required), hold_ms, max_wait_ms, observe_after. Returns: result

observeB

List interactive and labelled elements on screen with handles. Optionally attach a screenshot.

Inputs: width, screenshot.

pinchA

Two-finger pinch: zoom "in" or "out", centred on a handle/"x,y" or the screen centre. Emulator gRPC only.

Inputs: zoom (required), target, max_wait_ms, observe_after. Returns: result

press_keyB

Press a key: back, home, recent, delete, tab, volume_up, volume_down, power, or any KEYCODE_ name. "enter" (also "search"/"go"/"send"/"done") presses the on-screen keyboard's action key when the keyboard is shown, which is what submits most search boxes and chat inputs.

Inputs: key (required), max_wait_ms, observe_after. Returns: result

rotateA

Turn the device to "portrait", "landscape", "reverse_portrait" or "reverse_landscape", like a person turning the phone. The display only follows if auto-rotate is on and the app allows it; check the orientation in the returned header.

Inputs: orientation (required), max_wait_ms, observe_after. Returns: result

screenshotA

Current screen as JPEG, scaled to width px wide (the device is usually 1080 wide; scale coordinates back).

Inputs: width.

scrollA

Scroll "down" (reveal content below), "up", "left" or "right", within a scrollable handle or the whole screen, by about distance of its height/width so consecutive pages overlap. fling=True lets the list coast further (faster for long lists, but items can be skipped).

Inputs: direction (required), fling, target, distance, +3 more. Returns: result

statusC

Which backends are in use, screen size and pacing.

Inputs: no named parameters.

swipeC

Swipe from start to end (handles or "x,y"). Set hold_ms > 0 to press first, i.e. drag.

Inputs: end (required), start (required), hold_ms, duration_ms, +2 more. Returns: result

tapC

Tap an element handle ("e7") or device coordinates ("540,1200").

Inputs: target (required), max_wait_ms, observe_after. Returns: result

tap_textC

Tap the first element whose text (or content description) contains text.

Inputs: text (required), exact, max_wait_ms, observe_after. Returns: result

type_textB

Type into the focused field (tap the field first). Unicode is fine. clear=True replaces existing text.

Inputs: text (required), clear, max_wait_ms, observe_after. Returns: result

wait_forC

Wait until an element whose label (text or content description) contains text, and/or with resource id resource_id, appears.

Inputs: text, timeout, resource_id, observe_after. Returns: result

wait_idleA

Wait until the screen stops changing and nothing is loading (use when the element list says loading, e.g. a web page still coming in), then return the element list.

Inputs: max_wait_ms. Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.2/5.0

    Scored across 18 tools

    Disambiguation4/5

    Each tool has a distinct action: observation (screenshot/observe), input (type_text, press_key), gestures (tap, tap_text, long_press, swipe, scroll, pinch), waiting, and app lifecycle. Minor overlap exists between screenshot and observe (which can attach a screenshot) and between swipe and scroll, but descriptions clearly delineate when to use each.

    Naming Consistency4/5

    Names are uniformly lowercase snake_case with an `app_` prefix grouping the package-management tools and verb_noun forms like type_text, press_key, wait_for, long_press. A handful of bare single-word names (screenshot, observe, tap, status) deviate from the verb_noun pattern but remain unambiguous.

    Tool Count4/5

    18 tools is slightly on the heavy side but each maps to a needed mobile-automation primitive (perception, gesture input, waiting, app control, device state). No tool appears redundant enough to drop outright.

    Completeness4/5

    Core lifecycle is well covered: observe/screenshot for perception, tap/type/swipe/pinch/press_key for interaction, wait_for/wait_idle for synchronization, and app_launch/stop/current/list for app management. Gaps exist around clipboard/paste, deep-link or URL opening, and notification/shell access, but agents can work around most of these via existing tools.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      B
      quality
      D
      maintenance
      Enables AI agents to interact with Android devices through visual UI element detection and automated interactions. Provides comprehensive Android automation capabilities including touch gestures, text input, screenshots, and video recording via uiautomator2.
      12
      4
      -
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI agents to operate a real Android phone through its accessibility service, exposing screen trees with stable refs, taps, typing, gestures, notifications, apps, and other device controls.
      5
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables AI agents to see and drive a real Android phone over plain ADB: screenshots and numbered UI trees, gestures, typing with accents and emoji, SMS/RCS reading and prepared replies, notifications, files, and settings, with no root and no app installed on the phone. Safeguards mask security codes and require explicit confirmation before sending, paying, deleting or confirming anything.
      18
      3
      MIT