DEV Community

Trung Thanh Tran
Trung Thanh Tran

Posted on

Driving Android Phones Over ADB Without Screenshot Loops or Raw XML Dumps (turbo-android-mcp)

Running an AI agent against an Android phone over adb usually hits two bottlenecks on the first screen. A full 1080x2400 PNG capture via adb exec-out screencap -p takes around 1.5 seconds over USB and costs roughly 1,800 vision tokens per step. Dumping the raw accessibility hierarchy via uiautomator dump avoids vision tokens, but a single Settings or messaging screen produces 35 KB to 80 KB of raw XML (10,000+ tokens) filled with layout wrappers, system bars, and decorative views.

I published turbo-android-mcp v0.1.0 to npm (npx -y turbo-android-mcp), a zero-dependency Node.js MCP server that drives Android phones, tablets, and emulators over standard adb without device root.

GitHub: https://github.com/Tthanh2k6/turbo-android
npm: https://www.npmjs.com/package/turbo-android-mcp

Compact UI trees, query filters, and delta diffs

Instead of feeding raw uiautomator XML to the model, ui_tree strips the status bar, navigation bar, and empty layout containers, then formats interactive or text-bearing nodes into one line per element with center coordinates (cx,cy):

com.android.settings
[1] TextView "Wi-Fi" desc="Wireless network" id=title clickable (200,300)
[2] Switch "Off" id=switch_widget clickable (900,300)
[3] TextView "Searching..." id=status (300,500)
Enter fullscreen mode Exit fullscreen mode

You can pass index, id, or text from ui_tree directly into tap, type_text, and batch_actions without calculating pixel coordinates by hand.

On subsequent steps, passing onlyChanged: true runs a two-pass structural diff against the previous snapshot and returns only added (+), modified (~), and removed (-) nodes:

com.android.settings
~ [2] Switch "On" id=switch_widget clickable (900,300)
+ [3] TextView "HomeNet 5G" id=network_name clickable (350,650)
- [3] TextView "Searching..." id=status (300,500)
-- delta: 1 added, 1 changed, 1 removed, 1 unchanged
Enter fullscreen mode Exit fullscreen mode

When a screen has long lists, ui_tree also accepts a case-insensitive substring query (matching text, content-desc, resource-id, or class name) and a maxChars limit (default 6000, up to 20000). Multi-step flows such as tapping a search bar, typing a query, waiting 200ms, and reading the delta diff run in a single round-trip through batch_actions.

Hiding root tools when running over ADB

The repository supports two transports:

  1. AdbTransport (default on Windows, macOS, and Linux): connects to any Android device over USB or Wireless Debugging without root.
  2. ChrootRootTransport (optional advanced mode): runs inside an on-device Debian arm64 chroot on a rooted tablet.

In standard AdbTransport mode, tools/list exposes only the 12 non-root screen and app tools (ui_tree, screenshot, tap, swipe, key, type_text, open_app, open_settings, list_apps, current_app, wait, batch_actions) and hides the 7 privileged root tools (root_shell, settings_get, settings_put, app_manage, root_file, system_diagnostics, power_saver). Keeping unreachable root tools out of tools/list saves ~1,100 schema tokens per turn and prevents the model from attempting root commands on an unrooted phone.

Three Android quirks that broke early builds

  1. uiautomator dump fails while animations run and drops split-screen panes. Standard uiautomator dump frequently exits with ERROR: could not get idle state if a spinner or transition is active, and it only dumps a single window on tablets running split-screen or two-pane Settings. ui_tree runs uiautomator dump --windows (supported on Android 13+) with automatic retries, then filters the multi-window XML down to windows belonging to the foreground package plus any focused dialog window.
  2. adb shell input text fails on accented Vietnamese and Unicode. Android's built-in input text command only accepts printable ASCII. In turbo-android-mcp, type_text uses input text for plain ASCII and routes Unicode, accented Vietnamese, CJK, and emoji payloads as Base64 broadcasts through TurboImeService, automatically restoring the user's previous keyboard (/data/local/tmp/turbo_prev_ime) in a finally block.
  3. WebViews and mobile browsers return empty trees to uiautomator. When an Android app renders inside Chrome, Brave, or a debuggable WebView, uiautomator often sees a single blank container. The included CDP bridge (daemon/cdp-bridge.mjs) detects @chrome_devtools_remote, @brave_devtools_remote, and @webview_devtools_remote_<pid> sockets and forwards DevTools traffic to 127.0.0.1:9333 so turbo-browser-mcp can attach to the mobile tab.

Hardcoded financial and password deny-zones

Connecting an agent to a personal phone requires strict boundaries enforced in code before any shell command runs:

  • Banking apps, e-wallets (momo, zalopay, vnpay, shopeepay, paypal, vcb, techcombank, mbbank, bidv, vietinbank), VNeID, password managers (1password, bitwarden, keepass, lastpass, dashlane, protonpass), and root managers (KernelSU) are blocked across ui_tree, screenshot, tap, swipe, type_text, open_app, and the CDP bridge.
  • Any node with password="true" has its text masked as "••••" and its content-desc stripped in ui_tree.
  • If a password input is focused or targeted by index/id, type_text rejects the call immediately so credentials must be typed by hand.

Quick start (Node 20+, adb)

Verify your adb binary, connected device serial, and TurboImeService status first:

npx -y turbo-android-mcp --doctor
Enter fullscreen mode Exit fullscreen mode

Add to Claude Code:

claude mcp add turbo-android -- npx -y turbo-android-mcp
Enter fullscreen mode Exit fullscreen mode

Or add to mcpServers in Cursor, Claude Desktop, or Antigravity:

{
  "mcpServers": {
    "turbo-android": {
      "command": "npx",
      "args": ["-y", "turbo-android-mcp"],
      "env": {
        "TURBO_ANDROID_ADB": "adb",
        "TURBO_ANDROID_SERIAL": "",
        "TURBO_ANDROID_LANG": "en"
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

The package is MIT-licensed with 153 unit tests running on Node 20 and Node 22. If you run into quirky uiautomator trees on specific OEM skins (One UI, HyperOS, ColorOS), open an issue on the repo.

Top comments (2)

Collapse
 
userxnom profile image
Abdullah Naseer •

This is the rare agent-tooling post that names the actual costs instead of hand-waving them — 1,800 vision tokens per screenshot step versus 10,000+ tokens of raw XML is the kind of trade-off that decides whether a phone agent is usable at all, and the compact ui_tree plus onlyChanged diff is the right answer to both at once. The detail I respect most is the deny-zones being enforced in code before any shell call, not left to the model's judgment — that is the part most phone-agent demos quietly skip.

Two things I am curious about: with RecyclerView lists, does ui_tree only see what is currently laid out, so the agent has to scroll to discover items below the fold — and does onlyChanged pick those up cleanly once they appear? And on the split-screen fix, dump --windows covers Android 13+, but when two apps sit side by side, how does a tap by index resolve to the right window — is there anything stopping an index from one pane being tapped in the other?

Collapse
 
jacobianflux profile image
Jacobian Flux Labs •

The onlyChanged: true two-pass structural diff (+ / ~ / -) is a great MCP design pattern — most UI-automation servers either burn vision tokens on repeated screenshots or flood context windows with raw XML wrappers. Conditionally hiding the 7 privileged root tools from tools/list under AdbTransport is also underrated: cutting ~1,100 schema tokens per turn while preventing the model from hallucinating unreachable commands pays off on every step. Enforcing password="true" masking and package deny-zones in server code rather than relying on system prompts is exactly how device-level MCP boundaries should be built.