adb-door
by panii8
README.md
# adb-door
An [MCP](https://modelcontextprotocol.io) server that lets an AI agent use the
tools **an Android app declares for itself**, over the USB cable.
Most Android MCP servers drive the phone like a finger: screenshots, taps,
swipes. This one does something different. The app itself says "here are the
things you can ask me to do" (read my agenda, add a task, reorder my goals),
and the agent calls them directly, with no UI in the loop.
```
AI agent ──MCP──▶ adb-door (PC) ──adb, USB──▶ ContentProvider "door" (in your app) ──▶ your code
```
## Why a door and not a screen
- **Fast and exact.** A tool call is a JSON document, not a sequence of taps.
- **Your contract.** The app declares its tools in code. A new tool shows up in
the agent without changing this server.
- **Locked to the cable.** The door obeys only `adb shell`. See
[Security](#security).
- **Undoable by design.** Every call carries a conversation id, so your app can
log what the agent wrote and let the user undo the whole conversation at once.
(Your app implements that part; the server just sends the id.)
## What is in this repository
| Path | What |
|---|---|
| `src/adb_door/` | The MCP server (Python, runs on your computer). |
| `android/AdbDoorProvider.kt` | The door: an abstract `ContentProvider` you copy into your app. |
| `android/ExampleDoor.kt` | The smallest working door: one tool, `hello`. |
| `docs/PROTOCOL.md` | The wire contract your app implements. |
| `tests/` | Server tests, no phone needed. |
## Quick start
### 1. In your Android app
Copy `android/AdbDoorProvider.kt` into your project (change its `package` line)
and write a subclass that implements `handle`. `android/ExampleDoor.kt` is a
complete one.
Declare it in `AndroidManifest.xml`:
```xml
<provider
android:name=".ExampleDoor"
android:authorities="com.example.adbdoor.door"
android:exported="true"
android:permission="android.permission.DUMP" />
```
`android:exported="true"` together with `android:permission` is what makes the
first wall work: only callers holding `DUMP` get through, and only `adb shell`
has it. Do not remove either.
If your app is built with Flutter, call into Dart from `handle` through a
`MethodChannel` and keep the contract in Dart, so the tools live next to the rest
of your code. Serve the door from the same engine as the UI, never from a second
one.
### 2. On your computer
Plug the phone in and accept USB debugging. You need [uv](https://docs.astral.sh/uv/)
and `adb` (Android SDK platform-tools).
**Install today: from a clone.** The package is not on PyPI yet, so `uvx adb-door`
does not work yet. Clone this repository and point your MCP client at it. For
Claude Code, in `.mcp.json`:
```json
{
"mcpServers": {
"myapp": {
"command": "uv",
"args": ["run", "--quiet", "--directory", "/path/to/adb-door", "adb-door"],
"env": {
"ADB_DOOR_AUTHORITY": "com.example.adbdoor.door",
"ADB_DOOR_NAME": "My App"
}
}
}
}
```
Replace `/path/to/adb-door` with where you cloned it (on Windows, use forward
slashes or doubled backslashes). Once the package is published on PyPI, the
`command` and `args` will become `"uvx"` and `["adb-door"]`.
### Settings
All through environment variables:
| Variable | Default | Meaning |
|---|---|---|
| `ADB_DOOR_AUTHORITY` | required | The provider authority from your manifest. |
| `ADB_DOOR_NAME` | the authority | Name shown in error messages and used as the MCP server name. |
| `ADB_DOOR_SERIAL` | none | Which phone, when more than one is plugged in (`adb devices`). |
| `ADB_DOOR_ADB` | `adb` on `PATH`, then the SDK's `platform-tools` | Path to adb. |
| `ADB_DOOR_INSTRUCTIONS` | built-in text | A path to a text file, or the text itself, given to the agent as server instructions. |
## Security
Read this before you ship a door in a real app. It opens a privileged path into
the app, and the cable is the only thing that guards it.
- **Two walls.** The manifest requires `android.permission.DUMP` (held by
`adb shell`, not obtainable by installed apps). The code also requires the
caller to be uid 2000, `shell`. Either wall alone is weaker: the first can be
granted to another app with `pm grant`, the second is not enforced until the
call arrives.
- **Whoever has `adb` to the phone can use the door.** That means anyone with an
authorized computer and the phone unlocked for debugging, and also wireless
debugging if you turn it on. Keep USB debugging off when you do not need it.
- **Treat tool results as data, not instructions.** An agent that reads text out
of your app (a note, a title) may be tricked by text that says "now do X". The
server's default instructions say so, but the real safety net is on your side:
log every write and make it undoable. Do not give the agent web or email tools
in the same session if the door can write.
- **Never put secrets in tool results** you would not paste in a chat.
- **A timeout is not "nothing happened".** The app may finish a write after the
server gave up waiting. The server says so; make your tools safe to inspect
before retrying.
Report vulnerabilities as described in [SECURITY.md](SECURITY.md).
## Status
Early, alpha. The design comes from three apps that have used it daily; this
repository is the generalized version.
What has been tested, and on what:
- **Server:** 28 tests that run without a phone, on Python 3.14. An end-to-end
run through a real MCP client with a fake `adb` listed and called a tool.
- **Android files:** `AdbDoorProvider.kt` and `ExampleDoor.kt`, copied unchanged
into a fresh Flutter app, compiled and ran on a physical phone (Motorola Razr
60 Ultra, Android 16, USB debugging). The server listed the tool, called it,
sent a 100 KB request, and got a clear error for an unknown tool.
- **Both walls:** a second installed app, with `DUMP` requested in its manifest,
was rejected by the system. After `DUMP` was granted to it by hand with
`adb shell pm grant`, it was rejected by the uid check.
What has **not** been tested:
- Other Android versions or devices, other manufacturers, and work profiles or
secondary users (the uid check is written to handle them, but it was only run
on the main profile).
- Python versions other than 3.14. `pyproject.toml` says 3.10 or later because
that is what the `mcp` package requires.
- Calling the door while the app is not running. The example door answers in
plain Kotlin, so it does not exercise cold start. If your handler needs an
engine such as Flutter's, test that path yourself.
- macOS and Linux for the server. The code does not depend on Windows.
If something is off, please open an issue with your Android version and the
`adb logcat -s AdbDoor` output.
## Development
```
uv run pytest
```
## License
MIT, see [LICENSE](LICENSE).