Skip to main content
Glama

agy-codemode

Zero-dependency Anthropic-style Code Execution with MCP plugin for Google Antigravity 2.x.

CI Version Zero Dependencies Node.js License Platforms

Features · Architecture · Installation · Usage · Configuration · Security · Development


Why agy-codemode?

Traditional MCP setups inject every connected server's tool list and JSON schemas into context on every turn, and force multi-step tool calls (loops, pagination, filtering) to round-trip raw payloads through the model.

agy-codemode collapses all upstream MCP servers — including installed Antigravity Marketplace plugins — into 2 lazy MCP tools:

  • codemode_search — BM25 + progressive disclosure over synced servers, instructions, skills, and typed tool stubs (names, summary, or full).

  • codemode_execute — executes model-written TypeScript/ESM in an isolated sandbox (bwrap --unshare-net + Node --permission) so the agent batches calls with Promise.all, filters payloads locally, and returns only the compact summary.


Related MCP server: codemodekit

Features

  • Zero External Dependencies: Pure Node.js 22 ESM using native TypeScript stripping (--experimental-strip-types), node:test, and node:net.

  • Antigravity Customizations & Marketplace Auto-Discovery: Read-only scanner for ~/.gemini/config/plugins/ (plugin.json JSONC + mcp_config.json) and ~/.gemini/config/config.json, expanding ${PLUGIN_ROOT}, ${PLUGIN_DATA}, ${userHome}, and ${env:VAR:-default}.

  • Zero-Spawn Schema Fast-Path: Reads Antigravity's existing ~/.gemini/antigravity/mcp/<plugin>_<server>/ cache for IDE-enabled plugins without spawning duplicate stdio processes or hitting file locks.

  • Auto-Managed Server Roster (AGENTS.md): Maintains a compact <!-- CODEMODE_ROSTER:START/END --> block (~15 tokens/server) so disabled/offloaded plugins remain discoverable without bloating <mcp_servers>.

  • Zero-Symlink Skill Preservation (keep-skills): Keeps skills/ from disabled MCP plugins active via Antigravity's official ~/.gemini/config/skills.json without editing config.json.

  • Smart Safety Classification: Automatically skips self-recursion / meta-plugins, detects OAuth-protected HTTP servers (401 → oauth-keep-native), and preserves MCP App UI tools (_meta.ui.resourceUri → mcp-app-ui).

  • Pre-Imported native Globals: readFile, runCommand, manageTask, writeFile, and editFile are pre-imported in codemode_execute for multi-file audits, grep/filter pipelines, and batched test runs, while hybrid routing keeps user-facing edits on native Antigravity tools for Undo/diff UI support.

  • Incremental Hash Sync & Idle Reaper: Per-server configHash caching, bounded sync concurrency, automatic mid-session delta resync on config changes, and a 10-minute .unref()'d idle reaper for stdio children.

  • Layered Sandbox & Secret Redaction: Runs scripts under Bubblewrap (bwrap --unshare-net) + Node --permission, keeps upstream credentials strictly inside the broker process, and dynamically redacts configured secrets from stdout/stderr.


Architecture

flowchart LR
    AGY["Antigravity Agent"] -->|codemode_search / codemode_execute| BROKER["agy-codemode Broker (Node 22)"]
    BROKER -->|Read-Only Scan| PLUGINS["~/.gemini/config/plugins/ + servers.json"]
    BROKER -->|Generates Typed Stubs| STUBS["~/.gemini/codemode/servers/<server>/<tool>.ts"]
    BROKER -->|Per-Run Auth UDS| SANDBOX["Sandbox (bwrap --unshare-net + node --permission)"]
    SANDBOX -->|Imports .ts Stubs + Native Globals| BROKER
    BROKER -->|Stdio / Streamable HTTP| UPSTREAM["Upstream MCP Servers (Broker-Held Credentials)"]

Requirements

  • Node.js >= 22.0.0 (for native TypeScript execution and --permission flag)

  • Bubblewrap (bwrap) on Linux (recommended; falls back to node --permission with tightened FS read allowlists if unavailable)

  • Google Antigravity 2.x (Desktop App, IDE, or CLI)


