Skip to main content
Glama
README.md
<div align="center">

<br/>

<a href="https://github.com/shadjosef/pad-study-mcp">
  <img src="docs/assets/brand-icon.png" alt="pad-study-mcp" width="116" height="116" />
</a>

<h1>pad-study-mcp</h1>

<p>
  <strong>Let AI coding &amp; study agents read your live handwritten notes off any Android tablet — privately, sharply, and with zero cursor hijacking.</strong><br/>
  Built for university math, accounting, finance, and STEM problem sets: fail-closed multi-window privacy gate, orientation-aware smart ink auto-crop, and 0 KB ETag unchanged diffing over USB-C, Wi-Fi, or Tailscale ADB.<br/>
  macOS · Windows · Linux · Antigravity · Codex · Claude Code · Cursor · <a href="https://github.com/shadjosef/study-os">Study-OS</a>
</p>

<p>
  <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-147d64?style=flat-square&labelColor=334155" alt="License: MIT" /></a>
  <img src="https://img.shields.io/badge/python-3.10%2B-147d64?style=flat-square&labelColor=334155" alt="Python 3.10+" />
  <img src="https://img.shields.io/badge/transport-USB--C%20%C2%B7%20Wi--Fi%20%C2%B7%20Tailscale-147d64?style=flat-square&labelColor=334155" alt="USB-C, Wi-Fi, and Tailscale ADB" /><br/>
  <img src="https://img.shields.io/badge/privacy-Fail--Closed%20All--Window%20Gate-0f5f4c?style=flat-square&labelColor=334155" alt="Fail-Closed Multi-Window Privacy" />
  <img src="https://img.shields.io/badge/tests-21%20passing-0f5f4c?style=flat-square&labelColor=334155" alt="21 pytest tests passing" />
  <a href="https://github.com/shadjosef/pad-study-mcp/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/shadjosef/pad-study-mcp/ci.yml?style=flat-square&label=CI&labelColor=334155" alt="pad-study-mcp CI" /></a>
</p>

<p>
  <a href="#quick-start"><img src="https://img.shields.io/badge/QUICK%20START%20WITH%20UVX-147d64?style=for-the-badge&logo=python&logoColor=white" alt="Quick Start with uvx" /></a>
  <a href="SECURITY.md"><img src="https://img.shields.io/badge/SECURITY%20%26%20PRIVACY%20MODEL-334155?style=for-the-badge&logo=shield&logoColor=white" alt="Security and Privacy Model" /></a>
</p>

<p>
  <a href="#smart-ink-auto-crop">Smart Ink Auto-Crop</a> ·
  <a href="#fail-closed-multi-window-privacy-gate">Privacy Gate</a> ·
  <a href="#tools--diagnostics">Tools &amp; Doctor CLI</a> ·
  <a href="#how-its-built">How it's built</a> ·
  <a href="#quick-start">Quick Start</a> ·
  <a href="#supported-tablets--study-apps">Supported Apps</a> ·
  <a href="#configuration">Configuration</a>
</p>

<br/>

<img src="docs/assets/hero-showcase.png" alt="pad-study-mcp end-to-end study workflow — Android tablet infinite canvas auto-cropped by pad_peek() and checked live inside Antigravity, Codex, or Claude Code" width="900" />

<p><sub>Write on your Android tablet with a stylus, ask "is step 3 right?" in Antigravity / Codex / Claude Code — <code>pad_peek()</code> verifies every visible window, crops straight to your handwriting (~24 KB), and returns instant feedback with zero copy-pasting.</sub></p>

</div>

