Why Android Camera MCP?
- LAN-First & Private: Control messages, JPEG frames, and on-device ML Kit analysis stay strictly inside your local Wi-Fi/LAN. No cloud relays, accounts, or subscriptions.
- Decoupled Gateway Daemon & Multi-Phone Registry: Run
python main.py gatewayonce (:8765for phones,127.0.0.1:8766for local MCP clients). Restarting an AI client or running several clients at once never drops the phone connection, and multiple phones can connect concurrently. - On-Device Scene Analysis (
camera_analyze): Runs offline ML Kit OCR, QR/barcode scanning, and exposure/sharpness stats directly on the phone, returning compact JSON with normalizedx,y,w,hbounding boxes — no large image transfer needed just to read a label or meter. - Phone-Side ROI Crop & Capture Presets: Pass normalized
crop_x/y/w/hto crop from the full sensor before upload (paired withzoom_ratioorcamera_preview/camera_analyze), plus namedpresetprofiles (general,document,macro,low_light). - Background & Screen-Off Operation: CameraX is bound to an Android
LifecycleServiceforeground service (FOREGROUND_SERVICE_TYPE_CAMERA) with wake and Wi-Fi locks, automatic reconnect on network change, and an in-app Allow background running shortcut. - Observability & LAN Discovery: Built-in mDNS/NSD discovery (
_android-camera-mcp._tcp+ Discover button), per-command timing breakdown, phone-side SQLite log viewer, and automatic log sync to~/.android-camera-mcp/device-logs/.
Architecture
┌───────────────────────────────────────────────┐
│ Android Camera Agent (v0.5.0) │ Kotlin · CameraX · LifecycleService
│ Capture · ROI crop · Live frames · ML Kit OCR │ SQLite TraceLog · NSD Discover
└──────────────────────┬────────────────────────┘
│ Persistent TCP :8765 (4B length + 1B kind + payload)
│ 0x01 JSON control/logs + 0x02 binary JPEG
▼
┌───────────────────────────────────────────────┐
│ Camera Gateway Daemon │ python main.py gateway
│ Multi-device registry · FIFO queue · mDNS │ Stream buffer · Device log store
└──────────────────────┬────────────────────────┘
│ Local Control API (127.0.0.1:8766)
▼
┌───────────────────────────────────────────────┐
│ MCP Server (stdio) │ python main.py mcp (one per AI client)
│ 15 typed FastMCP camera tools │
└──────────────────────┬────────────────────────┘
│ MCP over stdio
▼
┌───────────────────────────────────────────────┐
│ Antigravity · Claude · Cursor · Kiro │
└───────────────────────────────────────────────┘
Quick Start
Install the Android APK
Scan the QR code below or pick a versioned APK from GitHub Releases (Android 10+).
Run the Gateway Daemon
Start python main.py gateway on your LAN machine (:8765 for phones, 127.0.0.1:8766 for MCP clients, optional zeroconf for mDNS).
Connect Phone & AI Client
Register python main.py mcp in Antigravity / Claude / Cursor / Kiro, tap Discover (or enter LAN IP) and Connect on the phone.
1. Scan QR Code to Download APK
Every build on main publishes an immutable versioned release (v0.5.0-b<run>-<sha>) with SHA-256 checksums, plus updates the rolling latest-debug QR code below:
2. Set Up & Start the Python Gateway
Requires Python 3.10+ (requirements.txt pins mcp<2 for the MCP Python SDK 1.x FastMCP API).
git clone https://github.com/sinhsac/android-camera-mcp.git
cd android-camera-mcp/server
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
# Optional: enable mDNS LAN discovery (Discover button on Android)
pip install zeroconf
# Keep the gateway running (phone port 8765, local API 127.0.0.1:8766)
python main.py gateway
# Optional: verbose logs + rotating log file
python main.py gateway --log-file ~/.android-camera-mcp/gateway.log -v
3. Configure Your MCP Client
Antigravity CLI:
agy mcp add android-camera \
/absolute/path/to/android-camera-mcp/server/.venv/bin/python \
/absolute/path/to/android-camera-mcp/server/main.py mcp
Claude Desktop, Cursor, or Kiro (mcpServers JSON):
{
"mcpServers": {
"android-camera": {
"command": "/absolute/path/to/android-camera-mcp/server/.venv/bin/python",
"args": ["/absolute/path/to/android-camera-mcp/server/main.py", "mcp"]
}
}
}
On Windows, set "command" to C:\\path\\to\\android-camera-mcp\\server\\.venv\\Scripts\\python.exe. If the gateway daemon is not running, tools cleanly report GATEWAY_UNAVAILABLE.
4. Connect the Phone
- Open Android Camera Agent and grant Camera permission (plus Notifications on Android 13+).
- Tap Discover to find the gateway automatically via mDNS (when
zeroconfis installed), or enter your computer's LAN IP and port8765manually, then tap Connect. - Optional: tap Allow background running to exempt the app from battery optimization, and All logs to inspect the on-device SQLite trace database.
- Tap Test capture to verify locally, or ask your AI: "List my connected Android cameras, analyze the scene for text or QR codes, and capture a tight crop."
Recommended AI Framing Workflow
- Read text / labels / QR codes: call
camera_analyzefirst (runs offline on the phone, returns OCR text, barcodes, exposure/focus hints, and normalizedx,y,w,hboxes without sending a large image). - Inspect a fine detail: call
camera_preview(orcamera_analyze) → pickcrop_x/y/w/h→ callcamera_capture(crop_*=..., max_dimension=1600)(optionally withzoom_ratioorpreset="document"). - Monitor a scene briefly: call
camera_stream_start→ pollcamera_stream_frame(after_sequence=...)→ callcamera_stream_stop(auto-stops after duration or idle timeout).
Available MCP Tools (15)
| Category | Tool | Description |
|---|---|---|
| Discovery | camera_list |
List connected Android agents, online/stale status, active camera, lenses, battery, and thermal health. |
| Discovery | camera_info |
Inspect per-camera capabilities (zoom/EV ranges, flash, manual focus, max JPEG size, presets), stream state, and FIFO queue depth. |
| Discovery | camera_status |
Fetch live phone state, active camera, battery %, charging, temperature, thermal level, uptime, and timing breakdown. |
| Analysis | camera_analyze |
On-device offline ML Kit OCR + barcode/QR scanning + exposure/focus stats (dark|ok|bright, blurry|soft|sharp) and normalized x,y,w,h boxes; supports optional crop_*, still=true, and include_image=true. |
| Capture | camera_capture |
Capture an upright JPEG still (1600px long edge default; max_dimension=0 for full sensor) with optional preset (general|document|macro|low_light), phone-side ROI crop_x/y/w/h, and per-shot camera controls. |
| Capture | camera_preview |
Fast low-resolution frame (640px default) from the live feed with optional phone-side crop_* to check framing before a full capture. |
| Streaming | camera_stream_start |
Start a temporary low-FPS live stream with automatic duration and idle timeout limits. |
| Streaming | camera_stream_frame |
Return the newest buffered stream frame; pass after_sequence to wait for a newer frame. |
| Streaming | camera_stream_stop |
Stop an active stream on the device (idempotent). |
| Controls | camera_set_zoom |
Set zoom ratio on the active camera (clamped to supported range, including ultra-wide <1.0x). |
| Controls | camera_set_torch |
Toggle continuous flashlight/torch on or off. |
| Controls | camera_set_flash |
Set flash mode (off, auto, on) for subsequent captures. |
| Controls | camera_set_focus |
Configure continuous AF, one-shot auto AF, or manual focus distance (0.0–1.0). |
| Controls | camera_set_exposure |
Set EV compensation steps or omit value to restore auto exposure (0). |
| Controls | camera_select_lens |
Switch active camera/lens by camera_id and refresh advertised capabilities. |
CLI Options & Server Tests
# Gateway daemon options
python main.py gateway \
--host 0.0.0.0 --port 8765 \
--api-host 127.0.0.1 --api-port 8766 \
--min-capture-interval 1.5 --max-queue 4 \
--log-file ~/.android-camera-mcp/gateway.log -v
# Add --no-mdns to disable _android-camera-mcp._tcp advertisement
# MCP stdio server (default subcommand)
python main.py mcp --api-host 127.0.0.1 --api-port 8766
# Run automated server test suite (real TCP sockets)
cd server
pip install -r requirements.txt pytest
python -m pytest -q
Security, Power & Troubleshooting
The local control API binds strictly to 127.0.0.1:8766, while the device TCP listener on :8765 intentionally uses no pairing token for personal trusted-LAN simplicity. Allow inbound TCP 8765 only from your local subnet and do not expose it to the public internet.
- Battery & OEM Background Killing: The foreground service holds a partial wake lock and Wi-Fi lock while connected. Plug the phone into power for extended sessions and tap Allow background running in the app to exempt it from aggressive battery optimization on Samsung, Xiaomi, or Oppo devices.
- Per-Device FIFO Queue & Pacing: Commands for the same phone run in FIFO order (
--max-queue 4by default) and early captures automatically wait for the--min-capture-intervalcooldown (~1.5s) instead of failing.RATE_LIMITEDis only returned when the queue is full. - Device Logs & Crash Reports: The phone records trace logs in SQLite (viewable via All logs) and automatically uploads unsynced entries to
~/.android-camera-mcp/device-logs/<device_id>/logs.jsonlon the gateway host. - Building Android From Source: Requires JDK 17 and Android SDK (
compileSdk 35,minSdk 29). Run./gradlew assembleDebugfrom the repository root.