Repository avatar
Other Tools
v0.3.0
active

agycraft-mcp

io.github.YuchengWang/agycraft-mcp

Privacy-first local MCP server & CLI doctor for Antigravity and Gemini CLI.

Documentation

agycraft-mcp

npm version License: MIT

Privacy-first local MCP server & offline CLI doctor for Antigravity (AGY) and Gemini CLI — part of the ModelCraft open-source ecosystem. Available on npm and GitHub.

Independent community project. Not affiliated with or endorsed by Google.

Note on Gemini CLI Support: Google sunset personal/consumer-tier access for Gemini CLI on June 18, 2026. agycraft-mcp continues to maintain full Gemini CLI support (settings.json diagnostics, --scope project registration, and OTel telemetry) for Gemini Code Assist Standard/Enterprise and paid Gemini API key workflows. Individual developers are recommended to use Antigravity (agy).

Why agycraft-mcp?

  • Preflight & Hygiene (doctor, preflight): Catch broken mcp_config.json/settings.json, url vs httpUrl mismatches, stripped *TOKEN*/*KEY*/*SECRET* env vars, corporate proxy SSL errors (NODE_EXTRA_CA_CERTS), missing .geminiignore, and bloated global rules before your session stalls — plus a live cloud status gate (preflight).
  • Multi-Granularity Token, Rollup & KV Cache Audit (analyze_token_usage): Inspect 5h / 24h / 7d / 30d / all consumption across summary, hourly, daily, weekly, and monthly rollups (v2 schema with watermarks.json salt_fingerprint), scope: "global" | "project" isolation (project_hash), auth_mode filtering, Thinking output cost share, <4,096 implicit KV cache misses, and unified model catalog shadow cost estimation (estimated_total_usd, estimated_cache_savings_usd).
  • Quota-Saving Prescriptions & Executive Summaries (get_saving_recommendations): Detect long-session snowballs (with gentle phase-milestone compaction guidance when KV cache hit rate >= 85%), heavy model mismatches, Thinking downgrade opportunities, autonomous agent failure loops, and missing .geminiignore (with Python/data-science exclusions) — returning behavior_summary and executive_summary in a single call.
  • Actionable Error Attribution (diagnose_error): Diagnose all 5 fault domains (Quota/429 desync, Auth/403 mismatch, Capacity/503-504, MCP transport, Network/SSL), Structured Output & Function Calling protocol errors, and 4 granular GCP / Vertex AI rules (gcp-vertex-api-disabled, gcp-adc-expired, gcp-vertex-iam-or-location, gcp-vpc-sc-blocked) with BigQuery/GCS false-positive protection, copyable fix commands, verification steps, don't-dos, and modelcraft.dev deep links.
  • Model Selection & Mixed-Auth Ecosystem Status (lookup_model_guide, get_ecosystem_status): Pick the right model or Orchestrator pairing (e.g. Neon + Hydrogen), check deprecation warnings, inspect readonly auth_context mixed-auth isolation (Google OAuth / GCP ADC / API Key), view live upstream status, and compute local PT midnight & rolling 5h/7d reset countdowns.

Privacy & Compliance Architecture (100% Auditable)

  1. Zero User Data Upload: All token analysis, incremental rollup aggregation, structural transcript counting, and doctor checks run 100% locally.
  2. Strict Numeric/Metadata Whitelist: ~/.config/agycraft/usage.jsonl only records v, ts, provider, product, session_hash (salted SHA-256), model, input_tokens, cache_read_tokens, output_tokens, thinking_tokens, context_used_pct, tool_calls, turn_index, error_code, project_hash (salted SHA-256 of workspace_dir/cwd), and auth_mode. Prompts, responses, source code, raw file paths, project names, and emails are never written or logged.
  3. Zero Credential Inspection: Credential files (oauth_creds.json, application_default_credentials.json) are checked via existsSync only — never read, parsed, or logged. Never reads secret env values or calls undocumented Google/AGY internal endpoints.
  4. One-Way Read-Only Snapshots: The only network request is a parameterless GET to public static JSON snapshots (jsDelivr -> GitHub Pages -> GitHub Raw multi-source fallback, configurable via AGYCRAFT_DATA_URL / MODELCRAFT_DATA_URL) with ETag caching and bundled offline fallback snapshots in snapshots/.
  5. Zero Native Dependencies: Pure TypeScript/JavaScript for Node 20+ (Node 22+ LTS recommended) — no better-sqlite3 or C++ build steps.

Quick Start (30 Seconds)

1. Run Offline Preflight Doctor & Live Status Guard

# Run directly with npx (no global install required)
npx -y agycraft-mcp@latest doctor
npx -y agycraft-mcp@latest preflight

