agent-mobile-auto
Controls Android devices through uiautomator2/ADB, providing device discovery, health checks, compact/diff UI snapshots, semantic finding, taps/swipes/long-presses, Unicode text input, app launch, screenshots, waits, and batch/exec automation.
Controls non-jailbroken iOS devices via pymobiledevice3 and Loopback WDA, supporting UI snapshots, screenshots, taps/swipes, text input, app control, waits, and safety/lease checks.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
agent-mobile-auto
AI-Native 跨平台移动端真机自动化引擎(Android
uiautomator2/ADB+ 非越狱 iOSpymobiledevice3/LoopbackWDA)
面向 Claude Code / Cursor / Antigravity / OpenCode 的统一移动端控制底座:L1/L2 紧凑 UI 快照、Set-of-Mark (SoM) 视觉标注截图、跨进程独占租约与人工接管锁、batch --stdin单会话流水线、零依赖原生 MCP Server。
与 agent-browser-bridge(浏览器 CDP + 桌面桥接)和 agent-desktop(桌面 OS 可访问性树)一脉相承,共同组成 AI-Native 全端自动化三件套(Browser + Desktop + Mobile)。
为什么做 agent-mobile-auto?
传统移动端自动化脚本直接套给 AI Agent 往往会遇到四个硬伤:
原始 XML 极其费 Token:单屏 Android/iOS 无障碍树动辄 10k–15k Tokens,塞满上下文还拖慢推理。
多 Agent / 人机抢手机导致误点:页面异步弹窗、列表滚动或人工介入后,旧坐标和旧编号直接点偏。
每步冷启动开销大:传统 CLI 每步重启进程、重连设备,多步操作延迟极高。
缺少原生 MCP 与视觉融合:纯无障碍树在 Flutter / Canvas / 动态 H5 上容易漏节点,纯截图又缺结构化坐标。
agent-mobile-auto 用一套干净的协议层系统性解决以上问题:
核心能力 | 设计与效果 |
L1 紧凑快照 + L2 语义差分 | 过滤空容器、统一 Android/iOS 角色名,单屏减少 ~90%+ Token;L2 Diff 仅输出增删改节点,并用 |
强绑定 Scoped Ref ( | 对齐 |
Set-of-Mark (SoM) 标注截图 | 自动处理 iOS Retina 2x/3x 逻辑坐标缩放,在截图上叠加高对比度 |
跨进程独占租约 + |
|
模糊超时保护 ( | 写操作 POST 响应丢失/超时不盲目重放,返回 |
Android 毫秒级热态 + 微信/OEM 穿透 + IME 零破坏 | 默认 |
iOS Loopback 安全边界 | WDA 强制仅限 |
语义定位器 + App | 支持 |
归一化坐标 + 画面感知哈希 Diff + Deep-Link | 支持 |
零副作用热连接 Daemon + MCP 共享连接池(v0.3) | 严格仅绑 |
统一 JSON Envelope + Batch + 原生 MCP | 所有 CLI 输出统一结构化信封; |
Related MCP server: Zeus Mobile MCP
架构总览
flowchart TD
A["AI Agent / User<br/>(Claude Code / Cursor / Antigravity / Shell)"] --> B["CLI (agent-mobile)<br/>JSON Envelope + batch --stdin"]
A --> C["Built-in MCP Server<br/>(agent-mobile mcp over stdio)"]
B --> D["Shared Engine & Batch Runner (engine.py)"]
C --> D
D --> E["Safety Guardrails<br/>DeviceLease + --manual + lease_epoch<br/>SnapshotTracker + Pre-Tap Freshness"]
E --> F["Snapshot & Vision Layer<br/>L1 Compact / L2 Diff / SoM Overlay (Pillow)"]
E --> G["AndroidAdapter<br/>uiautomator2 RPC (default) / ADB fallback"]
E --> H["IosAdapter<br/>pymobiledevice3 (R0) + Loopback WDA (R1)"]
G --> I["Android Device (Explicit Serial)"]
H --> J["iOS Device (Explicit UDID, 127.0.0.1 WDA)"]快速开始
环境要求
Python 3.11+ 与
uv(推荐)Android:已安装
adb且开启 USB 调试iOS(可选):安装
uv sync --extra ios(引入pymobiledevice3),并在本地127.0.0.1:<port>转发已签名的 WebDriverAgent
安装
git clone https://github.com/linxi27667/agent-mobile-auto.git
cd agent-mobile-auto
# 基础安装(Android + MCP + SoM)
uv sync
# 包含 iOS 支持与开发测试工具
uv sync --extra ios --extra devCLI 常用命令
# 0. Android 11+ WLAN 无线调试配对与 mDNS 发现(免插线、免手动配 adb PATH)
uv run agent-mobile wifi pair 192.168.1.50:37000 123456
uv run agent-mobile wifi mdns
uv run agent-mobile wifi connect 192.168.1.50:41000
# 1. 发现已连接的 Android / iOS 设备
uv run agent-mobile devices
# 2. 单设备健康体检(能力矩阵、租约、iOS 签名倒计时)
uv run agent-mobile doctor --platform android --device <SERIAL>
# 3. 抓取紧凑 L1 UI 快照(-i 仅显示可交互控件)
uv run agent-mobile observe --platform android --device <SERIAL> --mode compact -i
# 4. 仅看与上一屏的变化(L2 语义差分)
uv run agent-mobile observe --platform android --device <SERIAL> --mode diff
# 5. 按文本/角色语义查找元素,返回强绑定 scoped_ref
uv run agent-mobile find --platform android --device <SERIAL> --text "Wi-Fi" -i
# 6. 生成 Set-of-Mark (SoM) 编号标注截图(自动压缩至 720px 宽)
uv run agent-mobile screenshot --platform android --device <SERIAL> --som --max-width 720 --out screen_som.png
# 7. 使用语义定位器、强绑定 Scoped Ref 或归一化相对坐标点击(可附加 --verify-frame-change 画面 Diff)
uv run agent-mobile tap 'role:Button[name="Wi-Fi"]' --platform android --device <SERIAL>
uv run agent-mobile tap '@snap-1-0001:e03' --platform android --device <SERIAL>
uv run agent-mobile tap --rx 0.83 --ry 0.078 --verify-frame-change --platform android --device <SERIAL>
# 8. Code-First Runner:单会话内执行带条件分支的 Python 流程(1 轮搞定复杂分支)
uv run agent-mobile exec --platform android --device <SERIAL> --code "
mobile.launch('com.tencent.mm')
mobile.sleep(0.8)
snap = mobile.observe()
if snap.foreground_app == 'com.vivo.doubleinstance':
mobile.tap('id:main', refresh=False)
result = {'app': snap.foreground_app}
"
# 9. Deep-Link / Android Intent 直达与 App learnings 知识库
uv run agent-mobile open-url --url android.settings.WIFI_SETTINGS --platform android --device <SERIAL>
uv run agent-mobile learnings list
uv run agent-mobile learnings show com.tencent.mm
# 8. 等待某个文本或应用出现(支持 --gone 等待消失)
uv run agent-mobile wait --platform android --device <SERIAL> --text "已连接" --timeout 10
# 10. 启动零副作用热连接 Daemon(可选,CLI 自动复用热连接,空闲 15 分钟自动退出)
uv run agent-mobile daemon start
uv run agent-mobile daemon status
uv run agent-mobile daemon stop
# 11. 人工接管手机(阻塞所有 AI 写入并作废旧快照)/ 释放 / 单设备隔离恢复
uv run agent-mobile lease --platform android --device <SERIAL> --manual
uv run agent-mobile lease --platform android --device <SERIAL> --release
uv run agent-mobile lease --platform android --device <SERIAL> --recoverPowerShell 提示:在 PowerShell 中请用单引号包裹带
@的引用(如'@snap-1-0001:e03'),避免被识别为 splatting 语法。
单会话 Batch 流水线(消除 CLI 冷启动)
通过 batch --stdin 在同一个进程、同一次设备连接和同一个租约内顺序执行多步操作,并支持 @latest:e01 动态绑定上一步 observe 生成的快照:
echo '[
{"action": "launch", "app": "com.android.settings"},
{"action": "observe", "mode": "compact", "interactive_only": true},
{"action": "tap", "ref": "@latest:e01"},
{"action": "type", "text": "Wi-Fi", "clear": true},
{"action": "press_key", "key": "enter"},
{"action": "wait", "text": "Wi-Fi", "timeout_s": 5}
]' | uv run agent-mobile batch --platform android --device <SERIAL> --stdin接入 MCP(Claude Code / Cursor / Antigravity / OpenCode)
agent-mobile mcp 内置零依赖 JSON-RPC 2.0 stdio 服务器,直接写入客户端 MCP 配置即可:
{
"mcpServers": {
"agent-mobile-auto": {
"command": "uv",
"args": [
"run",
"--directory",
"/path/to/agent-mobile-auto",
"agent-mobile",
"mcp"
]
}
}
}暴露的 MCP 工具(17 个)
类别 | 工具名 | 说明 |
发现与体检 |
| 列举设备、健康检查、能力矩阵与 App |
观察与视觉 |
| L1/L2 快照、语义查找、轮询等待、原始/SoM 标注截图(直接返回 |
交互动作 |
| 支持语义定位器 / |
应用与编排 |
| 应用启停/列表、Deep-Link 直达、人工接管锁与隔离恢复、 |
给 AI Agent 的内置 Skill
仓库在 skills/agent-mobile-auto/SKILL.md 提供标准 Agent Skill,也可以直接通过命令输出:
uv run agent-mobile skill统一 JSON 响应契约
所有 CLI 命令与 MCP 文本块共享同一套 Envelope 结构,方便 Agent 准确判断错误码与重试策略:
{
"version": "1.0",
"ok": false,
"command": "tap",
"error": {
"code": "MANUAL_TAKEOVER",
"message": "Device android:DEV01 is locked in manual takeover mode (owner=human)",
"retryable": false,
"details": {}
}
}退出码 | 典型 | 含义与 Agent 应对策略 |
| — | 执行成功(若返回 |
|
| 快照陈旧或元素未命中,重新 |
|
| 平台不支持或端口归属冲突,不重试 |
|
| 设备被其他 Agent 占用或处于人工接管锁,立即退让 |
开发与测试
项目采用纯 Python 跨平台测试(Windows / macOS / Linux),全部核心逻辑均有离线单元测试覆盖(无需连接真机):
uv sync --extra dev
uv run ruff check src tests
uv run pytest -v安全边界
本项目为通用移动设备自动化与测试底座,不包含绕过风控、自动付款、代登录、破解解锁或私密数据抓取能力。
支付、下单、实名认证、2FA、锁屏解锁及 iOS 开发者信任等高敏环节须严格交由人工操作(配合
lease --manual)。切勿向 Git 提交真实设备序列号、UDID、签名证书、
.ipa/.apk或包含个人隐私的截图。
License
MIT © 2026 Jeason Liu (linxi27667)
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Drive real devices from your AI Coding tool. Embed a client SDK (Unity, Godot, Flutter, iOS/macOS, Android, React Native, Web) in your app, then capture screenshots, traverse the UI tree, inject taps and key events, and run automated test tasks on the physical device over a secure relay.
Give your AI agent a real cloud Android phone: push APKs, drive it, get screenshots and logs.
Let AI agents control Android and iOS devices on Mobilerun Cloud: screen, input, apps, workflows.
Cloud Android devices for AI agents: install an APK, read the screen, tap, type, read logcat.
Related MCP Servers
- AlicenseAqualityBmaintenanceEnables AI agents to automate Android and iOS devices, including emulators and physical devices, by capturing screenshots, reading UI accessibility trees, performing touch and text input, and managing app lifecycle and logs.184MIT
- AlicenseNot gradedqualityCmaintenanceEnables local, air-gapped automation of Android and iOS devices and emulators, letting AI agents inspect UI hierarchies, tap, swipe, type, manage apps, capture screenshots, and pull device logs and crash reports. Bundles banking-grade safeguards such as automatic PII and secret redaction, PCI-DSS-style log sanitization, and configurable screenshot-blocking DLP policies.Apache 2.0
- AlicenseNot gradedqualityCmaintenanceTurns a real cloud iPhone or Android device into an environment an agent drives through up to eighteen capability-gated tools for reading the screen, tapping, swiping, typing, pressing keys and launching apps. The device also records video and a timed trajectory of every action for later inspection.8Apache 2.0
- AlicenseAqualityBmaintenanceEnables agents and LLMs to automate, inspect, and scrape native iOS and Android apps across simulators, emulators, and real devices through a platform-agnostic interface using accessibility snapshots or screenshot-based coordinates. It provides device, app, screen, input, log, and crash management tools, including optional cloud device reservation.34Apache 2.0