android-mcp
by Draklyfg
README.md
# android-mcp
[](https://github.com/Draklyfg/android-mcp/actions/workflows/ci.yml)
**English** | [简体中文](README.zh-CN.md)
An [MCP](https://modelcontextprotocol.io) (Model Context Protocol) server
that lets an AI client operate Android devices over ADB — list devices,
inspect the screen, read the UI hierarchy, tap and swipe, type text, manage
apps, and pull logs.
The server talks to devices through the standard `adb` binary from Android
platform-tools. It never builds shell strings: every adb invocation is an
argument list with a timeout and bounded output, and commands that target a
device always carry an explicit serial when more than one device is present.
## Requirements
- Python 3.11+
- Android platform-tools (`adb`) on your PATH, or pointed to by the
`ADB_PATH` environment variable
- A device or emulator with USB debugging enabled
## Install
```bash
pip install .
```
For development:
```bash
python -m venv .venv
.venv/bin/pip install -e '.[dev]'
```
## Run
```bash
android-mcp # console script
python -m android_mcp # equivalent
```
The server speaks MCP over stdio. Example client configuration (for an MCP
client that launches servers as subprocesses):
```json
{
"mcpServers": {
"android": {
"command": "android-mcp",
"env": { "ADB_PATH": "/path/to/platform-tools/adb" }
}
}
}
```
## Tools
| Tool | Description |
| --- | --- |
| `list_devices` | Devices visible to adb, with state and model. Returns an empty list plus an error message instead of failing when adb is missing. |
| `get_device_info` | Model, manufacturer, Android version, SDK, build id, battery level. |
| `screenshot` | Current screen as a PNG image. |
| `dump_ui_tree` | UI hierarchy as a compact text tree (class, text, id, bounds, `[clickable]` and other flags). |
| `tap` | Tap at pixel coordinates. |
| `swipe` | Swipe between two points with a duration. |
| `press_key` | Key by name (`HOME`, `BACK`, `ENTER`, `POWER`, `DPAD_UP`, ...) or numeric keycode. |
| `input_text` | Type text into the focused field (no newlines). |
| `launch_app` | Launch an app by package name. |
| `list_packages` | Installed packages, optionally third-party only. |
| `install_apk` | Install a local APK (`adb install -r`). |
| `uninstall_package` | Uninstall by package name. |
| `logcat` | Last N log lines (1–1000), with optional substring filter. |
| `shell_readonly` | One read-only command from a strict allowlist: `getprop [name]`, `dumpsys battery`, `df [path]`, `ps [-A\|-e]`. Everything else is rejected before it reaches the device. |
Most tools accept an optional `serial`. When exactly one usable device is
attached it is selected automatically; with several, the serial is required
so commands are never ambiguous.
## Safety notes
- `shell_readonly` is the only free-form command surface, and it is
deliberately tiny: tokens are character-checked (no shell metacharacters)
and arguments are constrained per command.
- Package names for launch/uninstall are validated against the standard
package-name grammar.
- Text input escapes spaces and shell metacharacters for
`adb shell input text`.
- All adb calls have timeouts (30 s default, longer for installs) and
captured output is capped at 4 MiB.
## Development
```bash
.venv/bin/python -m pytest
```
The test suite needs no real device: it runs against a fake `adb`
executable (`tests/fake_adb.py`) that serves canned devices, properties,
screenshots, UI dumps, and logs, and it includes an end-to-end test that
spawns the server over stdio and calls its tools through a real MCP client.
## License
MIT — see [LICENSE](LICENSE).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues