Skip to content
Foxnet-LabPublic

About

On-device MCP server exposing a Shizuku-backed adb shell on 127.0.0.1:5556

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

ShellMCP

ShellMCP icon

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.

ShellMCP running state and live log

Highlights

  • 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_exec does anything, and dedicated tools exist only where they save context or return non-text (element-aware ui, image screenshot, binary file_read/file_write, named press_key, compact device_info). Everything else is a one-liner shell_exec recipe.
  • Shell identity is uid 2000 with groups such as adb, shell, sdcard_rw, and SELinux context u: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.

Quick start

  1. Install and start Shizuku (moe.shizuku.privileged.api) on the device.
  2. Install ShellMCP and open it.
  3. Grant Shizuku access when prompted (needed for the elevated shell).
  4. Tap START MCP. The status turns green and the button becomes red STOP MCP.
  5. Tap COPY URL to copy http://127.0.0.1:5556/mcp, or use the health check:
http://127.0.0.1:5556/health

Connecting a client

On the device

Point any MCP client that supports Streamable HTTP at:

http://127.0.0.1:5556/mcp

From a host over adb

adb forward tcp:5556 tcp:5556

Then 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.

Tools

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

shell_exec recipes

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" }
  }
}

Live log and UI

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.

Architecture

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.

Troubleshooting

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

Building

./gradlew :app:assembleDebug     # app/build/outputs/apk/debug/app-debug.apk
./gradlew :app:assembleRelease   # app/build/outputs/apk/release/app-release-unsigned.apk

Min 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.

Releases

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.

Credits

License

MIT - see LICENSE.

About

On-device MCP server exposing a Shizuku-backed adb shell on 127.0.0.1:5556

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages