Skip to main content
Glama
README.md
# android-ui-mcp-server

<!-- LANG_NAV_START -->
[العربية](README.ar.md) | [Deutsch](README.de.md) | **[English](README.md)** | [Español](README.es.md) | [Français](README.fr.md) | [हिन्दी](README.hi.md) | [日本語](README.ja.md) | [한국어](README.ko.md) | [Polski](README.pl.md) | [Português](README.pt.md) | [Русский](README.ru.md) | [中文](README.zh.md)
<!-- LANG_NAV_END -->

Android MCP Server for automating Android devices via ADB and UIAutomator2.

It provides **82 MCP tools** in three categories:

| Category | Prefix | Count | Description |
|----------|--------|-------|-------------|
| ADB | `adb_*` | 22 | Device communication via ADB (shell, install, screenshot, logcat, port forwarding, WiFi, etc.) |
| UI | `ui_*` | 32 | UI automation via UIAutomator2 (click, swipe, getTree, OCR, image matching, clipboard, etc.) |
| Playwright | `pw_*` | 28 | WebView automation via Chrome DevTools Protocol (click, eval, React tree, scroll, etc.) |

## Architecture

**100% Rust backend.** Each tool is a struct implementing the `McpTool` trait (see `crates/mcp-server/src/tools/mcp_tool.rs`), following the convention: **one struct = one file**, file name = tool name (snake_case), e.g. `click.rs` → `ui_click`.

```
crates/mcp-server/src/tools/
├── mcp_tool.rs           # Common trait
├── registry.rs           # Central registration of all tools
├── adb/                  # 22 ADB tools
├── ui/                   # 32 UI tools
└── pw/                   # 28 Playwright/WebView tools
```

The application is a **native Tauri v2 desktop app** — a single process that owns all backend state (MCP listener, ADB, emulator cache, scrcpy, diagnostics, tool registry). AI clients spawn a tiny `android-mcp-proxy` binary that bridges stdio ↔ authenticated localhost TCP to the Tauri host. The React frontend communicates with the backend exclusively via Tauri's native IPC (`invoke` + `Channel<UiEvent>`) — no HTTP server, no Socket.IO, no browser WebSocket.

### Admin UI and i18n

The web interface (admin panel) lives in `ui/src/`. It is a React 19 frontend loaded by Tauri's WebView and communicating with the Rust backend via native IPC.

```
ui/src/
├── App.tsx               # Root component — wires hooks and components
├── nativeClient.ts       # Single import point for @tauri-apps/api (invoke + Channel)
├── types.ts              # Shared types (Snapshot, ActiveSession, SetupPhase, …)
├── i18n/                 # Internationalization (12 languages)
│   ├── index.ts          #   Bundle aggregator, t(), detectLocale()
│   ├── types.ts          #   Locale, LocaleOption types
│   └── ui/               #   UI strings (~300 keys × 12 languages, en = source of truth)
├── hooks/                # React hooks (each state/logic in a separate file)
│   └── useUiEvents.ts    #   Subscribes to Channel<UiEvent> + gap detection → resync
├── components/           # UI components (one file = one component)
│   └── LivePreviewSection.tsx # Native Channel<Vec<u8>> live preview (no WebSocket)
└── utils/                # Pure helper functions (no React dependency)
```

### Tauri Desktop App

The admin panel runs in a **Tauri v2** desktop app. The Tauri app IS the backend — it starts the MCP TCP listener, owns all shared state (`AppRuntime`), and serves the React frontend via Tauri's native WebView. AI clients spawn `android-mcp-proxy` (a tiny stdio ↔ TCP bridge) which connects to the Tauri app's MCP listener via authenticated localhost TCP. See [ARCHITECTURE.md](ARCHITECTURE.md) for details.

## Installation

### macOS (Homebrew)

```sh
brew tap b2bc-devkit/tap
brew install b2bc-devkit/tap/android-ui-mcp-server
brew services start android-ui-mcp-server   # optional: auto-start at login
```

The formula installs the tray app `android-ui-mcp-server` and the MCP bridge
`android-mcp-proxy` as bare universal binaries — there is no `.app` bundle.
Distribution deliberately avoids casks: Homebrew propagates macOS quarantine
attributes onto cask-installed executables, which made unsigned binaries hang
when spawned directly (including `android-mcp-proxy` launched by AI clients).
Formula-installed binaries are not quarantined. Migrating from the retired
cask? Run `brew uninstall --cask android-ui-mcp-server` first, then install
the formula as above.

### Windows (Scoop)

```powershell
scoop bucket add b2bc https://github.com/b2bc-devkit/scoop-bucket
scoop install android-ui-mcp-server
```

The package installs `android-ui-mcp-server.exe` and `android-mcp-proxy.exe`
side by side and creates a Start Menu shortcut for the tray app. It requires
the WebView2 Runtime, which is preinstalled on Windows 11 and most
up-to-date Windows 10 systems.

## Persistent UiAutomator2 server

For every connected device the backend keeps a persistent [appium-uiautomator2-server](https://github.com/appium/appium-uiautomator2-server) (v10.6.6) alive under instrumentation. `ui_*` tools (UI tree, tap/swipe actions, screenshots) are served by it whenever it is running and transparently fall back to plain `adb shell` commands otherwise.

- Both server APKs are downloaded once from GitHub Releases into `~/.android-mcp-server/`, verified against pinned SHA-256 digests (as is the scrcpy server jar), and installed only when missing or outdated.
- Per-device state (`stopped / installing / starting / running / error / disabled`), server version and local forward port are shown in the admin UI — in the **Connected Devices** header widgets (alongside the ADB and scrcpy widgets) and in each session's details.
- The feature can be toggled at runtime (global switch / per-device restart in the widget popover) or disabled at startup via `ANDROID_MCP_DISABLE_UIAUTOMATOR_SERVER=1`.

## Live Preview (scrcpy)

The admin UI can mirror a device screen with the scrcpy v3.1 protocol: the server JAR is pushed per session and streams H.264 (up to 768 px / 30 fps / 4 Mbps) over an ADB reverse tunnel, decoded in the frontend with WebCodecs (`@yume-chan/scrcpy-decoder-webcodecs`). Touch input is injected back over the scrcpy control socket. Per-device streaming state is reported in the scrcpy widget of the **Connected Devices** header.

## Build

All build and quality gates are wired through [Wireit](https://github.com/google/wireit) (Google's incremental build orchestrator) with content-hash caching — re-running `npm run build` skips any step whose inputs haven't changed.

```
npm run verify             # FULL verification (Wireit-cached):
                            #   quality gates (build) + release builds (rust, tauri)
npm run build              # quality gates only:
                            #   vite build (UI) + lint:check + trivy:scan
                            #   + cargo:fmt + cargo:clippy + cargo:deny + cargo:machete
npm run build:ui           # only build the admin UI bundle (vite)
npm run build:rust         # cargo build --release -p mcp-server -p android-mcp-proxy (domain lib + proxy)
npm run build:tauri        # cargo build --release -p android-ui-mcp-server-app (Tauri app)
npm start                  # build + run Tauri app in release mode
```

### Rust quality, profiling and analysis gates

```
npm run setup:rust-tools   # cross-platform bootstrap — installs all tools below
                            # (cargo-deny, cargo-machete, cargo-dylint, dylint-link,
                            #  cargo-flamegraph, samply, nightly toolchains for dylint/miri)

# Blocking gates (run by `npm run build` via Wireit):
npm run cargo:fmt          # cargo fmt --check (formatting)
npm run cargo:clippy       # cargo clippy --workspace --all-targets -- -D warnings
npm run cargo:deny         # cargo deny check (advisories, bans, licenses, sources)
npm run cargo:machete      # cargo machete (unused dependencies)

# Nightly-only gates (separate rust-analysis.yml CI workflow):
npm run cargo:dylint       # company custom lints (nightly-2026-04-16)
npm run cargo:miri         # memory-safety / UB detection (nightly)
npm run cargo:nightly      # both: cargo:dylint + cargo:miri (Wireit-cached)

# Benchmarks (on demand):
npm run bench              # criterion CPU benchmarks
npm run bench:callgrind    # gungraun (Callgrind) instruction-count benchmarks

# Profiling (on demand):
npm run profile:flamegraph # CPU flamegraph
npm run profile:samply     # CPU sampling profiler
npm run profile:dhat       # heap profiling (feature dhat-heap)
```

## Tests

```
cargo test -p mcp-server    # Rust unit tests
npm run test:e2e            # build:rust (Wireit) + Playwright e2e tests
                            # (UI specs attach to the app's WebView2 over CDP;
                            #  the harness sets ANDROID_MCP_E2E_CDP_PORT so the
                            #  window is created with --remote-debugging-port)
cargo run -p mcp-server --example uia2_live
                            # live UiAutomator2 end-to-end verification on a
                            # connected device/emulator (serial as first arg)
```

See [AGENTS.md](AGENTS.md) for details.

## Security (Trivy CVE scan)

The project uses [`@b2bc-devkit/trivy-scan`](https://github.com/b2bc-devkit/trivy-scan) to run
[Aqua Security's Trivy](https://aquasecurity.github.io/trivy/) vulnerability scanner.
`trivy-scan` downloads the official Trivy binary for your OS/CPU on first use, verifies its SHA-256
checksum, and caches it in your user cache directory. No manual installation is required.

```
npm run trivy:scan  # HIGH/CRITICAL scan (table output); configured via trivy.yaml
```

In CI (`.github/workflows/ci.yml`), the `test` job runs the full Wireit build including `trivy:scan` as a
blocking gate, plus `cargo fmt --check`, `cargo clippy`, `cargo deny check`, `cargo machete`, and `cargo test`.
A separate `security-reports` job generates JSON + HTML reports as artifacts.

## Libraries & tooling

The project is built on a modern, CPU-conscious toolchain. Key libraries and tools:

| Tool | Version | Role |
|------|---------|------|
| [Rust](https://www.rust-lang.org/) | stable | Backend (82 MCP tools, Tauri host, proxy, scrcpy, OCR) |
| [TypeScript](https://www.typescriptlang.org/) | 7.x | Frontend UI only (React 19 + Ant Design 6) |
| [Vite](https://vitejs.dev/) | 8.x | Admin UI bundler |
| [Oxlint](https://oxc.rs/) | 1.83 | Lint (replaces ESLint, Rust-based, `correctness` + `suspicious` + `perf` categories + `react-perf` plugin; `--deny-warnings` = warnings are blocking) |
| [Wireit](https://github.com/google/wireit) | 0.14.x | Caching build orchestrator (wires all `npm run build` / `verify` steps) |
| [Trivy](https://aquasecurity.github.io/trivy/) | — | HIGH/CRITICAL CVE scan (`@b2bc-devkit/trivy-scan` wrapper) |
| [Tauri](https://tauri.app/) | 2.x | Desktop shell for the admin dashboard (replaces Electron) |
| [cargo-deny](https://github.com/EmbarkStudios/cargo-deny) | 0.20.x | Dependency / license / security audit (Wireit gate) |
| [cargo-machete](https://github.com/bnjbvr/cargo-machete) | 0.9.x | Unused dependency detection (Wireit gate) |
| [cargo-dylint](https://github.com/trailofbits/dylint) | 6.x | Custom company lints (`tools/dylint/company_lints`, nightly) |
| [cargo miri](https://github.com/rust-lang/miri) | — | Memory-safety / UB detection for `unsafe` code (nightly) |
| [criterion](https://github.com/bheisler/criterion.rs) | 0.5.x | CPU benchmarks + regression detection |
| [gungraun](https://github.com/gungraun/gungraun) | 0.19.x | Instruction-count benchmarks (deterministic, no noise) |
| [cargo-flamegraph](https://github.com/flamegraph-rs/flamegraph) | 0.6.x | CPU profiling (flamegraph visualization) |
| [samply](https://github.com/mstange/samply) | 0.13.x | CPU sampling profiler |
| [dhat](https://github.com/nnethercote/dhat-rs) | 0.3.x | Heap profiling + allocation site analysis |


## Startup WiFi setup

- The interactive WiFi setup wizard is available in the admin dashboard UI (Tauri app).
- Pairing and connection are performed through the wizard UI — no environment variables required.

See [WIFI_CONFIGURATION.md](WIFI_CONFIGURATION.md) for details.

## Device selection (`serial`)

Tools that execute commands on a device support an optional `serial` field.

### Behavior

- if you provide `serial` → the command targets the specified device,
- if you omit `serial` and there is exactly 1 `device` → the server selects it automatically,
- if you omit `serial` and there is more than 1 `device` → the server returns a clear error with a list of serials and an example.

Example error:

`Multiple connected Android devices detected (...). Provide 'serial' in tool input. Example: { "serial": "192.168.1.190:37395" }`

## `adb_run_as_shell`

Runs a command in the application's UID context via `run-as`.

### Parameters

- `packageName` (required) — e.g. `com.mparted`
- `command` (required) — shell command executed under `run-as`
- `serial` (optional) — target device

### Usage example

```json
{
	"packageName": "com.mparted",
	"serial": "192.168.1.190:37395",
	"command": "/data/user/0/com.mparted/files/tools/arm64-v8a/bin/blkid --help >/data/local/tmp/mp_runas_blkid.out 2>&1; echo EXIT:$?; tail -n 40 /data/local/tmp/mp_runas_blkid.out"
}
```

### `run-as` requirements

- the app must be installed,
- the app must support `run-as` (debuggable),
- the command is executed via `sh -c` (supports redirections, `;`, `|`, etc.).

## WebView and Playwright/React tools (`pw_*`)

The Playwright/React tools for WebView operate on an active CDP connection.

### Connection handling

- if there is no active connection and exactly **1** WebView is detected → the connection is established automatically,
- if **more than 1** WebView is detected → you must specify `packageName` (works in all `pw_*` tools, e.g. `pw_getReactTree`, `pw_click`) or manually use `ui_webview` with the `connect` command,
- if no WebView is detected → make sure the WebView screen is visible and `webContentsDebuggingEnabled=true`.

### Parallel `pw_*` invocations

- `pw_*` requests are serialized per controller session to avoid RPC races on parallel calls (e.g. `pw_eval` + `pw_getReactTree`).

### Smoke scenario (WebView + `pw_*`)

The following sequence lets you quickly verify that the CDP channel and `pw_*` tools work correctly.

1) List available WebViews

```json
{
	"command": "list"
}
```

2) (Optional) explicit connect when multiple WebViews are present

```json
{
	"command": "connect",
	"packageName": "com.example.app"
}
```

3) Simple JS test in the WebView

```json
{
	"expression": "document.title",
	"packageName": "com.example.app"
}
```

4) React tree test

```json
{
	"maxDepth": 4,
	"packageName": "com.example.app"
}
```

Note: `pw_getReactTree` now has a fast preflight. When the current WebView has no React hook (`__REACT_DEVTOOLS_GLOBAL_HOOK__`), the tool immediately returns an empty structure and a `warning` instead of waiting for the full RPC timeout.

Expected result:
- no `Not connected to any WebView` error,
- a correct response for `pw_eval`,
- a returned tree (or a controlled message if the screen is not a React app).

On a failed `connect`, the response now includes:
- `error` with the specific reason (`Reason: ...`),
- `details` (including `packageName`, `socketName`, a diagnostic hint).

## Tool documentation

Detailed documentation for each tool (parameters, examples) is embedded directly in the binary at compile time (`include_dir!` / `include_str!` in `src-tauri/src/embedded.rs`). The source files live in `docs/tools/` and are available in 12 languages:

- `docs/tools/en/` — English (source of truth, fallback)
- `docs/tools/ar/` — Arabic
- `docs/tools/de/` — German
- `docs/tools/es/` — Spanish
- `docs/tools/fr/` — French
- `docs/tools/hi/` — Hindi
- `docs/tools/ja/` — Japanese
- `docs/tools/ko/` — Korean
- `docs/tools/pl/` — Polish
- `docs/tools/pt/` — Portuguese
- `docs/tools/ru/` — Russian
- `docs/tools/zh/` — Chinese

When a localized doc is unavailable, the tool falls back to English automatically.

## CI

`.github/workflows/ci.yml` runs on push/PR to `main`:
- **`test` job** — `ubuntu-latest` + `macos-latest` matrix: `npm ci`, `npm run build` (Wireit quality gates including trivy-scan), `cargo fmt --check`, `cargo clippy`, `cargo deny check`, `cargo machete`, `cargo test --workspace`, `npm run test:unit:run`
- **`test-windows` job** — `windows-2025-vs2026`: same gates as above
- **`security-reports` job** — `ubuntu-latest`: generates Trivy JSON + HTML reports as artifacts