> [!NOTE]
> **Built for real exam prep alongside [Study-OS](https://github.com/shadjosef/study-os).** Works with **Samsung Galaxy Tab, Xiaomi Pad, OnePlus Pad, Boox, and Pixel Tablet** running AOSP, OneUI, HyperOS, or OxygenOS. Runs **100% locally over stdio** — zero cloud relays, zero background Android agent APKs, and zero desktop cursor hijacking.

---

## Why This Exists

General mobile-automation MCP servers are built for tapping UI buttons, not for letting an AI tutor proactively glance at your handwritten math or accounting work while you study:

| Problem with raw screenshots | How `pad-study-mcp` solves it |
| :--- | :--- |
| **Privacy leaks** — a floating chat bubble, split-screen banking app, autofill overlay, or pulled-down notification shade leaks into the model context. | **Fail-closed all-window gate** inspects wake/lock state and every visible Android `Window #N` (`FLAG_SECURE`, `NotificationShade`, `BiometricPrompt`, split-screen, PiP) **before** a single pixel is captured. |
| **Tiny, blurry handwriting** — a `3200×2136` infinite canvas is ~80% blank paper and toolbars, so vision downscaling turns `-` signs and exponents into mush. | **Orientation-aware ink auto-crop** strips toolbars, ruled lines, dark PDF gutters, and corner nav pills — zooming handwriting **~2.5× larger** while cutting payload size by **~84%** (`~150 KB → ~24 KB`). |
| **Context bloat on follow-ups** — re-sending the same full-page image on every "why?" follow-up burns vision tokens and triggers context compaction. | **Status-bar-immune ETag diff (`if_changed_since`)** skips sending image bytes (`0 KB`) when your canvas hasn't changed, while still catching a single minus sign or decimal edit. |
| **Flaky wireless ADB** — switching between desk USB-C and campus/couch Tailscale Wi-Fi leaves stale `offline` devices. | **USB → Wi-Fi / Tailscale auto-reconnect** prefers USB-C when plugged in, falls back to your wireless/Tailscale target automatically, and recovers stale `offline` sessions cleanly. |

---

## Smart Ink Auto-Crop

<p align="center">
  <img src="docs/assets/autocrop-compare.png" alt="Before vs After comparison of raw 3200x2136 tablet screencap (~150 KB) versus pad_peek() Smart Ink Auto-Crop (~24 KB)" width="880" />
</p>
<p align="center"><sub>Raw 3.2K tablet canvas (left) vs. <code>pad_peek()</code> smart ink crop (right): thin 2px strokes, colored dark-mode ink, yellow highlighters, and portrait page headers stay intact while toolbars, ruled lines, dark PDF gutters, and corner nav pills vanish.</sub></p>

- **Two-pass ruled-line suppression** removes full-width notebook rules and graph grids without erasing horizontal fraction bars, minus signs, or T-account dividers.
- **Moat-checked corner pill filtering** ignores floating infinite-canvas navigation pills (`← ⌖ →`) only when isolated by clean whitespace, so genuine writing in the top-right corner is never clipped.
- **Dark-mode & highlighter aware** using `ImageChops` + `MaxFilter(3)` background-delta detection rather than naive luminance thresholding.
- **Zero-token unchanged follow-ups:** every `pad_peek` response includes a `canvas_hash` computed over the cropped ink region (immune to clock ticks and battery changes); pass it back as `if_changed_since` on the next turn to receive `{"status": "unchanged"}` with `0` image bytes.

---

## Fail-Closed Multi-Window Privacy Gate

<p align="center">
  <img src="docs/assets/privacy-gate.png" alt="Fail-closed multi-window privacy gate showing allowed study apps, refused co-visible unlisted apps and notification shades, and non-overridable FLAG_SECURE / password manager blocks" width="880" />
</p>
<p align="center"><sub>Capture runs only when the tablet is awake, unlocked, free of overlays/<code>FLAG_SECURE</code>, and every visible non-system window is allowlisted.</sub></p>

- **Cross-OEM wake & lock parsing:** handles AOSP, Samsung OneUI, Xiaomi HyperOS, and OnePlus OxygenOS `dumpsys power` + `dumpsys window` formats in a single fast ADB shell pass.
- **Every visible window checked:** split-screen study apps (`StarNote` + `Xodo PDF`) are allowed together; a note app alongside a floating chat window or browser is refused (`skipped_non_study_app`).
- **Non-overridable hard blocks:** password managers (`Bitwarden`, `1Password`, `KeePass*`, `Proton Pass`), 2FA authenticators, banking/wallets, messaging, email, `NotificationShade`, `BiometricPrompt`, and `FLAG_SECURE` windows are blocked even if an agent calls `allow_any_app=True` (unless you explicitly opt in via `PAD_STUDY_ALLOW_BLOCKED=1`). See [`SECURITY.md`](SECURITY.md).

---

## Tools & Diagnostics

| Tool | Purpose | Key Parameters |
| :--- | :--- | :--- |
| **`pad_peek`** | Privacy-checked, ink-auto-cropped canvas capture with ETag diffing. | `auto_crop=True`, `max_size=1200`, `if_changed_since=""`, `allow_any_app=False`, `device=""` |
| **`pad_zoom`** | High-detail crop of a specific region in full-screen tablet coordinates (same privacy gate). | `x`, `y`, `width`, `height`, `max_size=1200`, `allow_any_app=False`, `device=""` |
| **`pad_status`** | Ultra-fast (`~0.2–0.4s`) health & privacy check: transport, lock state, battery, and visible apps. | `device=""` |

**Built-in CLI diagnostics (`pad-study-mcp doctor`):** verify your ADB binary, USB/Tailscale transport, lock state, battery, visible windows, and privacy decision from the terminal in under a second:

```json
{
  "adb": "/usr/local/bin/adb",
  "status": "ok",
  "device": "100.64.0.10:5555",
  "transport": "wireless",
  "battery_pct": 84,
  "screen_awake": true,
  "screen_locked": false,
  "visible_apps": ["StarNote"],
  "privacy_gate": "allowed"
}
```

---

## How It's Built

Single-file Python 3.10+ MCP server (`mcp` + `Pillow` only) running locally over stdio — zero daemon processes, zero Android helper apps, and zero external network calls.

```mermaid
flowchart LR
  subgraph Tablet["Android Tablet (OneUI · HyperOS · OxygenOS · AOSP)"]
    APP["Study App(s)\nStarNote · Samsung Notes · Goodnotes · Obsidian · Saber"]
    WIN["WindowManager & PowerManager\nWake · Lock · All Windows · FLAG_SECURE"]
  end

  subgraph Transport["Encrypted Local / Mesh Transport"]
    USB["USB-C ADB\n(Preferred when plugged in)"]
    TS["Wi-Fi / Tailscale WireGuard ADB\n(Auto-reconnect + stale-offline recovery)"]
  end

  subgraph Server["pad-study-mcp (Local Python Stdio Server)"]
    GATE["1. Fail-Closed Privacy Gate\nAllowlist + Hard Blocks + Shade Check"]
    CROP["2. Smart Ink Auto-Crop\nToolbar · Ruled Line · Gutter · Pill Removal"]
    ETAG["3. High-Precision ETag Hash\nStatus-Bar-Immune Canvas Diff"]
  end

  subgraph Clients["AI Coding & Study Clients"]
    AGY["Antigravity / Codex / Claude Code / Cursor"]
    SOS["Optional: Study-OS MCP\n(Exact Exam Task + Rubric Context)"]
  end

  APP --> USB
  APP --> TS
  WIN -->|"1. Inspect before capture"| GATE
  USB --> GATE
  TS --> GATE
  GATE -->|"Refuse (0 px) if locked/blocked/unlisted"| AGY
  GATE -->|"Allowed → exec-out screencap"| CROP
  CROP --> ETAG
  ETAG -->|"~24 KB JPEG or 0 KB unchanged"| AGY
  SOS -.->|"Parallel task + handwritten check"| AGY
```

---

## Quick Start

**Prerequisites:** Python 3.10+, [`adb`](https://developer.android.com/tools/releases/platform-tools) (Android Platform-Tools), and **USB debugging** enabled on your Android tablet.

### 1-Line MCP Install (`uvx`)

Add `pad-study` to your MCP client config — works identically in **Antigravity**, **Claude Code**, **Cursor**, and any MCP-compatible client:

```json
{
  "mcpServers": {
    "pad-study": {
      "command": "uvx",
      "args": ["--from", "git+https://github.com/shadjosef/pad-study-mcp", "pad-study-mcp"],
      "env": {
        "PAD_STUDY_DEVICE": "100.64.0.10:5555"
      }
    }
  }
}
```

*(Omit `PAD_STUDY_DEVICE` if you only plug in over USB-C — `pad-study-mcp` auto-detects the attached tablet.)*

<details>
<summary><strong>Codex CLI (<code>~/.codex/config.toml</code>)</strong></summary>

```bash
codex mcp add pad-study \
  --env PAD_STUDY_DEVICE=100.64.0.10:5555 \
  -- uvx --from git+https://github.com/shadjosef/pad-study-mcp pad-study-mcp
```

</details>

<details>
<summary><strong>Wireless over Campus / Isolated Wi-Fi with Tailscale (Recommended)</strong></summary>

Campus and office Wi-Fi networks typically enable **AP client isolation**, which blocks direct LAN connections between your laptop and tablet. [Tailscale](https://tailscale.com/) creates an encrypted peer-to-peer WireGuard tunnel between them automatically:

1. Install **Tailscale** on both your computer and Android tablet (whitelist Tailscale from battery optimization on Android).
2. Plug the tablet in via USB-C once after reboot and enable TCP ADB:
   ```bash
   adb tcpip 5555
   adb connect <tablet-tailscale-ip>:5555
   ```
3. Unplug USB-C and set `PAD_STUDY_DEVICE="<tablet-tailscale-ip>:5555"` (or save the IP in `~/.config/pad-study-mcp/device`).
4. On untrusted public Wi-Fi, see the network hygiene notes in [`SECURITY.md`](SECURITY.md) (close port `5555` via `adb -s <target> usb` when done, or use USB-C).

</details>

<details>
<summary><strong>Local Editable Install, Diagnostics &amp; Running Tests</strong></summary>

```bash
git clone https://github.com/shadjosef/pad-study-mcp.git
cd pad-study-mcp
uv venv .venv
uv pip install --python .venv/bin/python -e ".[dev]"

# Verify ADB, lock state, visible windows, and privacy gate:
.venv/bin/pad-study-mcp doctor

# Run the full 21-test unit suite (privacy gate, auto-crop, ETag, device recovery):
.venv/bin/pytest -v
```

</details>

<details>
<summary><strong>Optional: Proactive Study Rule (Antigravity / Codex / Claude)</strong></summary>

Add a short instruction to your agent's global rules (`GEMINI.md`, `AGENTS.md`, or `CLAUDE.md`) so you never have to say *"check my tablet"* manually:

```markdown
Whenever I ask about math, accounting, finance, economics, statistics, or physics
— or ask "is this right?", "check this", or "next step" — proactively call
`pad_peek()` first (passing `if_changed_since="<last canvas_hash>"` on follow-up turns).
If it returns `screen_off_or_locked`, `blocked_for_privacy`, `skipped_non_study_app`,
or `offline`, silently answer my text question normally.
```

</details>

---

## Supported Tablets & Study Apps

Works with any Android tablet supporting ADB (`Samsung Galaxy Tab`, `Xiaomi Pad`, `OnePlus Pad`, `Boox`, `Pixel Tablet`, `Lenovo Tab`).

<details>
<summary><strong>35+ built-in allowlisted study apps (plus custom <code>PAD_STUDY_EXTRA_APPS</code>)</strong></summary>

| Category | Built-in Allowlisted Apps |
| :--- | :--- |
| **Handwriting & Infinite Canvas** | StarNote, Notein, Samsung Notes, Goodnotes, Notewise, Flexcil, MyScript Notes / Nebo, Boox Notes, Squid, Touchnotes, Jnotes, Mi Canvas, Xiaomi Notes, Saber (FOSS), Butterfly (FOSS), Concepts, Krita |
| **Knowledge, Flashcards & PDFs** | Obsidian, Notion, OneNote, AnkiDroid, KOReader, Boox NeoReader, Xodo PDF, Adobe Acrobat Reader, WPS Office / Lite |
| **Calculators** | Google Calculator, AOSP Calculator, Samsung Popup Calculator, OnePlus Calculator, Xiaomi Calculator |

*(Need another app? Pass a comma-separated package list via `PAD_STUDY_EXTRA_APPS`.)*

</details>

---

## Configuration

All environment variables are optional:

| Variable | Description |
| :--- | :--- |
| `PAD_STUDY_ADB` | Explicit path to the `adb` binary (otherwise auto-detected from `PATH` & standard Android SDK locations on macOS/Linux/Windows). |
| `PAD_STUDY_DEVICE` | Explicit USB serial or wireless `<ip>:5555` target (takes priority when multiple Android devices are attached). |
| `PAD_STUDY_IP_CACHE` | File containing a cached wireless/Tailscale IP (defaults to `~/.config/pad-study-mcp/device`). |
| `PAD_STUDY_PORT` | Default ADB TCP port when a bare IP is supplied (default `5555`). |
| `PAD_STUDY_EXTRA_APPS` | Comma-separated extra Android package names to allowlist as study apps. |
| `PAD_STUDY_BLOCKED_APPS` | Comma-separated extra package names or `*glob*` patterns to always hard-block. |
| `PAD_STUDY_ALLOW_BLOCKED` | Set to `1` only if you explicitly want to permit overriding `BLOCKED_PACKAGES` / `FLAG_SECURE` (default off). |

---

## License & Security

- **License:** [MIT](LICENSE)
- **Privacy & Network Security:** See [`SECURITY.md`](SECURITY.md) for the fail-closed multi-window architecture, campus/public Wi-Fi ADB hygiene, and vulnerability reporting.

TDQS

A3.7/5.0

Scored across 3 tools

Disambiguation5/5

Each tool targets a distinct operation: pad_status checks device health/privacy, pad_peek captures the full canvas, and pad_zoom captures a specific region. Their descriptions clearly delineate when to use each, with no overlapping responsibilities.

Naming Consistency5/5

All tools use a consistent snake_case pad_ prefix followed by a concise action verb/noun (status, peek, zoom). The pattern is predictable and easy to extend.

Tool Count5/5

Three tools are well-scoped for a focused tablet inspection server: health/status, full capture, and regional capture. Each tool has a clear purpose and earns its place without redundancy.

Completeness4/5

The surface covers status checking, full canvas capture, and zoomed inspection, which are the core lifecycle operations for a study-tablet monitoring MCP. Minor gaps exist around structured text/OCR extraction or explicit app-list retrieval, but these can be worked around via existing capture and status tools.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues