An on-device MCP server that gives agents a real adb shell.
ShellMCP runs as an Android app and exposes a Model Context Protocol
endpoint on loopback only. Tools execute through Shizuku
as uid 2000 (the shell user), so an agent running on the phone gets adb-level
file and command access without a host PC, root, or a USB cable.
- Streamable HTTP MCP at
http://127.0.0.1:5556/mcp(POST), built with the official Kotlin MCP SDK and Ktor CIO. - 9 curated tools with a deliberately small surface:
shell_execdoes anything, and dedicated tools exist only where they save context or return non-text (element-awareui, imagescreenshot, binaryfile_read/file_write, namedpress_key, compactdevice_info). Everything else is a one-linershell_execrecipe. - Shell identity is
uid 2000with groups such asadb,shell,sdcard_rw, and SELinux contextu:r:shell:s0(not the app UID). - Foreground service keeps the server alive; the UI shows running state, a start/stop toggle, a copyable URL, and a live diagnostic log.
- Loopback only - the server never binds to Wi-Fi or LAN interfaces.
- Install and start Shizuku (
moe.shizuku.privileged.api) on the device. - Install ShellMCP and open it.
- Grant Shizuku access when prompted (needed for the elevated shell).
- Tap START MCP. The status turns green and the button becomes red STOP MCP.
- Tap COPY URL to copy
http://127.0.0.1:5556/mcp, or use the health check:
http://127.0.0.1:5556/health
Point any MCP client that supports Streamable HTTP at:
http://127.0.0.1:5556/mcp
adb forward tcp:5556 tcp:5556Then use http://127.0.0.1:5556/mcp in the host client, for example:
{
"mcpServers": {
"shellmcp": {
"url": "http://127.0.0.1:5556/mcp"
}
}
}The phone must stay awake/unlocked for UI tools (
screenshot,ui_dump) to be useful. The foreground service keeps the process alive; a partial wake lock prevents CPU suspension while the server is running.
| Tool | Arguments | What it does |
|---|---|---|
shell_exec |
command, optional timeout_ms |
Run any command as uid 2000 - the main workhorse. Output capped at ~96 KB. |
ui |
action, text/desc/id/clazz, index, x,y, direction, max_swipes, wait_ms, redact |
Element-aware UI. Actions: find, tap_element, tap_and_wait, scroll_to. Returns compact JSON with centers - no pixel guessing, minimal context. |
ui_dump |
optional raw, redact |
Compact JSON node list of the current screen (raw uiautomator XML opt-in). |
screenshot |
- | Return a PNG as MCP image content |
file_read |
path, optional base64, redact |
cat a file as text or base64; PII redaction available |
file_write |
path, content_base64 |
Write a file from base64 content |
press_key |
key |
Named key event: home, back, recents, enter, tab, del, power, volume_up/down, dpad_*, menu, search, ... (or raw keycode int) |
input |
args |
Low-level input passthrough, e.g. tap 500 1200, swipe 500 800 500 300 200, text hello |
device_info |
- | Compact JSON: model, Android, SDK, ABI, serial, display, battery, memory, focus |
Everything below is a shell_exec (or two), because a MCP tool
wrapper would only add schema context. Quote grep patterns (grep -E "level:|status:").
| Goal | Command |
|---|---|
| Logcat tail | logcat -d -t 200 |
| Logcat filtered | logcat -d -s TAG:* or logcat -d | grep -i wifi |
| Clear logcat | logcat -c |
| Crash log | logcat -d -b crash -t 200 |
| Battery | `dumpsys battery | grep -E "level: |
| Display | wm size; wm density |
| Wi-Fi | cmd wifi status (SSID, RSSI, link speed) |
| Bluetooth | `dumpsys bluetooth_manager | grep -iE "mState |
| Cell tower | dumpsys telephony.registry | grep -oE "mOperatorAlphaLong=[^,]*|getRilDataRadioTechnology=[0-9A-Za-z()]+|ssRsrp = -?[0-9]+|mMcc = [0-9]+|mMnc = [0-9]+" | head -20 |
| Network | `ip -4 addr show | grep -E "^[0-9]+: |
| Install APK | pm install -r /data/local/tmp/app.apk |
| Uninstall | pm uninstall -k com.example.app |
| Grant permission | pm grant com.example.app android.permission.CAMERA |
| Clear app data | pm clear com.example.app |
| Launch app | monkey -p com.example.app -c android.intent.category.LAUNCHER 1 |
| Force stop | am force-stop com.example.app |
| Current activity | dumpsys window | grep mCurrentFocus |
| List dir | ls -la /sdcard/Download |
| Screen record (10 s) | screenrecord --time-limit 10 /data/local/tmp/rec.mp4 |
| Package info | `dumpsys package com.example.app | grep -E "versionName |
Example MCP call:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "shell_exec",
"arguments": { "command": "id; whoami" }
}
}The lower pane is a live diagnostic log:
- Server start/stop events carry a short run ID, e.g.
MCP #478dfc25 starting,MCP #478dfc25 listening,MCP #478dfc25 stopped, releasing engine. - Every tool invocation is logged with its duration, e.g.
MCP/I screenshot 626ms. - The log is selectable (long-press for Copy / Share / Select all), with COPY LOGS and CLEAR LOGS buttons. It buffers the last 200 entries and resets when the app process restarts.
The UI is edge-to-edge compliant and targets Android 15+ behavior.
MCP client
| Streamable HTTP (POST /mcp), 127.0.0.1:5556
v
Ktor CIO server -> Kotlin MCP SDK Server (tool registry)
|
v
AdbShell / ShizukuProcess
| IShizukuService.newProcess (AIDL)
v
sh (uid 2000, u:r:shell:s0)
The shell layer is derived from ShellBox.
Shizuku 13.x exposes newProcess on the AIDL interface but the published 13.1.5
API facade does not wrap it, so ShellMCP calls the AIDL directly.
| Symptom | Fix |
|---|---|
SHIZUKU NOT READY |
Start Shizuku, open ShellMCP, tap GRANT SHIZUKU |
| Server won't start / port refused | Another process owns 5556; stop it and tap START MCP again |
| Notification not visible | Grant notifications; the service still runs without it |
| Debug build shows 16 KB warning | Debug includes unaligned native libs; use the signed release |
screenshot / ui_dump empty |
Unlock the screen and ensure the device is awake |
./gradlew :app:assembleDebug # app/build/outputs/apk/debug/app-debug.apk
./gradlew :app:assembleRelease # app/build/outputs/apk/release/app-release-unsigned.apkMin SDK 26, compile SDK 36, Kotlin 2.4, AGP 8.7, Gradle 8.13. R8 is disabled in release builds to preserve reflection targets in the terminal/JNI-derived code.
Signed releases are published at github.com/Foxnet-Lab/shellmcp/releases. Release APKs are signed with the XNet upload key and 16 KB page aligned.
- Shell execution layer derived from ShellBox.
- Protocol layer: official Kotlin MCP SDK.
- Elevated shell: Shizuku.
MIT - see LICENSE.
