Skip to main content
Glama
README.md
<div align="center">

<img src="assets/banner.png" alt="Phone Harness banner" width="100%">

<img src="assets/logo.svg" alt="Phone Harness logo" width="140">

# PHONE HARNESS

**A 40-tool Rust MCP server for real Android devices — built on `rmcp`, driven by ADB, zero Python runtime.**

![Rust](https://img.shields.io/badge/Rust-1.88%2B-ff7043?style=for-the-badge&logo=rust)
![MCP](https://img.shields.io/badge/MCP-rmcp_3.12-00e5ff?style=for-the-badge)
![Platform](https://img.shields.io/badge/Platform-Windows%20%7C%20Android-7c4dff?style=for-the-badge)
![Tools](https://img.shields.io/badge/Tools-40-ff2d95?style=for-the-badge)

</div>

---

## Overview

Phone Harness exposes an Android device to any MCP client through a single stdio server. Observation is **accessibility-first**: it reads `uiautomator` hierarchies, returns a compact indexed DOM, and rejects actions grounded against a stale observation generation. Actions are executed with ADB.

It is a native Rust rewrite of the original Python `universal-phone-harness`. The Python implementation remains available separately as a compatibility fallback.

```
+----------------+      stdio / MCP       +-------------------+      ADB      +----------------+
|  MCP client    |  <------------------>  |  phone_harness    |  <-------->  |  Android device|
|  (OpenCode…)   |   40 tools, JSON-RPC   |  Rust, rmcp 3.12  |   shell I/O  |  USB / WiFi    |
+----------------+                        +-------------------+              +----------------+
```

## Features

- **40 tools** — observation, gestures, app lifecycle, logs, GPS mocking, screen recording, batching, crawling and replay.
- **Generation-gated grounding** — indexed actions require the `observation_generation` returned by `phone_observe`.
- **No Python required** — a single 5 MB release binary.
- **Token-bounded output** — compact DOM with interactive-only filtering by default.
- **Session recording** — interaction traces as JSONL, replayable with text re-grounding.
- **Screen recording** — frame capture encoded to MP4 with `ffmpeg` (for devices without `screenrecord`).
- **Batch commands** — multiple actions in one MCP round-trip.

## Tool map

| Group | Tools |
|---|---|
| Observe & assert | `phone_observe`, `phone_assert_state`, `phone_wait_for`, `phone_wait_for_settle`, `phone_health_check` |
| Input | `phone_tap`, `phone_type`, `phone_swipe`, `phone_drag`, `phone_press_key`, `phone_long_press`, `phone_double_tap` |
| Navigation | `phone_open_app`, `phone_open_url`, `phone_open_settings`, `phone_dismiss_dialog` |
| Screen | `phone_save_screenshot`, `phone_take_screenshot`, `phone_start_screen_recording`, `phone_stop_screen_recording` |
| Apps | `phone_list_devices`, `phone_list_apps`, `phone_get_foreground_app`, `phone_terminate_app`, `phone_install_app`, `phone_uninstall_app`, `phone_clear_app_data` |
| Clipboard | `phone_set_clipboard`, `phone_get_clipboard` |
| Location | `phone_set_location`, `phone_clear_location` |
| Orientation | `phone_get_orientation`, `phone_set_orientation` |
| Diagnostics | `phone_get_device_logs`, `phone_efficiency_report` |
| Automation | `phone_batch`, `phone_start_recording`, `phone_stop_recording`, `phone_replay_trace`, `phone_crawl_app` |

## Install

crates.io: `cargo install phone_harness_rust`.

Prebuilt binary: copy `target/release/phone_harness_rust.exe` somewhere stable, then register it with your MCP client.

OpenCode global config — `~/.config/opencode/opencode.json`:

```jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "servers": {
      "phone_harness": {
        "type": "local",
        "command": ["D:\\path\\to\\phone_harness_rust.exe"],
        "protocol": "legacy"
      }
    }
  }
}
```

Requirements at runtime: ADB on PATH or at `D:\platform-tools\adb.exe`, USB debugging authorized, `ffmpeg` on PATH for screen recording.

## Build from source

```powershell
cargo build --release
```

On Windows with the MSVC toolchain you need the Visual Studio C++ build tools **and** a Windows SDK (`kernel32.lib`, `dbghelp.lib`). `build.ps1` in this repository sets `LIB` and uses the bundled linker when building from a plain shell.

## Usage loop

1. `phone_observe` → get `[1]`, `[2]`… badges and an `observation_generation`.
2. `phone_tap` / `phone_type` with `index` **and** that generation.
3. Text and coordinate selectors do not need a generation.
4. On a failed assertion, re-observe — don't reuse a stale generation.

```json
{ "index": 3, "observation_generation": 12 }
```

## Verified on

- Huawei JLN-LX1 (`JLN-LX1`), Android 12, 1080×2388, ADB serial `U4YYD22415503298`.
- Mock GPS provider `oc-mock` confirmed through `dumpsys location`.
- Screen recording produced a 2.67 s / 254 KB MP4 at 3 fps, verified with `ffprobe`.

## Known limitations

- `phone_wait_for_settle` uses UI-hierarchy stability, not perceptual image diff.
- `phone_save_screenshot` writes a raw framebuffer PNG; the SoM overlay is not implemented. Secure windows (banking apps) may return no pixels.
- `phone_set_orientation` changes the `user_rotation` setting; some real devices do not physically rotate.
- `phone_set_location` installs a mock location provider; it does not override GNSS hardware.
- `phone_replay_trace` and `phone_crawl_app` are simplified versions of their Python counterparts.
- `phone_get_clipboard` may return empty on Android 12; `phone_set_clipboard` works.

## Registry identity

- MCP Registry name: `mcp-name: io.github.ZachDreamZ/phone-harness-rust`

## Research credits

Capability ideas came from [mobile-next/mobile-mcp](https://github.com/mobile-next/mobile-mcp), [CursorTouch/Android-MCP](https://github.com/CursorTouch/Android-MCP), and the original [universal-phone-harness](https://github.com/ZachDreamZ/universal-phone-harness). MCP transport is the official Rust SDK [rmcp](https://github.com/modelcontextprotocol/rust-sdk).

## License

MIT — see [LICENSE](LICENSE).