Installation

Quick Install (Linux / macOS)

git clone https://github.com/mochmizan/agy-codemode.git ~/agy-codemode
cd ~/agy-codemode
./install.sh

The installer symlinks ./plugin to ~/.gemini/config/plugins/agy-codemode and runs doctor to verify your environment. It never modifies ~/.gemini/config/config.json.

Manual Install

mkdir -p ~/.gemini/config/plugins
ln -sfn "$(pwd)/plugin" ~/.gemini/config/plugins/agy-codemode
node plugin/bin/agy-codemode.mjs doctor
node plugin/bin/agy-codemode.mjs sync

Reload Antigravity (or start a new conversation) to activate the plugin.


Usage

CLI Commands

# Verify Node 22 TypeScript support, bwrap sandbox, and config paths
node plugin/bin/agy-codemode.mjs doctor

# Inspect installed Antigravity plugins and offload recommendations
node plugin/bin/agy-codemode.mjs discover
node plugin/bin/agy-codemode.mjs discover --json

# Sync discovered + configured MCP servers into typed .ts stubs
node plugin/bin/agy-codemode.mjs sync
node plugin/bin/agy-codemode.mjs sync --workspace /path/to/repo

# Keep a disabled plugin's skills active via official ~/.gemini/config/skills.json
node plugin/bin/agy-codemode.mjs keep-skills <plugin-name>
node plugin/bin/agy-codemode.mjs keep-skills --prune

# List synced servers and tool counts
node plugin/bin/agy-codemode.mjs list

MCP Tools Exposed to Antigravity

Tool

Purpose

Key Arguments

codemode_search

Progressive BM25 search over synced MCP servers & tools

query?, server?, detail? ("names" | "summary" | "full"), limit?, resync?, workspace?

codemode_execute

Execute TypeScript/ESM in the isolated sandbox

code?, skill?, timeoutMs?, maxOutputChars?, workspace?

Example codemode_execute Script

import { resolveLibraryId } from "./servers/context7/resolveLibraryId.ts";
import { queryDocs } from "./servers/context7/queryDocs.ts";

const libs = await resolveLibraryId({ libraryName: "next.js", query: "app router caching" });
const docs = await queryDocs({ libraryId: "/vercel/next.js", query: "revalidateTag" });

// Filter locally before printing to context
console.log(String(docs).slice(0, 1500));

Configuration

User configuration lives at ~/.gemini/codemode/servers.json (auto-created with safe defaults). Explicit entries in servers.json take highest precedence over auto-discovered plugins.

{
  "discovery": {
    "mode": "all",
    "excludePlugins": ["agy-codemode", "agy-prefill", "usage-monitor"]
  },
  "builtins": {
    "native": true
  },
  "lifecycle": {
    "idleTimeoutMs": 600000
  },
  "sandbox": {
    "redactSecrets": true
  },
  "trustedWorkspaces": [
    "${userHome}/projects/my-app"
  ],
  "mcpServers": {
    "serena": {
      "optIn": true,
      "description": "LSP semantic symbol navigation, cross-file references & diagnostics",
      "command": "serena",
      "args": ["start-mcp-server", "--context", "antigravity", "--agent-interface", "tools", "--project", "${WORKSPACE}"]
    },
    "custom-api": {
      "description": "Internal REST/MCP service",
      "url": "https://mcp.example.com/mcp",
      "headers": {
        "Authorization": "Bearer ${env:CUSTOM_API_TOKEN}"
      }
    }
  }
}

Per-Project Scoping (.agents/codemode.json)

Add <workspace>/.agents/codemode.json to customize active MCPs per repository with zero native schema bloat (Antigravity ignores this file; only agy-codemode reads it):

