Skip to main content
Glama
README.md
# agy-relay

MCP + HTTP relay server that lets **Claude Code** invoke **Google Antigravity (`agy`)** as a configurable subagent using your authenticated Antigravity subscription.

## Prerequisites

- **Node.js `>= 20`**
- **Google Antigravity CLI (`agy`)** installed on `PATH` (or in its default user install folder) and signed in (`agy models` succeeds)
- **Claude Code** (CLI or IDE extension)

## Quick Install

Clone or copy `agy-relay` anywhere on disk, then run the installer from the checkout:

```bash
# macOS / Linux / Git Bash (installs MCP server + bundled skills in user scope)
./install.sh

# Include Orchestrator enforcement hooks and CLAUDE.md routing section
./install.sh --hooks --claude-md

# Project-scoped install (.mcp.json + .claude/skills + optional .claude/settings.local.json)
./install.sh --scope project --project /path/to/repo --hooks --claude-md
```

On Windows PowerShell:

```powershell
# Default user-scope install (MCP server + bundled skills)
.\install.ps1

# With optional hooks (enforce|advisory|off) and CLAUDE.md routing section
.\install.ps1 --hooks --hook-mode enforce --claude-md

# Project-scoped install
.\install.ps1 --scope project --project D:\work\my-app
```

If script execution is blocked, run it as `powershell -ExecutionPolicy Bypass -File .\install.ps1` (arguments follow the file name).

The scripts do not change directory: relative `--project`, `--claude-dir` and `--claude-json` values (and the default project, your current directory) resolve against where you ran them. Dependencies are installed by the node installer itself (skipped for `--dry-run`).

Project scope notes:

- `.mcp.json` holds an **absolute path** to this checkout (`<agy-relay>/bin/agy-relay.mjs`), so think twice before committing it; teammates need their own install.
- Hooks also contain machine-absolute paths, so project scope writes them to `.claude/settings.local.json` (not the committed `.claude/settings.json`).

Re-running the installer is idempotent: unchanged files are neither rewritten nor backed up, and every file it does change is first copied to a never-overwritten `<file>.bak-<timestamp>` (a `-1`, `-2` suffix is added on collisions). Uninstall removes only what install added: our hook commands (matched by path inside this checkout, or an old agy-relay copy), the MCP entry, the CLAUDE.md section, bundled `SKILL.md` files that are still unmodified (the skill dir only if then empty), and `env.AGY_RELAY_HOOK_MODE` only if install wrote it (tracked in `<data dir>/install-state.json`).

Note: when `--hook-mode <enforce|advisory|off>` is supplied with `--hooks`, `agy-relay` writes `AGY_RELAY_HOOK_MODE` into `settings.json` under `"env"` on both Windows and POSIX so hook commands stay shell-neutral.

### Doctor, Uninstall & CLI Usage

```bash
# Verify Node, agy CLI + models, MCP wiring, hooks, and skills
npm run doctor
# or: node bin/agy-relay.mjs doctor [--scope project --project /path/to/repo]

# Preview changes without touching disk
node bin/agy-relay.mjs install --dry-run --hooks --claude-md

# Uninstall agy-relay entries (preserves unrelated MCP servers, hooks, and modified skills)
node bin/agy-relay.mjs uninstall
node bin/agy-relay.mjs uninstall --scope project --project /path/to/repo

# Run test suite
npm test

# Start standalone HTTP + Streamable HTTP MCP server
node bin/agy-relay.mjs serve --port 4788

# One-shot CLI dispatch
node bin/agy-relay.mjs dispatch --preset scout --cwd /path/to/repo --task "Summarize auth flow"
```

## Environment Variables

| Variable | Default | Purpose |
|---|---|---|
| `AGY_RELAY_DATA_DIR` | `<agy-relay>/data` | Directory for run logs, model/quota caches, preset overrides, and blackboards |
| `AGY_RELAY_CONFIG_DIR` | `<agy-relay>/config` | Directory for base `presets.json`, `skills.json`, and `mcps.json` |
| `AGY_RELAY_HOOK_MODE` | `enforce` (`block`) | Hook behavior in `bin/claude-hook.mjs`: `enforce`, `advisory`, or `off` |
| `AGY_RELAY_META_PATHS` | _(none)_ | Extra directories (separated by `;` on Windows, `:` elsewhere) that the hook guard treats as meta/tooling paths and never blocks. Defaults (`~/orchestra`, `~/.claude`, `~/.agents`, `~/.gemini`, `~/.codex`, OS temp, `scratch-workspaces`) always apply; the `CLAUDE_CONFIG_DIR` directory is added automatically |
| `CLAUDE_CONFIG_DIR` | `~/.claude` | Custom Claude Code config dir (when set, user MCP config defaults to `<CLAUDE_CONFIG_DIR>/.claude.json`) |

## Features

- **Dual Interface & Live Operations Dashboard**:
  - **MCP Server (stdio)** registered directly in Claude Code (`agy-relay mcp`), exposing typed tools with `compact: true` lean return payloads and `responseStyle: "terse"` default so Antigravity subagents never waste tokens writing human prose.
  - **Live Subagent Dashboard** (`http://127.0.0.1:4788/`) showing every active worker, the exact tool step it is executing right now, full step-by-step inside-work trace, MCP guard denials, shared context blackboards, and estimated Claude tokens saved in real time via SSE (`/api/events`).
  - **Companion Claude Skills & Enforced Hook**: bundled in `claude/skills/agy-conserve/SKILL.md` (token-conservation routing & compact dispatch workflow) and `claude/skills/agy-relay/SKILL.md` (full relay reference), plus `<agy-relay>/bin/claude-hook.mjs` wired into `settings.json` (`UserPromptSubmit` + `PreToolUse` hard-blocking inline project edits, large unbounded reads >=12 KB, and >3 exploration calls/turn; per-turn bypass via `#inline` or `"do it yourself"`, or `AGY_RELAY_HOOK_MODE=advisory|off`).
- **Flexible Model Presets & Effort (`low | medium | high | xhigh | max`)**:
  - Live `agy models` discovery with caching & refresh.
  - Named presets (`quick`, `scout`, `review`, `implement`, `ui-craft`, `deep`, `architect`, `orchestrator`) in `config/presets.json`, plus runtime CRUD (`agy_presets`) persisted in `data/presets.user.json`.
  - Safe by default (`read-only` sandbox + git worktree fingerprint verification); write-enabled presets or explicit `mode: "write"` opt in intentionally.
  - Quota-aware automatic fallback chains with cooldown tracking (`data/quota.json`).
- **Hybrid Skill Auto-Router & Injector**:
  - Indexes skills from `~/.claude/skills`, `~/.agents/skills`, `~/.gemini/config/skills`, `<repo>/.claude/skills`, and `<repo>/.agents/skills`.
  - Scores relevance against task prompt, target file extensions/names, and preset tag affinity while auto-excluding orchestrator meta-skills (`config/skills.json`).
  - Supports `auto`, `explicit`, `stage` (copies into `.agents/skills/` for native Antigravity progressive disclosure), and `none` modes with configurable `maxSkills`, `tokenBudget`, and `injectionStyle` (`auto | full | summary`).
- **Per-Run MCP Selection, Hard Isolation Hook & Multiplexer Bridge**:
  - Discovers MCP servers across `~/.gemini/config/mcp_config.json`, `~/.claude.json`, `<repo>/.mcp.json`, and `config/mcps.json` (excluding `agy-relay` itself to prevent recursion).
  - Supports `none`, `all`, `preset`, allowlists/denylists, and per-server tool allow/deny filters (`allowTools`, `denyTools`).
  - Stages a per-run plugin (`.agents/plugins/relay/`) providing BOTH:
    - **Hard `PreToolUse` MCP guard hook** (`hooks.json` -> `node guard.mjs`) that hard-denies disallowed global MCP servers (like `figma` or `playwright`) and disallowed tools per run without mutating `~/.gemini/config/mcp_config.json` and with full audit logging (`blockedMcpCalls` in `result.json`).
    - **Scoped Streamable HTTP MCP bridge** (`ServerName="relay_hub"` -> `/mcp/bridge/:runId`), verified to work in both `read-only` (`--sandbox`) and `write` modes, proxying allowed non-global or tool-filtered MCP servers (with automatic Antigravity 64-char tool-name compliance) AND exposing live `blackboard_*` tools to `agy`.
- **Structured Shared Context Blackboard**:
  - Persistent, versioned per-repo or custom-ID JSON store (`data/contexts/<id>.json`) with optimistic revision concurrency (`expectedRevision`).
  - Tracks `goal`, `architecture`, `conventions`, `decisions`, `pinnedFiles` (with automatic line-range snippet hydration), `findings`, `openQuestions`, and `runHistory`.
  - Bidirectional: Claude updates via `agy_context_update`; `agy` receives a token-budgeted projection in its brief and writes back via bridge `blackboard_*` tools or `<blackboard_updates>` blocks.

## MCP Tools Exposed to Claude Code

| Tool | Purpose |
|---|---|
| `agy_dispatch` | Run Antigravity synchronously or asynchronously with preset/model/effort/mode/skills/mcps/context/jsonSchema/conversationId |
| `agy_run_status` | Poll live progress, usage tokens, touched files, and final output |
| `agy_run_list` | List recent and active runs |
| `agy_run_cancel` | Cancel an active run |
| `agy_models` | List live `agy models` and quota cooldown state (optional `refresh`, `clearQuota`) |
| `agy_presets` | `list`, `get`, `upsert`, or `delete` presets |
| `agy_skills` | `list` indexed skills or `match` preview for a task + target files |
| `agy_mcps` | Discover configured MCP servers across Antigravity, Claude, workspace, and relay |
| `agy_context_get` | Read shared blackboard (`json` or rendered `markdown`) |
| `agy_context_update` | Update goal, architecture, conventions, decisions, pinned files, findings, questions |
| `agy_context_list` | List all stored blackboards |
| `agy_context_delete` | Delete a blackboard |

## HTTP API Endpoints

- `GET /api/health`
- `GET /api/models?refresh=1`, `POST /api/quota/clear`
- `GET /api/presets`, `GET|POST|DELETE /api/presets/:name`
- `GET /api/skills?cwd=...`, `POST /api/skills/match`
- `GET /api/mcps?cwd=...`
- `GET /api/contexts`, `GET|PATCH|DELETE /api/contexts/:id`, `GET /api/contexts/:id/render`
- `GET|POST /api/runs`, `GET /api/runs/:id`, `POST /api/runs/:id/cancel`, `GET /api/runs/:id/events` (SSE)
- `POST /mcp` (Streamable HTTP MCP server)
- `POST /mcp/bridge/:runId` (Per-run scoped MCP bridge for Antigravity)

## License

MIT, see [LICENSE](LICENSE).