Mobile Agent Harness

io.github.Aelindrav0.5.0更新于 Oct 4, 2026

Android device automation for AI agents: MCP server, CLI, and plugin runtime over adb.

已验证STDIO仅桌面Developer ToolsBrowser Automation

概览

AI 生成的概览

让 AI 助手通过 adb 观察和操作 Android 设备,使用无障碍树选择器、截图、OCR 和应用流程。

功能
这是一个 MCP 服务器、CLI 和插件运行时,通过自愈的 uiautomator2 桥接驱动 Android 设备,无需在设备上安装应用。观察类工具包括 ui.snapshot、ui.dump、ui.find、vision.screenshot、vision.ocr 和 vision.diff;操作类工具包括 ui.click、ui.set_text、ui.scroll、input.tap 和 input.swipe。还提供应用生命周期工具(app.launch、app.probe、app.wait_idle)、Shell 与数据工具(shell.run、state.prefs、state.db、file.push、file.pull、net.http)、事件捕获以及知识与任务辅助工具。选择器基于实时无障碍树解析而非坐标,工具返回 ok/error 信封。
适用场景
当助手需要检查或操作真实 Android 设备或模拟器时使用:复现界面流程、读取屏幕状态、执行应用级检查,或在自己的设备上为开发和测试构建按应用划分的自动化 harness。
运行要求
作为本地 Python 进程运行(Python 3.9+),需要 adb 在 PATH 中且目标设备已启用 USB 调试。设备序列号通过 AGENT_SERIAL_DEFAULT、AGENT_SERIAL_USB 或 --serial/ANDROID_SERIAL 设置。可选视觉功能使用 MAH_FRAME_STREAM、MAH_VISION_MODE 和 MAH_VLM_URL/MAH_VLM_MODEL;OCR 功能需要安装 ocr 附加项。
安装前请注意
该服务器可以操作设备:点击、输入、滚动、启动和停止应用、执行 Shell 命令以及推送或拉取文件,因此误操作可能更改或删除设备数据。Root 支持是声明式的,仅在设备已有 su 时启用,并受命令允许列表限制。消息、银行和电商类应用带有反自动化风控,adb 层在这些应用上不可靠。若 MAH_VLM_URL 指向外部视觉端点,屏幕数据会发送给该第三方。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Mobile Agent Harness,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

mobile-agent-harness

Android device automation for AI agents. MCP server, CLI, and a hot-reloadable plugin runtime on top of a self-healing uiautomator2 bridge. No device-side app required.

中文文档:README.zh-CN.md

This is the base runtime only. Plugins live in the community catalog: awesome-mobile-agent-harness-plugin. App business knowledge for AI lives in app-knowledge-packs, which this repo's knowledge/ loader reads directly.

Install

bash
git clone https://github.com/Aelindra/mobile-agent-harness
cd mobile-agent-harness
pip install -e .          # add ".[ocr]" for vision.ocr / ui2.*

Requires Python 3.9+ and adb on PATH with USB debugging enabled.

Quick start

  1. Point the bridge at your device:
bash
export AGENT_SERIAL_DEFAULT=192.168.1.23:5555   # or "emulator-5555"
  1. List the tool surface (works without a device) and run the offline tests:
bash
python -m core.cli tools
python tests/test_runtime.py
  1. Call a tool:
bash
python -m core.cli call ui.snapshot
python -m core.cli call ui.click --args '{"selector":"text@^Network & internet$","pkg":"com.android.settings"}'
  1. Attach to any MCP client:
json
{
  "mcpServers": {
    "phone": {
      "command": "python",
      "args": ["-m", "core.cli", "mcp"],
      "cwd": "/path/to/mobile-agent-harness",
      "env": { "AGENT_SERIAL_DEFAULT": "192.168.1.23:5555" }
    }
  }
}

All tools return a {"ok": bool, "error"?, ...} envelope. ok=false is a business result (e.g. error_type=selector_not_found) — adapt instead of retrying.

Tools

GroupTools
Observationui.snapshot ui.dump ui.find ui2.state ui2.screen_evidence ui2.timeline ui2.find_templates vision.screenshot vision.ocr vision.diff
Actionui.click ui.click_handle ui.text_handle ui.hold_read ui.set_text ui.scroll ui.back ui.home input.tap input.swipe input.key
Appapp.launch app.current app.probe app.list app.stop app.wait_idle
Shell & datashell.run state.prefs state.db file.push file.pull net.http
Eventsevents.tail events.wait events.capture events.record_start events.record_stop
Knowledge & tasksknowledge.list knowledge.guide ui2.check_states ui2.orient task.begin task.note task.end template.add sys.capabilities

ui.snapshot returns a compact accessibility-tree listing with element handles (e0, e1, ...); ui.click_handle acts on a handle with drift detection. ui2.state fuses the accessibility tree with OCR for canvas-drawn UIs. ui2.screen_evidence collects measurable screen features (overlay level, motion, color, layout density) without interpreting them. app.probe returns deterministic side signals (package, version, orientation); ui2.timeline captures N frames of lightweight evidence in time order; ui2.orient probes context, routes to matching knowledge packs, and evaluates their state discriminators — returning matched states or ranked hypotheses with the missing evidence listed.

Selectors

Selectors resolve against the live accessibility tree. Coordinates are not used.

python
# ui.click selector examples
"id@d98 && [email protected]"       # resource-id, short form completed with pkg@
"text@^Settings$ && [email protected]"
"[email protected] && [clickable=true]"
"desc@^Search$"                        # content-desc regex

Harnesses and plugins

A harness file declares per-app flows as selector steps with pre/postconditions; distill drafts one by exploring an app, lint checks selector quality, and failed postconditions mark tools stale for re-distillation. See harnesses/com.android.settings/harness.json5 for the built-in example.

Plugins drop into plugins/ and register tools or capability providers at load time; registrations are reversible and hot-reloaded on file change. See the Plugin development guide in README.zh-CN.md and knowledge/README.md for the knowledge-pack format.

For business context on apps where model priors are unreliable, point agents at app-knowledge-packs — a community catalog of structural app surveys in the open Agent Skills format, split per feature module for complex apps. Mobile scenarios in particular are private-domain and underrepresented in training data, so agents benefit from loading the relevant survey before operating an unfamiliar app. The local knowledge/ directory remains this repo's runtime layer (packs, icon templates, state discriminators).

Configuration

VariableDescriptionExample
AGENT_SERIAL_DEFAULTDevice serial used when --serial/ANDROID_SERIAL absent192.168.1.23:5555
AGENT_SERIAL_USBUSB serial fallback0123456789abcdef
MAH_FRAME_STREAM1 enables the H.264 frame stream for observation tools1
MAH_VISION_MODEVision enhancement: off / client / endpointclient
MAH_VLM_URL / MAH_VLM_MODELExternal vision endpoint (OpenAI-compatible)http://127.0.0.1:11434/v1/chat/completions

How it compares

  • vs mobile-mcp / agent-device: they are generic device toolsets; this project adds the layer above transport — per-app knowledge as files (harnesses), a hot-reloadable plugin runtime with capability seams, and an explicit adb/root privilege model.
  • vs droidrun: droidrun requires a device-side accessibility app; this project is zero-install over adb.
  • Root support is declarative: if the device already has su, the shell seam gains a root provider gated by a command allowlist. This project does not provide root.

Known limitations

Messaging, banking, and e-commerce apps run active anti-automation risk control; the adb tier is unreliable on them. Target use is development, testing, and your own device workflows.

Contributing

Plugins are contributed to awesome-mobile-agent-harness-plugin; app business knowledge to app-knowledge-packs — see their contributing guides.

License

MIT.

来源:README.md,提交 a05ec97

工具

0
工具元数据尚未被收录。

版本历史

1
  1. v0.5.0最新Oct 4, 2026