{
  "enable": ["serena"],
  "disable": ["custom-api"],
  "mcpServers": {
    "project-db": {
      "description": "Read-only analytics DB",
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres", "${env:DB_URL}"]
    }
  }
}
  • enable / disable always work (safe — only toggles servers defined in your global servers.json).

  • Repo-defined mcpServers only execute if the workspace is listed in trustedWorkspaces (or "trustProjectServers": true) in ~/.gemini/codemode/servers.json.

  • A SessionStart + PreInvocation hook injects a compact 1-line-per-server roster for the active workspace (0 tokens on normal turns; auto re-injects after /compact).

  • Truncated codemode_execute output spills into <artifactDirectoryPath>/scratch/codemode-runs/ inside the active conversation directory so deleting a conversation deletes its spill logs automatically.

  • discovery.mode: "all" (default — discovers both enabled and disabled plugins), "disabled-plugins", or "off".

  • Persist intermediate datasets in ./workspace/ (~/.gemini/codemode/workspace/) and reusable scripts in ~/.gemini/codemode/skills/<name>.ts (runnable via codemode_execute(skill="<name>")).


Security & Sandbox Model

Layer

Protection

Network Isolation

bwrap --unshare-net blocks all direct outbound network access from sandboxed scripts.

Filesystem Isolation

Node --permission restricts FS reads to package.json, servers/, runtime/, workspace/, and skills/ (blocking servers.json and host secrets).

Credential Isolation

Upstream env variables and HTTP headers stay exclusively inside the broker process and never enter sandbox process.env.

IPC Authentication

Each sandbox run communicates with the broker over a per-run Unix domain socket guarded by a random bearer token.

Output Redaction

Built-in secret patterns plus dynamically collected header/env secret values are redacted from stdout/stderr before returning to context.


Development & Testing

# Run the full automated test suite (12 end-to-end & unit tests)
npm test

# Or invoke directly with Node 22
AGY_CODEMODE_NO_DISCOVERY=1 node --test plugin/tests/*.test.mjs

Repository Structure

agy-codemode/
├── install.sh                   # Idempotent plugin symlink installer
├── package.json                 # Zero-dep package metadata & scripts
├── CHANGELOG.md
├── LICENSE
└── plugin/
    ├── plugin.json              # Antigravity plugin manifest (v0.3.0)
    ├── mcp_config.json          # Portable ${PLUGIN_ROOT} MCP entrypoint
    ├── assets/logo.svg          # Plugin icon
    ├── rules/AGENTS.md          # Hybrid routing rule + managed server roster
    ├── bin/agy-codemode.mjs     # CLI (doctor, discover, sync, keep-skills, list)
    ├── src/
    │   ├── mcp-server.mjs       # MCP JSON-RPC server (codemode_search, codemode_execute)
    │   ├── discovery.mjs        # Antigravity plugin/cache scanner & skills.json helper
    │   ├── config.mjs           # Config loader, hash fingerprinting, secret extraction
    │   ├── codegen.mjs          # Typed .ts stub generator, BM25 search, roster updater
    │   ├── upstream-pool.mjs    # Stdio + Streamable HTTP MCP client pool & idle reaper
    │   ├── sandbox.mjs          # bwrap + Node --permission runner & secret redactor
    │   ├── native-server.mjs    # Host-bridged native globals (readFile, runCommand, ...)
    │   └── format.mjs           # Compact output formatting helpers
    └── tests/
        ├── codemode.test.mjs    # 12 end-to-end & unit tests
        └── mock-mcp-server.mjs  # Local mock MCP server for deterministic tests

License

MIT

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables building safe, programmable Code Mode MCP servers from upstream tool sources, with model-authored TypeScript running in a sandbox and tool calls routed to trusted host-side providers.
      1
      Apache 2.0
    • A
      license
      Not graded
      quality
      C
      maintenance
      Fronts every MCP server you have with two tools: search shortlists relevant tools, and execute runs sandboxed Python that calls upstream tools as mcp..(). It enables agents to make bulk, repeated, or conditional tool calls using calibrated decision-model choices instead of per-item LLM generation.
      3
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables agents to accomplish multi-step work by writing a single sandboxed JavaScript program that drives shell, filesystem, HTTP, and every tool of any configured MCP server, returning only a small summary instead of raw JSON. This collapses dozens of advertised tool schemas into one tool, cutting per-request context by roughly 26× while keeping disabled upstream servers reachable.
      1
      34 npm
      MIT