Skip to main content
Glama
README.md
# AGY Magician

A zero-dependency local MCP bridge and agent skill that connects coding agents (such as Antigravity / T3 Code / MCP clients) to personal **Gemini Web** (`gemini.google.com`) accounts — and gives Gemini Web live, OAuth-protected access to your local files.

## How It Works

```text
Coding Agent (MCP client)
   │  stdio MCP (agy-mcp.mjs — locked 1-to-1 to one account)
   ▼
Local Bridge Server (server.mjs on 127.0.0.1:38471)
   ├──► Browser CDP (browser-trigger.mjs + picker-script.js)
   │       Opens /u/<index> on gemini.google.com, selects model/effort,
   │       attaches @AGY Magician, submits prompt, captures reply
   │
   └──◄ Public HTTPS via Tailscale Funnel (https://<your-host>.ts.net/mcp)
           OAuth 2.1 + PKCE + Dynamic Client Registration
           Exposes list_files, read_file, search_files, write_file, save_note_for_antigravity
```

### Two Tool Sets

**1. Agent-side tools (`agy-mcp.mjs`)**
- `plan_with_my_gemini` — Delegates a prompt to the agent's locked Gemini Web account (`mode: "chat"` or `"task"`, `effort: "low" | "medium" | "high"`, `allowWrite`, `remote`, `continue_job_id`, `wait`).
- `check_gemini_job` — Polls status or retrieves the completed response for a `job_id`.
- `check_gemini_limits` — Inspects available models and any visible quota/reset notices without sending a prompt.

**2. Gemini-side tools (`server.mjs` at `/mcp`)**
- `list_files` — Lists local drives or full folder contents without a tiny item cutoff (supports absolute paths or `job:<jobId>`).
- `read_file` — Reads local files in full up to 2 MB; auto-compacts huge JSON exports (> 2 MB) by skipping giant trailing cache blobs (such as `indexedDB`) and supports `#offset=<bytes>` chunking for other multi-MB files.
- `search_files` — Case-insensitive search matching both file/folder names (including media/binary files) and text file contents, with streaming search for large files and escaped-quote matching.
- `write_file` — Creates or overwrites text files with no arbitrary size cap (automatically backs up overwritten files to `backups/`; blocked on read-only jobs and `.git`/`.env`).
- `save_note_for_antigravity` — Archives markdown plans/notes into `bridge-replies/`.

### Built-In Safeguards
- **1-to-1 Account Locking:** Each agent instance only ever talks to its assigned `BRIDGE_ACCOUNT`.
- **Optional Ask-First Accounts:** Set `"requireExplicitApproval": true` on any account in `accounts.json` to force agents to ask before using that account.
- **Unattended / Remote Failsafe:** Passing `remote: true` forces read-only plan-only mode; unresolved write prompts automatically fall back to read-only after `approvalTimeoutSeconds`.
- **Protected Paths:** Sensitive credential folders (`.ssh`, `.aws`, `.gnupg`, browser `User Data`, `.t3/userdata`, `.gemini`, `.gemini-bridge`, `.git`, `.env`, Windows credential stores) are blocked.
- **OAuth 2.1 + Passcode Gate:** Public `/mcp` requires OAuth 2.1 + PKCE + a local 6-digit passcode (`passcode.txt`, auto-generated on first start) with brute-force lockout. Local `/local/*` endpoints reject proxied requests and require `local-api-token.txt`.

---

## Requirements
- **Node.js 22+** (uses built-in `fetch`, `WebSocket`, and `RegExp.escape`; zero npm dependencies)
- A Chromium-based browser (Chrome, Edge, Helium, etc.) signed into your Google account(s) with remote debugging enabled (`chrome://inspect/#remote-debugging`)
- **Tailscale Funnel** (or any HTTPS reverse proxy) pointing to `http://127.0.0.1:38471` so `gemini.google.com` can reach `/mcp`

---

## Setup

### 1. Clone and create your local config files
```bash
git clone https://github.com/ct-g0d/agy-magician.git
cd agy-magician
cp accounts.example.json accounts.json
cp folders.example.json folders.json
```

Edit `accounts.json`:
- Set `browserDevToolsActivePort` to your browser's `DevToolsActivePort` file path (for example `C:\Users\<you>\AppData\Local\Google\Chrome\User Data\DevToolsActivePort`).
- Map each account key (`account1`, `account2`, …) to its Google `/u/<index>` slot, email, display name, and optional `requireExplicitApproval`.

### 2. Start the local bridge server
```bash
node server.mjs
```
On Windows, you can launch it invisibly at login via Task Scheduler using `wscript.exe "C:\path\to\agy-magician\run-hidden.vbs"`.

On first run, `server.mjs` creates:
- `passcode.txt` — 6-digit passcode used once when linking each Google account via OAuth
- `local-api-token.txt` — local-only shared secret used by `agy-mcp.mjs`

### 3. Expose `/mcp` over HTTPS (Tailscale Funnel)
```bash
tailscale funnel --bg 38471
```
Your public MCP endpoint will be `https://<your-tailscale-host>.ts.net/mcp`.

### 4. Add the Custom MCP App in Gemini Web
1. Open `https://gemini.google.com` → **Settings → Connected Apps** (or `gemini.google.com/devmode`) → add a Custom MCP App.
2. Enter your HTTPS endpoint (`https://<your-tailscale-host>.ts.net/mcp`), name/handle (e.g. `AGY Magician`), and authorize using the 6-digit code in `passcode.txt`.
   - *Tip for multi-account linking:* Link additional Google accounts in an Incognito window so Google's OAuth redirect doesn't collide with `/u/0`.

### 5. Wire your MCP client & skill
- Copy the snippet from `mcp_config.example.json` into your coding agent's MCP config, setting `BRIDGE_ACCOUNT` and `BRIDGE_PROVIDER_NAME` per provider.
- Copy `skill/anti-gemini-magician/` into your agent's skills directory (e.g. `~/.gemini/config/skills/anti-gemini-magician/`).

---

## License
MIT — see [LICENSE](LICENSE).