dragon-touch-mcp
README.md
# dragon-touch-mcp
Control a Dragon Touch Android tablet from Claude over ADB via network.
Developed on the 27" TM27 model — should work on other Dragon Touch sizes (21", 32", etc.) since tab switching is based on Android resource IDs, not hardcoded coordinates.

## Requirements
- Node.js 18+
- `adb` in PATH — [Android SDK Platform Tools](https://developer.android.com/tools/releases/platform-tools) (macOS: `brew install android-platform-tools`)
- Tablet reachable over the network with ADB enabled (`adb tcpip 5555`)
## Add to Claude
```bash
claude mcp add dragon-touch -e DRAGON_TOUCH_IP=192.168.178.132 -- npx dragon-touch-mcp
```
Replace `192.168.178.132` with your tablet's IP address.
| Variable | Default | Description |
|---|---|---|
| `DRAGON_TOUCH_IP` | — | Tablet IP address (required) |
| `DRAGON_TOUCH_PORT` | `5555` | ADB port |
## Tools
| Tool | Description |
|---|---|
| `get_status` | Check adb, device connectivity, app installation, and the kiosk browser version |
| `get_device_info` | Read screen state (brightness, rotation, awake), audio volumes, battery, and device model |
| `get_app_settings` | Read app configuration from SharedPreferences (language, weather, sleep schedule, UI settings) |
| `set_brightness` | Set screen brightness (0–255) and disable auto-brightness |
| `set_volume` | Set media volume (0–15) |
| `get_active_tab` | Return the currently active tab/view |
| `capture_screen` | Take a screenshot of the tablet |
| `calendar_get_schedule` | Read all visible events from the current calendar view (day, week, or month) |
| `calendar_set_view` | Switch the calendar to day, week, month, or schedule view |
| `calendar_navigate` | Navigate the calendar forward or backward (1–30 steps, unit = active view) |
| `calendar_set_filter` | Show or hide family member profiles in the calendar filter |
| `open_url` | Open a URL fullscreen in the kiosk browser (optional: `downloadDir`) |
| `close_browser` | Close the kiosk browser |
| `install_kiosk` | Install or update the kiosk browser APK of this version (optional: `apkPath`) |
| `show_calendar` | Switch to Calendar tab |
| `show_tasks` | Switch to Tasks tab |
| `show_day` | Switch to Day tab |
| `show_meals` | Switch to Meals tab |
| `show_photos` | Switch to Photos tab |
| `show_lists` | Switch to Lists tab |
| `show_sleep` | Switch to Sleep tab |
| `show_goal` | Switch to Goal tab |
Tab switching uses Android resource IDs — works regardless of screen rotation or app language.
### Kiosk Browser
The Dragon Touch is primarily a family calendar and home dashboard device. The kiosk browser extends this by letting you display any web app on the tablet — fullscreen, no browser chrome, no address bar. This makes it possible to build custom web UIs (e.g. a React calendar, a home automation dashboard, or a digital photo frame) and push them to the tablet via MCP tools, without replacing or interfering with the native Dragon Touch app when not in use.
`open_url` opens a URL fullscreen; `close_browser` returns the tablet to whatever was running before. Both are controllable by Claude like any other tool.
`open_url` and `close_browser` require the Dragon Touch Kiosk Browser APK to be installed on the tablet.
> **Before installing:** Review the source code in `android/` yourself. Installing the APK modifies the tablet's running environment. **There is no guarantee the Dragon Touch will continue to function correctly afterwards**, as this interferes with the system.
Install or update the kiosk browser with the command that ships in the npm package:
```bash
DRAGON_TOUCH_IP=192.168.178.132 npx dragon-touch-mcp install_kiosk
```
The command downloads the signed APK of the same version from the [GitHub release](https://github.com/sveneisenschmidt/dragon-touch-mcp/releases), installs it, grants the `SYSTEM_ALERT_WINDOW` app-op and activates the device admin. A kiosk browser that was running before the update starts again with its last URL. The release workflow builds the APK from the tagged source.
`get_status` compares the installed kiosk browser with the version of the MCP server. After each npm update, run `install_kiosk` again when `get_status` reports a different version.
An APK from `make kiosk-install` is signed with the local debug key, the release APK with the release key. Android rejects an update across the two keys with `INSTALL_FAILED_UPDATE_INCOMPATIBLE`. To change from one to the other, uninstall the kiosk browser first:
```bash
adb shell dpm remove-active-admin com.dragontouch.kioskbrowser/.KioskAdminReceiver
adb uninstall com.dragontouch.kioskbrowser
```
To build and install from source instead:
```bash
make kiosk-install
```
**Requirements for a build from source:** Java, Gradle, and the Android SDK command line tools.
```bash
# macOS
brew install openjdk gradle --cask android-commandlinetools
# Ubuntu/Debian
apt install default-jdk gradle
# Android SDK: https://developer.android.com/studio#command-tools
```
Set `ANDROID_HOME` and `JAVA_HOME` if they differ from the defaults (see `Makefile`).
### Kiosk Makefile Targets
| Target | Description |
|---|---|
| `make kiosk-install` | Build the APK from source and install it on the tablet |
| `make kiosk-test` | Run the kiosk browser unit tests (no device required) |
| `make kiosk-open` | Open the URL defined by `KIOSK_URL` in the kiosk browser |
| `make kiosk-close` | Stop the kiosk browser |
| `make kiosk-provision KIOSK_APP_SRC=./dist` | Copy a local web app to the tablet and open it |
| `make kiosk-demo` | Push and open the built-in demo app (see `demo/kiosk/`) |
| `make kiosk-screenshot` | Take a screenshot and open it locally |
| `make kiosk-list-files` | List files in the kiosk app directory on the tablet |
| `make kiosk-pull-downloads` | Pull downloaded files from the tablet to `./downloads/` |
The `kiosk-provision` target copies the contents of `KIOSK_APP_SRC` to `/sdcard/kiosk-app/` on the tablet and opens `index.html`. Override the destination with `KIOSK_APP_DEST`.
| Variable | Default | Description |
|---|---|---|
| `KIOSK_APP_SRC` | — | Local path to the web app directory (required for `kiosk-provision`) |
| `KIOSK_APP_DEST` | `/sdcard/kiosk-app` | Destination directory on the tablet |
| `KIOSK_DOWNLOAD_DIR` | `/sdcard/kiosk-downloads` | Directory on the tablet where downloads are saved |
| `KIOSK_URL` | `https://sven.eisenschmidt.website` | URL to open with `kiosk-open` |
### Foreground Behavior
When the kiosk browser is open, it runs a foreground service (`KioskService`) that keeps it visible through three mechanisms:
- **Screen-on**: when the tablet wakes up (e.g. at the wake time of the [screen schedule](#screen-schedule)), the kiosk browser returns to the foreground.
- **Watchdog**: every 5 seconds the service checks whether the kiosk activity lost the foreground while the screen is on, and reclaims it. This defends against other apps bringing themselves to the front.
- **Boot autostart**: a `BOOT_COMPLETED` receiver relaunches the kiosk after a reboot (e.g. power loss), restoring the last URL from SharedPreferences. Note: this ROM silently drops plain service starts from boot receivers, so the receiver starts the activity directly.
The service is started automatically when `open_url` is called and runs until `close_browser` stops the app.
Reclaiming the foreground and the boot autostart require an exemption from Android 10's background-activity-start restrictions. The kiosk browser uses the `SYSTEM_ALERT_WINDOW` app-op for this, which `install_kiosk` and `make kiosk-install` grant automatically. It persists across reboots; after a factory reset or fresh install, re-grant it with:
```bash
adb shell appops set com.dragontouch.kioskbrowser SYSTEM_ALERT_WINDOW allow
```
### Screen Schedule
The kiosk browser turns the screen off at 22:00 and on at 06:00 every day. This replaces the sleep timer of the stock app, which is disabled (see [below](#stock-firmware-app-comfujiacalendar)).
- **Sleep**: an alarm calls `DevicePolicyManager.lockNow()`, which turns the screen off. The lock screen is disabled on the tablet, so no lock screen shows on wake.
- **Wake**: an alarm acquires a wake lock with `ACQUIRE_CAUSES_WAKEUP`, which turns the screen on. The kiosk browser then returns to the foreground.
A reboot or a force-stop deletes the alarms. The kiosk activity schedules them again on every start, so `open_url` and the boot autostart restore them.
`lockNow()` needs an active device admin. `install_kiosk` and `make kiosk-install` activate it. After a factory reset or fresh install, activate it with:
```bash
adb shell dpm set-active-admin com.dragontouch.kioskbrowser/.KioskAdminReceiver
```
An active device admin blocks `pm uninstall`. The APK is marked `testOnly`, so adb can remove the admin before an uninstall (e.g. after a signature mismatch):
```bash
adb shell dpm remove-active-admin com.dragontouch.kioskbrowser/.KioskAdminReceiver
```
Android stores the `testOnly` flag when it activates the admin. An admin activated by an older APK without the flag cannot be removed this way. Deactivate it once in Settings > Security > Device admin apps, then activate it again with `dpm set-active-admin`.
To change the times, start the kiosk with the `sleepAt` and `wakeAt` extras in `HH:mm` format. The kiosk browser stores them, and later starts without these extras keep them:
```bash
adb shell am force-stop com.dragontouch.kioskbrowser
adb shell am start -n com.dragontouch.kioskbrowser/.MainActivity --es sleepAt 21:30 --es wakeAt 06:30
```
### Stock Firmware App (com.fujia.calendar)
The Dragon Touch stock calendar app (`com.fujia.calendar`, runs with system UID) aggressively takes over the tablet: after a mid-2026 firmware update it brought itself to the foreground every few minutes **and force-stopped the kiosk browser roughly every 15–20 minutes**. A force-stop kills the kiosk service and cancels its restart, so no in-app mechanism can defend against it.
The stock app is therefore **disabled** on the tablet:
```bash
adb shell pm disable-user --user 0 com.fujia.calendar
```
This is a user-level setting — it does not modify the system partition and cannot brick the device.
**Restoring the original firmware behavior** (stock calendar active again):
```bash
# 1. Re-enable the stock app
adb shell pm enable com.fujia.calendar
# 2. Stop the kiosk browser (also stops watchdog and boot autostart)
adb shell am force-stop com.dragontouch.kioskbrowser
# 3. Optional: uninstall the kiosk browser entirely.
# The active device admin blocks the uninstall, so remove it first.
adb shell dpm remove-active-admin com.dragontouch.kioskbrowser/.KioskAdminReceiver
adb shell pm uninstall com.dragontouch.kioskbrowser
# 4. Reboot — the stock app takes over again
adb reboot
```
A factory reset also restores everything, including the stock app.
**Known ROM quirks** (pre-existing vendor bugs, unrelated to this project):
- `FallbackHome` crashes at boot because the ROM references a missing `com.waophoto.fota` activity. Harmless — the boot autostart brings the kiosk up regardless.
- The device has no resolvable HOME activity even with the stock app enabled.
- adb over TCP is always on (`persist.adb.tcp.port=5555`, `ro.adb.secure=0`) and adbd runs as root.
### Building Notes
Gradle incremental builds have produced stale APKs for this project (new manifest merged with partially old code, missing services). Always build clean:
```bash
cd android && gradle clean assembleDebug
```
Unit tests for the screen schedule logic run on the JVM, without a device:
```bash
make kiosk-test
```
### Downloads
The kiosk browser supports file downloads. Files are saved to `KIOSK_DOWNLOAD_DIR` on the tablet (default: `/sdcard/kiosk-downloads`). Pull them to your local machine with:
```bash
make kiosk-pull-downloads
```
Files are saved to `./downloads/` (git-ignored). Override the source directory:
```bash
make kiosk-pull-downloads KIOSK_DOWNLOAD_DIR=/sdcard/my-downloads
```
### Kiosk Demo
`demo/kiosk/` contains a minimal static web app that verifies the kiosk browser environment:
- **CSS** — flexbox layout, colors
- **JavaScript** — arrow functions, array methods
- **localStorage** — read/write
- **Local file access** — XHR fetch of a local JSON file
```bash
make kiosk-demo
```
> Note: `fetch()` is unreliable for `file://` URLs in the tablet's WebView (version 74). Use `XMLHttpRequest` instead when loading local files. Remote HTTP requests work normally.
>
> The manifest sets `usesCleartextTraffic`, so the WebView also loads plain `http://` URLs, such as a calendar feed or a dashboard on the LAN. Without it, Android blocks them since target SDK 28, and an XHR to one fails with a network error.
## CLI Usage
Every tool is also available as a CLI command — useful for scripting and automation without an MCP client.
```bash
# No payload needed
DRAGON_TOUCH_IP=192.168.178.132 npx dragon-touch-mcp show_calendar
DRAGON_TOUCH_IP=192.168.178.132 npx dragon-touch-mcp get_status
# With --ip flag
npx dragon-touch-mcp --ip 192.168.178.132 show_tasks
# capture_screen saves a PNG file (default: ./dragon-touch-capture.png)
DRAGON_TOUCH_IP=192.168.178.132 npx dragon-touch-mcp capture_screen
DRAGON_TOUCH_IP=192.168.178.132 npx dragon-touch-mcp capture_screen '{"output": "/tmp/shot.png"}'
```
All commands output JSON to stdout and errors to stderr. Exit code `0` on success, `1` on error.
## Development
```bash
git clone https://github.com/sveneisenschmidt/dragon-touch-mcp.git
cd dragon-touch-mcp
npm install
npm run build # compile TypeScript
npm test # run unit tests
npm run inspect # MCP Inspector at http://localhost:5173
npm run dev # watch mode
```
On macOS/Linux a `Makefile` is also available with the same targets plus `make clean`.
## Contributing
See [AGENTS.md](AGENTS.md) for architecture and conventions.
## License
MIT
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues