Agent-Android
This server lets AI agents discover and control Android devices over MCP: inspect screens, automate UI interactions, manage apps and text input, and handle connected devices.
Discover devices: list USB/WiFi devices, connect to WiFi ADB endpoints, pair via six-digit code, and reconnect remembered devices.
Inspect the screen: capture screenshots, get screen dimensions, dump the accessibility UI tree, or get a compact visible-label summary.
Use OCR: read text from screens without accessibility trees and tap text found via OCR.
Find and interact with UI elements: locate elements by text, resource ID, class, or content description; tap them, wait for them, or tap coordinates.
Perform gestures and input: tap, double-tap, swipe, send key events, type/clear text, and check text-input/IME capabilities.
Manage apps: list/search installed packages, launch apps, wait for a foreground app, and get the current foreground package.
Coordinate actions: read-only hints and destructive-action annotations help agents avoid unintended changes, and the README describes a per-device serialized async command queue with status/cancel support.
Allows controlling Android devices via ADB for automation, testing, and interaction, including screen capture, clicks, text input, app management, UI tree extraction, and OCR.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Agent-Android List connected devices and give a screen summary"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
agent-Android-bridge
简体中文 | English | 美术与设计资产 (Assets)
agent-Android-bridge 是面向 AI Agent 的 Android 执行桥。它通过 MCP 暴露设备发现、应用与进程管理、UI 树、截图/OCR、输入手势、文件与 Shell 操作,以及按设备串行的异步命令队列。
当前主线是 2.0.0 架构,提供两种设备驱动:
ADB 驱动:通过 USB 或 Wireless ADB 控制已授权设备,能力最完整。
Android Runner:手机主动建立 WSS 连接,适合跨 NAT 场景;当前 APK 主要覆盖截图、UI 树、手势、文字和剪贴板能力。
当前源码注册 58 个 MCP 工具。工具列表以 MCP 客户端发现结果和 src/agent_android/mcp_server/server.py 为准。
agent-Android-bridge 可以触发真实点击、消息发送、文件修改和应用操作。只控制自己拥有或获准控制的设备;付款、删除、发送等后果性动作应保留人工确认,并读取操作后的 UI 验证结果。
快速开始
要求:Windows、Python 3.11,以及 ADB 驱动路径所需的 Android Platform Tools。
powershell git clone https://github.com/xiaoran7/agent-Android-bridge.git agent-Android-bridge cd agent-Android-bridge py -3.11 -m venv .venv .\.venv\Scripts\python.exe -m pip install -U pip .\.venv\Scripts\python.exe -m pip install -e ".[dev,ocr]" .\.venv\Scripts\agent-android-bridge.exe setup
连接手机并在设备上批准调试授权:
powershell .\.venv\Scripts\agent-android-bridge.exe devices .\.venv\Scripts\agent-android-bridge.exe info "<device-id>"
启动本地 stdio MCP:
powershell .\.venv\Scripts\agent-android-bridge.exe mcp
Codex 注册示例:
powershell codex mcp add agent-android-bridge --env "ADB_PATH=C:\Android\platform-tools\adb.exe" -- "C:\path\to\agent-Android-bridge\.venv\Scripts\python.exe" -m agent_android.cli mcp
其他 stdio 客户端可参考 .mcp.json.example。
Related MCP server: DeepADB
SSE 与 Android Runner
SSE 模式同时挂载 Android Runner 的 WebSocket 入口 /runner/ws:
powershell .\.venv\Scripts\agent-android-bridge.exe mcp --transport sse --host 127.0.0.1 --port 8765
Runner 必须连接到同一服务对应的 ws://.../runner/ws 或 wss://.../runner/ws。
Runner 身份认证(tg-oauth)
Runner 握手支持 OAuth 2.0 Bearer 认证:APK 以 Authorization Code + PKCE 通过 TannerLab ID(tg-oauth)登录,WebSocket 握手携带 Authorization: Bearer ,网关经 RFC 7662 introspection 验证通过后才注册会话。
配置以下三项后认证强制开启(缺一项即回退为接受未认证设备,仅限本机开发):
变量 | 用途 |
AGENT_ANDROID_RUNNER_OAUTH_ISSUER | tg-oauth 发行者 URL,如 https://auth.tannerlab.cn |
AGENT_ANDROID_RUNNER_OAUTH_CLIENT_ID | 网关使用的机密客户端 ID(调 introspection 用) |
AGENT_ANDROID_RUNNER_OAUTH_CLIENT_SECRET | 上述机密客户端的 secret |
AGENT_ANDROID_RUNNER_OAUTH_ALLOWED_CLIENTS | 允许接入的 Runner 客户端列表,默认 gent-android-runner,agent-android-bridge-runner,droidbridge-runner |
tg-oauth 侧需在部署环境变量 OAUTH_CLIENTS 注册两个客户端(公共客户端给 APK,机密客户端给网关;接入契约见 tg-oauth docs/INTEGRATION.md):
json [ {"client_id": "droidbridge-runner", "name": "agent-Android-bridge Runner", "description": "agent-Android-bridge Android Runner 设备端", "redirect_uris": ["agent-android-bridge://oauth/callback", "droidbridge://oauth/callback"]}, {"client_id": "droidbridge-gateway", "name": "agent-Android-bridge Gateway", "description": "agent-Android-bridge Runner 接入网关(introspection)", "redirect_uris": ["https://mcp2.tannerlab.xyz/runner/callback"], "client_secret": "<与网关 env 一致>"} ]
注意:tg-oauth 的 seed 校验要求每条 edirect_uris 非空,机密客户端也要至少登记一个占位回调地址。
公网部署必须同时具备受信任反代的 TLS 与此处认证;认证回答的是"这条会话是谁发起的",设备授权与后果性动作确认仍由运营者自行保留。
Android APK 的构建、权限与当前能力见 Runner README。
推荐调用顺序
list_devices
screen_summary;无有效无障碍树时再用 screenshot 或 OCR
ind_element / wait_for_element
执行最小必要动作
再次读取 UI、前台应用或命令状态,确认真实结果
submit_action、get_command_status、list_commands 与 cancel_command 提供非阻塞命令票据。同一设备按提交顺序执行,不同设备可并行;只能取消仍处于 pending 的命令。
Unicode 输入
ADB 路径的可靠 Unicode 输入需要用户自行提供并核验 ADBKeyBoard:
powershell .\scripts\install_adb_keyboard.ps1 -DeviceId "<device-id>" -ApkPath "C:\path\to\ADBKeyboard.apk"
input_text(method="auto") 在没有可靠输入后端时会明确失败。若显式使用 method="raw",应接受输入法拦截、转义和 OEM 差异带来的不可靠性。Runner 使用无障碍输入,不依赖 ADBKeyBoard。
配置
变量 | 用途 |
ADB_PATH | db 可执行文件路径 |
AGENT_ANDROID_DATA_DIR | 设备记录和活动数据库目录 |
AGENT_ANDROID_RUNTIME_DIR | 命令队列与进程锁目录 |
AGENT_ANDROID_COMMANDS_DB | 命令队列 SQLite 文件 |
AGENT_ANDROID_COMMAND_QUEUE_TIMEOUT | 命令开始前的排队超时 |
AGENT_ANDROID_COMMAND_QUEUE_MAX_PENDING | 单设备待处理/运行命令上限 |
AGENT_ANDROID_SCRCPY_SERVER_JAR | 开发时覆盖 scrcpy-server |
AGENT_ANDROID_SCRCPY_SERVER_VERSION | 自定义 scrcpy-server 版本 |
AGENT_ANDROID_SCRCPY_SERVER_SHA256 | 自定义 scrcpy-server 摘要 |
AGENT_ANDROID_SCRCPY_MAX_SIZE | scrcpy 编码最长边 |
AGENT_ANDROID_RUNNER_OAUTH_ISSUER | tg-oauth 发行者 URL;与 CLIENT_ID/SECRET 同时配置后 Runner 握手强制认证 |
AGENT_ANDROID_RUNNER_OAUTH_CLIENT_ID | 网关 introspection 用的机密客户端 ID |
AGENT_ANDROID_RUNNER_OAUTH_CLIENT_SECRET | 上述机密客户端的 secret |
AGENT_ANDROID_RUNNER_OAUTH_ALLOWED_CLIENTS | 允许接入的 Runner 客户端列表 |
开发检查
powershell .\scripts\setup_venv.ps1 .\.venv\Scripts\python.exe -m ruff check . .\.venv\Scripts\python.exe -m ruff format --check . .\.venv\Scripts\python.exe -m pytest -q .\.venv\Scripts\python.exe -m bandit -q -r src .\.venv\Scripts\python.exe -m build
Android Runner 需要 Android Studio、JDK 17 和 Android SDK 35;仓库目前没有 Gradle Wrapper。
当前边界
stdio 适合本机 Agent + ADB;Android Runner 需要 SSE 服务承载 WebSocket。
Runner 握手认证依赖 tg-oauth introspection;未配置 issuer 时网关接受未认证设备,只应用于本机开发。
Runner APK 只实现 MCP 表面的一个能力子集;未知动作会返回失败。
无障碍树可能缺失 Canvas、游戏或部分 WebView 内容,此时使用截图/OCR。
Android OEM 的输入法、后台冻结、无线调试和无障碍策略差异较大。
命令队列只持久化脱敏参数和状态;可执行回调留在提交进程,进程退出后不能由其他进程重放。
pyproject.toml 已是 2.0.0,但部分打包脚本和运行时版本常量仍在迁移;发布前必须完成一致性检查。
文档
代码采用 MIT License。内置 scrcpy-server 的来源与 Apache 2.0 许可见第三方声明。
Available Tools
27 toolsclear_textBDestructive
Clear text in the currently focused input field.
Inputs: device_id (required). Returns: result
connect_deviceADestructive
Connect to a WiFi device by ip:port (already tcpip-enabled or paired).
Inputs: ip (required), port (required). Returns: result
double_tapADestructive
Double-tap the screen at pixel coordinates (x, y).
Inputs: x (required), y (required), device_id (required). Returns: result
dump_uiARead-onlyIdempotent
Get all UI elements on screen (text/resource-id/class/bounds/clickable) via the accessibility tree.
Inputs: device_id (required). Returns: result
find_elementBRead-onlyIdempotent
Find the first UI element matching the given (non-None) attributes. Returns None if not found.
Inputs: device_id (required), text, exact, class_name, +2 more. Returns: result
get_current_appARead-onlyIdempotent
Get the package name of the currently foregrounded app.
Inputs: device_id (required). Returns: result
get_screen_sizeARead-onlyIdempotent
Get active and physical screen dimensions without transferring a screenshot.
Inputs: device_id (required). Returns: object
input_textADestructive
Type text into the focused field.
``auto`` only uses an unattended-safe ADBKeyBoard backend and fails clearly
when it isn't installed. ``raw`` is explicit best-effort ASCII and can be
intercepted or changed by the active Android IME.
Inputs: text (required), device_id (required), clear, method, +1 more. Returns: object
key_eventADestructive
Press a named key (home, back, recent, volume_up, ...) or raw Android keycode.
Inputs: key (required), device_id (required). Returns: result
launch_appCDestructive
Launch an app and, by default, wait until it is confirmed foreground.
Inputs: device_id (required), package_name (required), stop, wait, +1 more. Returns: object
list_appsBRead-onlyIdempotent
List installed package names on the device.
Inputs: device_id (required), third_party_only. Returns: result
list_devicesARead-onlyIdempotent
List all currently visible Android devices (USB and already-connected WiFi).
Inputs: no named parameters. Returns: result
list_remembered_devicesARead-onlyIdempotent
List WiFi device_ids previously paired/connected, whether or not currently reachable.
Inputs: no named parameters. Returns: result
ocr_screenARead-onlyIdempotent
Run OCR on the current screen for UIs with no usable accessibility tree (canvas/games/WebView). Returns matched text + bounding box + confidence.
Inputs: device_id (required), min_confidence. Returns: result
ocr_tapADestructive
Find text on screen via OCR (best fuzzy match) and tap its center. Raises if no good match is found.
Inputs: text (required), device_id (required), exact, min_similarity. Returns: object
pair_with_codeBDestructive
Pair with an Android 11+ wireless-debugging device using its six-digit code.
Inputs: ip (required), code (required), pairing_port (required). Returns: result
reconnect_remembered_devicesADestructive
Attempt to reconnect every remembered WiFi ADB device.
Inputs: no named parameters. Returns: result
screenshotBRead-onlyIdempotent
Capture the current screen of the given device as an image.
Inputs: device_id (required).
screen_summaryARead-onlyIdempotent
Return compact visible labels and bounds; prefer this over dump_ui for routine inspection.
Inputs: device_id (required), max_items. Returns: result
search_appsBRead-onlyIdempotent
Search installed package names containing keyword.
Inputs: keyword (required), device_id (required). Returns: result
swipeBDestructive
Swipe from (x1, y1) to (x2, y2) over duration seconds.
Inputs: x1 (required), x2 (required), y1 (required), y2 (required), +2 more. Returns: result
tapCDestructive
Tap the screen at pixel coordinates (x, y).
Inputs: x (required), y (required), device_id (required). Returns: result
tap_elementBDestructive
Find a UI element by attribute(s) and tap its center. Raises if no match is found.
Inputs: device_id (required), text, exact, class_name, +2 more. Returns: object
tcpip_pair_deviceADestructive
Switch a USB-connected, already-trusted device into WiFi mode and connect to it. Requires the device to have been used over USB at least once already.
Inputs: ip (required), usb_serial (required), port. Returns: result
text_input_capabilitiesARead-onlyIdempotent
Inspect the active IME and whether reliable Unicode input is available.
Inputs: device_id (required). Returns: object
wait_for_appBRead-onlyIdempotent
Wait until the requested Android package becomes the foreground app.
Inputs: device_id (required), package_name (required), timeout, interval. Returns: result
wait_for_elementCRead-onlyIdempotent
Wait until an accessibility element appears, then return it.
Inputs: device_id (required), text, exact, timeout, +4 more. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 27 tools
Most tools have clearly distinct purposes, such as tap vs double_tap vs swipe vs key_event. However, there is some overlap between UI inspection tools (dump_ui vs screen_summary vs find_element vs ocr_screen) and between device connection tools (connect_device vs pair_with_code vs tcpip_pair_device), though descriptions help differentiate them.
Tool names are mostly snake_case but mix verb_noun (e.g., list_devices, tap, input_text) with noun phrases (e.g., screenshot, key_event, screen_summary). Some names like 'tcpip_pair_device' are awkward. Overall readable but not fully consistent.
27 tools is on the high side for an MCP server. While each tool has utility, the set could potentially be streamlined (e.g., combining some UI inspection tools). The count feels slightly excessive for the domain scope.
The tool set covers many key operations (device discovery, screen capture, input, UI inspection, app management), but lacks common actions like device info retrieval, app install/uninstall, clipboard access, and explicit scrolling. These gaps may limit automation scenarios.
Maintenance
Related MCP Connectors
Remote MCP server that lets AI assistants operate your own Android phone (Android 11+, no root) with per-app allowlists, on-phone approval, hidden verification codes, and mandatory confirmation for banking and payment apps that Tongs recognizes.
Cloud Android devices for AI agents: install an APK, read the screen, tap, type, read logcat.
MCP server for building and testing AI agents with multi-model experimentation and insights.
Mobile sandboxes for AI agents: each agent gets its own cloud Android phone or iOS simulator over MCP, reads the screen, taps, types and installs your app. Android $0.01/min, iOS $0.03/min, parked phones free.
Related MCP Servers
- AlicenseAqualityCmaintenanceA MCP server that enables AI assistants to control Android devices via ADB, supporting device info, screen control, input simulation, app management, shell execution, file transfer, and UI parsing.20MIT
- AlicenseBqualityBmaintenanceA comprehensive MCP server that enables AI agents to interact with Android devices through Android Debug Bridge (ADB), offering 198 tools for device control, app management, diagnostics, and more.20924Apache 2.0
- AlicenseNot gradedqualityDmaintenanceA MCP server that enables LLMs to control Android devices via ADB, supporting input, UI hierarchy, device management, and shell commands.16MIT
- FlicenseNot gradedqualityDmaintenanceA powerful MCP server that provides comprehensive Android device automation capabilities through ADB, enabling AI agents to interact with Android devices for testing, automation, and device control tasks.1-