# Or install globally
npm install -g agycraft-mcp
agycraft-mcp doctor
agycraft-mcp preflight

2. Add to Antigravity CLI (agy), Gemini CLI (gemini), or JSON Config (mcp_config.json / settings.json)

Antigravity CLI (agy) & Gemini CLI (gemini) one-liners:

# Antigravity CLI
agy mcp add agycraft npx -y agycraft-mcp@latest

# Gemini CLI (project-scoped)
gemini mcp add --scope project agycraft npx -y agycraft-mcp@latest

(For local dev testing against a local ModelCraft server: agy mcp add --env AGYCRAFT_DATA_URL=http://127.0.0.1:4321/data/v1 agycraft npx -y agycraft-mcp@latest)

Or JSON config (~/.gemini/antigravity/mcp_config.json / ~/.gemini/settings.json):

{
  "mcpServers": {
    "agycraft": {
      "command": "npx",
      "args": ["-y", "agycraft-mcp@latest"]
    }
  }
}

3. Optional: View Non-Destructive Telemetry Setup Snippets

npx -y agycraft-mcp@latest setup

4. Clear All Local Data Anytime

npx -y agycraft-mcp@latest clear-local-data

5. Project-Scoped Sandbox Isolation (AGYCRAFT_CONFIG_DIR & AGYCRAFT_BRAIN_DIR)

To evaluate agycraft-mcp in an isolated repo/sandbox with zero writes to ~/.config/agycraft and zero scans of global ~/.gemini/antigravity-cli/brain, set AGYCRAFT_CONFIG_DIR (which automatically skips global brain scanning unless AGYCRAFT_BRAIN_DIR is explicitly provided, or set AGYCRAFT_BRAIN_DIR=none to disable explicitly):

CLI one-liners:

# Gemini CLI (supports --scope project)
gemini mcp add --scope project --env AGYCRAFT_CONFIG_DIR=./sandbox_repo/.agycraft agycraft npx -y agycraft-mcp@latest

# Antigravity CLI
agy mcp add --env AGYCRAFT_CONFIG_DIR=./sandbox_repo/.agycraft agycraft npx -y agycraft-mcp@latest

# Shell sandbox isolation for CLI commands
AGYCRAFT_CONFIG_DIR=./sandbox_repo/.agycraft AGYCRAFT_BRAIN_DIR=none npx -y agycraft-mcp@latest doctor

Or JSON config (~/.gemini/settings.json / .gemini/settings.json):

{
  "mcpServers": {
    "agycraft": {
      "command": "npx",
      "args": ["-y", "agycraft-mcp@latest"],
      "env": {
        "AGYCRAFT_CONFIG_DIR": "./sandbox_repo/.agycraft"
      }
    }
  },
  "toolPermission": "proceed-in-sandbox"
}

Note: "toolPermission": "proceed-in-sandbox" is an Antigravity top-level settings.json permission field (sibling to "mcpServers", not nested inside mcpServers.agycraft). agy mcp add and gemini mcp add do not write this field automatically—add it manually at the top level of your config file if needed.

CLI Subcommands

CommandDescription
agycraft-mcpStart Stdio MCP Server (default)
agycraft-mcp doctor [--auth-mode <channel>] [--json]Run offline preflight, channel isolation, & context hygiene checks
agycraft-mcp doctor --cost [--window 5h|24h|7d|30d|all] [--json]Inspect readonly cost breakdown by Canonical Model × Auth Mode (Shadow Cost vs Estimated GCP / API Spend)
agycraft-mcp preflight [--json]Live cloud status guard against status.json (MODELCRAFT_STATUS_URL / MODELCRAFT_DATA_URL); exits 1 on degraded, active incidents, 429/503 sources, or timeout
agycraft-mcp setupPrint opt-in AGY Hook, Gemini CLI OTel (logPrompts: false), & sandbox snippets
agycraft-mcp recordAppend whitelisted numeric hook payload from stdin (hashes workspace_dir/cwd into project_hash)
agycraft-mcp clear-local-dataDelete ~/.config/agycraft/usage.jsonl, .salt, cache/, and rollups/

Registered MCP Tools

  1. analyze_token_usage
    • Parameters: window ("5h" | "24h" | "7d" | "30d" | "all", default "5h"), granularity ("summary" | "hourly" | "daily" | "weekly" | "monthly", default "summary"), timezone, max_buckets (1..90, default 31), product ("agy" | "gemini-cli" | "all"), scope ("global" | "project"), workspace_dir (salted locally into project_hash, never returned), auth_mode ("all" | "google_oauth" | "gcp_adc" | "api_key" | "unknown").
    • Uses incremental rollups/ (v2 schema, hourly / daily / weekly / monthly + watermarks.json salt_fingerprint) and unified model catalog shadow cost estimation (estimated_total_usd, estimated_cache_savings_usd).
  2. get_saving_recommendations
    • Parameters: window ("24h" | "7d", default "24h"), scope ("global" | "project"), transcript_path, loopThreshold (default 4), workspace_dir, timezone.
    • Returns behavior_summary (avg_input_tokens_per_request, cache_hit_rate_pct, estimated_cache_savings_usd, light_model_request_share_pct, heavy_model_request_share_pct, top_models, peak_hours, project_share_of_global_pct, auth_context) and executive_summary in a single call, with gentle compaction guidance when KV cache hit rate >= 85% and Python/data .geminiignore exclusions.
  3. diagnose_error
    • Parameters: error_text (required), product ("agy" | "cli" | "api" | "web"), auth_mode (optional explicit channel ID/alias), doctor_summary.
    • Driven by ChannelRegistry (channels.json), covering 4-channel 429 RESOURCE_EXHAUSTED isolation (google_oauth, gcp_vertex_adc, gemini_api_key, vertex_express_key), 5 fault domains, Structured Output/Function Calling, and 4 granular GCP/Vertex AI rules (gcp-vertex-api-disabled, gcp-adc-expired, gcp-vertex-iam-or-location, gcp-vpc-sc-blocked) with BigQuery/GCS 400/403 anti-false-positive protection.
  4. lookup_model_guide
    • Parameters: task, model_id, provider ("google" | "antigravity" | "anthropic" | "all"), include_history (boolean).
  5. get_ecosystem_status
    • Parameters: plan ("free" | "pro" | "ultra"), product ("agy" | "cli" | "api" | "web"), timezone, scope ("global" | "project"), workspace_dir, auth_mode.
    • Includes readonly auth_context mixed-auth isolation (google_oauth, gcp_adc, api_key) alongside live upstream status and PT midnight / rolling 5h/7d reset countdowns.

Development

git clone https://github.com/YuchengWang/agycraft-mcp.git && cd agycraft-mcp && pnpm install && pnpm build && node dist/index.js doctor

Run tests and typechecking:

pnpm typecheck
pnpm test
pnpm build

Benchmarks & Community Acknowledgements

Special thanks to Dr. Jessica Rudd — Google Developer Expert (GDE) in GenAI and author of the Data Bytes newsletter (who also shared this evaluation in the GDE GenAI Circle) — for her independent sandbox testing, benchmarks, and actionable feedback in The Snowball Sensor: Catching Runaway AI Agent Loops Before They Burn Your Quota:

MetricUnguarded Runaway LoopWith agycraft-mcp (loopThreshold=4)Impact
Loop TerminationTurn 22Turn 4Halted 18 turns early
Cumulative Input Tokens361,37218,04095.0% reduction
Detection Latency (get_saving_recommendations)—2.86 msSub-3 ms overhead

Release History / Changelog

v0.2.4 (2026-12-04)

  • Consecutive & Sliding-Window polling_loop Detection: Upgraded collectTranscriptMeta and antipatterns to detect consecutive and sliding-window polling sequences, eliminating miss-detections in long sessions where polling accounts for < 15% of total tool calls.
  • Context-Depth Weighted Waste Quantification & >= 100K High Alerts: Quantified polling_wasted_tokens and estimated_wasted_usd weighted by per-turn context depth, escalating to high severity when polling occurs at >= 100K context tokens.
  • Structured Prescriptions & Cross-Client transcript.jsonl Discovery: Added structured polling_loop remediation prescriptions in get_saving_recommendations and automatic transcript.jsonl probing across both antigravity and antigravity-cli.

v0.2.2 (2026-12-02)

  • Bilingual Adaptive Output (lang: "en" | "zh" | "auto") & src/i18n.ts: Added bilingual localization across MCP tool responses and CLI diagnostics with src/i18n.ts, synchronized bilingual snapshots/*.json, and 99/99 unit tests passing.

v0.2.1 (2026-12-02)

  • doctor --cost Channel-Isolated Cost Audit & Deprecation Alerts: Added agycraft-mcp doctor --cost [--window 5h|24h|7d|30d|all] [--json] and doctor --json cost_summary / deprecated_model_in_use checks, strictly separating Shadow Cost (Shared Quota Pressure) (google_oauth), Estimated GCP / API Spend (gcp_adc), and Unattributed Est. (unknown) by Canonical Model × Auth Mode with zero session_hash, project_hash, or local path exposure.
  • Canonical Model Registry & unknown Attribution: Unified model IDs to canonical catalog entries (gemini-4-hydrogen, gemini-3.8-flash, gemini-3.5-flash-lite, claude-sonnet-5-5, etc.) and eliminated unknown gaps for AGY CHECKPOINT events and MODEL_TIER_FLASH_LITE CLI background logs (0 unknown in live analyze_token_usage).
  • Anthropic Provider & Deprecation Guidance: Added provider: "anthropic" support (claude-sonnet-5-5, claude-sonnet-4-5, claude-opus-4-6, claude-haiku-4-5) to lookup_model_guide, filtered deprecated gemini-3.8-flash from task: "planning", and resolved legacy gemini-3-8-flash aliases with migration warnings (-> gemini-4-hydrogen).
  • Dynamic ChannelRegistry (channels.json) & 4-Channel Isolation: Added data-driven ChannelRegistry (supporting both channels and auth_channels schemas in channels.json), doctor --auth-mode <channel> isolation checks, per-channel channel_reports in get_saving_recommendations, and 4-channel diagnose_error routing (google_oauth, gcp_vertex_adc, gemini_api_key, vertex_express_key).
  • Verification & Release Verdict: Verified on Node v20.20.2 and Node v22.21.1 with 94/94 unit tests passing across 8 test files, plus real-project (AGYCRAFT_READONLY=1, live modelcraft-web/public/data/v1/), zero-code dynamic channel extension (mock_enterprise_oidc), and isolated sandbox E2E verification — Go for release.

v0.2.0 (2026-12-02)

  • Built-in preflight Cloud Guard & Node 20+ Compatibility: Added agycraft-mcp preflight [--json] to check status.json (MODELCRAFT_STATUS_URL / MODELCRAFT_DATA_URL) and exit 1 on degraded status, active incidents, upstream 429/503 signals, or HTTP/network failures. Relaxed engines.node to >=20.0.0 (Node 22+ LTS recommended) with clean doctor Node 20.x support.
  • Project-Scoped Filtering & Mixed-Auth Isolation: Added scope: "global" | "project", one-way salted project_hash from workspace_dir/cwd (never persisting raw paths), unattributed_sessions_excluded reporting, and readonly auth_context / auth_mode isolation across Google OAuth (google_oauth), GCP ADC (gcp_adc), and API Key (api_key) using existsSync-only credential checks.
  • Incremental rollups/ (v2) & Shadow Cost Estimation: Added atomic, file-locked incremental rollups (hourly / daily / weekly / monthly + watermarks.json with salt_fingerprint invalidation) and unified model catalog shadow cost estimation (estimated_total_usd, estimated_cache_savings_usd) across analyze_token_usage (5h/24h/7d/30d/all).
  • Single-Call behavior_summary & executive_summary: Upgraded get_saving_recommendations to emit behavior_summary (top models, peak hours, cache hit rate, project share, auth context) and executive_summary, plus gentle phase-milestone compaction advice when KV cache hit rate >= 85% and Python/data .geminiignore exclusions (.venv/, __pycache__/, data/, logs/, tmp/, *.parquet, *.lock).
  • 4 Granular GCP / Vertex AI diagnose_error Rules & Anti-False-Positive: Added gcp-vertex-api-disabled, gcp-adc-expired, gcp-vertex-iam-or-location, and gcp-vpc-sc-blocked, while preventing BigQuery/GCS 400/403 data-plane errors from being misclassified as model schema or model auth errors.
  • AGYCRAFT_BRAIN_DIR & AGYCRAFT_CONFIG_DIR Sandbox Isolation: Added AGYCRAFT_BRAIN_DIR (none/off/false or custom path), automatic skipping of global brain scans when AGYCRAFT_CONFIG_DIR is set, and sandboxed setup snippets with top-level "toolPermission": "proceed-in-sandbox".
  • Acknowledgements: Driven by real-world sandbox testing (AGYCRAFT_CONFIG_DIR=./sandbox_repo/.agycraft, "toolPermission": "proceed-in-sandbox", Node.js v20.19.0) and benchmarks from Dr. Jessica Rudd (GDE in GenAI & Data Bytes author — The Snowball Sensor: Catching Runaway AI Agent Loops Before They Burn Your Quota, demonstrating 95.0% token reduction from 361,372 to 18,040 tokens and 2.86 ms detection latency).
  • Verification & Release Verdict: Verified on Node v20.20.2 and Node v22.21.1 with 65/65 unit tests passing across 7 test files, plus full MCP protocol interference & CLI sandbox E2E verification — Go for release.

v0.1.0 (2026-11-26)

  • Initial release with 5 Stdio MCP tools (analyze_token_usage, get_saving_recommendations, diagnose_error, lookup_model_guide, get_ecosystem_status), offline CLI (doctor, setup, record, clear-local-data), strict 12-field numeric/metadata whitelist, and bundled offline fallback snapshots.

License

MIT

NPM
agycraft-mcp
Install Command
npm install agycraft-mcp