turbo-android-mcp v0.1.0 發佈,透過 ADB 操控 Android 裝置並提供精簡 UI 樹
Driving Android Phones Over ADB Without Screenshot Loops or Raw XML Dumps (turbo-android-mcp)
Trung Thanh Tran 發佈 turbo-android-mcp v0.1.0,這個 Node.js MCP 伺服器可透過標準 adb 操控 Android 手機、平板及模擬器,毋須 root。
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)
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
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:
-
AdbTransport(default on Windows, macOS, and Linux): connects to any Android device over USB or Wireless Debugging without root. -
ChrootRootTransport(optional advanced mode): runs inside an on-device Debianarm64chroot 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
-
uiautomator dumpfails while animations run and drops split-screen panes. Standarduiautomator dumpfrequently exits withERROR: could not get idle stateif a spinner or transition is active, and it only dumps a single window on tablets running split-screen or two-pane Settings.ui_treerunsuiautomator 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. -
adb shell input textfails on accented Vietnamese and Unicode. Android's built-ininput textcommand only accepts printable ASCII. Inturbo-android-mcp,type_textusesinput textfor plain ASCII and routes Unicode, accented Vietnamese, CJK, and emoji payloads as Base64 broadcasts throughTurboImeService, automatically restoring the user's previous keyboard (/data/local/tmp/turbo_prev_ime) in afinallyblock. - WebViews and mobile browsers return empty trees to
uiautomator. When an Android app renders inside Chrome, Brave, or a debuggable WebView,uiautomatoroften 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 to127.0.0.1:9333soturbo-browser-mcpcan 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 acrossui_tree,screenshot,tap,swipe,type_text,open_app, and the CDP bridge. - Any node with
password="true"has its text masked as"••••"and itscontent-descstripped inui_tree. - If a password input is focused or targeted by index/id,
type_textrejects 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
Add to Claude Code:
claude mcp add turbo-android -- npx -y turbo-android-mcp
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"
}
}
}
}
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.
來源:DEV Community · dev.to