agycraft-mcp 0.0.0-stage → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ModelCraft Community Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,205 @@
1
- # Temporary Holding Version
1
+ # agycraft-mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm version](https://img.shields.io/npm/v/agycraft-mcp)](https://www.npmjs.com/package/agycraft-mcp) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
4
+
5
+ Privacy-first local MCP server & offline CLI doctor for **Antigravity (AGY)** and **Gemini CLI** — part of the [ModelCraft](https://modelcraft.dev) open-source ecosystem. Available on [npm](https://www.npmjs.com/package/agycraft-mcp) and [GitHub](https://github.com/YuchengWang/agycraft-mcp).
6
+
7
+ > **Independent community project. Not affiliated with or endorsed by Google.**
8
+ >
9
+ > **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`)**.
10
+
11
+ ## Why agycraft-mcp?
12
+
13
+ - **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`).
14
+ - **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`).
15
+ - **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.
16
+ - **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.
17
+ - **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.
18
+
19
+ ## Privacy & Compliance Architecture (100% Auditable)
20
+
21
+ 1. **Zero User Data Upload**: All token analysis, incremental rollup aggregation, structural transcript counting, and doctor checks run 100% locally.
22
+ 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.
23
+ 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.
24
+ 4. **One-Way Read-Only Snapshots**: The only network request is a parameterless `GET` to `https://modelcraft.dev/data/v1/*.json` (configurable via `MODELCRAFT_DATA_URL`) with ETag caching and bundled offline fallback snapshots in `snapshots/`.
25
+ 5. **Zero Native Dependencies**: Pure TypeScript/JavaScript for Node 20+ (Node 22+ LTS recommended) — no `better-sqlite3` or C++ build steps.
26
+
27
+ ## Quick Start (30 Seconds)
28
+
29
+ ### 1. Run Offline Preflight Doctor & Live Status Guard
30
+
31
+ ```bash
32
+ # Run directly with npx (no global install required)
33
+ npx -y agycraft-mcp doctor
34
+ npx -y agycraft-mcp preflight
35
+
36
+ # Or install globally
37
+ npm install -g agycraft-mcp
38
+ agycraft-mcp doctor
39
+ agycraft-mcp preflight
40
+ ```
41
+
42
+ ### 2. Add to Antigravity CLI (`agy`), Gemini CLI (`gemini`), or JSON Config (`mcp_config.json` / `settings.json`)
43
+
44
+ **Antigravity CLI (`agy`) & Gemini CLI (`gemini`) one-liners:**
45
+
46
+ ```bash
47
+ # Antigravity CLI
48
+ agy mcp add agycraft npx -y agycraft-mcp
49
+
50
+ # Gemini CLI (project-scoped)
51
+ gemini mcp add --scope project agycraft npx -y agycraft-mcp
52
+ ```
53
+
54
+ *(For local dev testing against a local ModelCraft server: `agy mcp add --env MODELCRAFT_DATA_URL=http://127.0.0.1:4321/data/v1 agycraft agycraft-mcp`)*
55
+
56
+ **Or JSON config (`~/.gemini/antigravity/mcp_config.json` / `~/.gemini/settings.json`):**
57
+
58
+ ```json
59
+ {
60
+ "mcpServers": {
61
+ "agycraft": {
62
+ "command": "npx",
63
+ "args": ["-y", "agycraft-mcp"]
64
+ }
65
+ }
66
+ }
67
+ ```
68
+
69
+ ### 3. Optional: View Non-Destructive Telemetry Setup Snippets
70
+
71
+ ```bash
72
+ npx -y agycraft-mcp setup
73
+ ```
74
+
75
+ ### 4. Clear All Local Data Anytime
76
+
77
+ ```bash
78
+ npx -y agycraft-mcp clear-local-data
79
+ ```
80
+
81
+ ### 5. Project-Scoped Sandbox Isolation (`AGYCRAFT_CONFIG_DIR` & `AGYCRAFT_BRAIN_DIR`)
82
+
83
+ 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):
84
+
85
+ **CLI one-liners:**
86
+
87
+ ```bash
88
+ # Gemini CLI (supports --scope project)
89
+ gemini mcp add --scope project --env AGYCRAFT_CONFIG_DIR=./sandbox_repo/.agycraft agycraft npx -y agycraft-mcp
90
+
91
+ # Antigravity CLI
92
+ agy mcp add --env AGYCRAFT_CONFIG_DIR=./sandbox_repo/.agycraft agycraft npx -y agycraft-mcp
93
+
94
+ # Shell sandbox isolation for CLI commands
95
+ AGYCRAFT_CONFIG_DIR=./sandbox_repo/.agycraft AGYCRAFT_BRAIN_DIR=none npx -y agycraft-mcp doctor
96
+ ```
97
+
98
+ **Or JSON config (`~/.gemini/settings.json` / `.gemini/settings.json`):**
99
+
100
+ ```json
101
+ {
102
+ "mcpServers": {
103
+ "agycraft": {
104
+ "command": "npx",
105
+ "args": ["-y", "agycraft-mcp"],
106
+ "env": {
107
+ "AGYCRAFT_CONFIG_DIR": "./sandbox_repo/.agycraft"
108
+ }
109
+ }
110
+ },
111
+ "toolPermission": "proceed-in-sandbox"
112
+ }
113
+ ```
114
+
115
+ > **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.
116
+
117
+ ## CLI Subcommands
118
+
119
+ | Command | Description |
120
+ | :--- | :--- |
121
+ | `agycraft-mcp` | Start Stdio MCP Server (default) |
122
+ | `agycraft-mcp doctor [--auth-mode <channel>] [--json]` | Run offline preflight, channel isolation, & context hygiene checks |
123
+ | `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`) |
124
+ | `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 |
125
+ | `agycraft-mcp setup` | Print opt-in AGY Hook, Gemini CLI OTel (`logPrompts: false`), & sandbox snippets |
126
+ | `agycraft-mcp record` | Append whitelisted numeric hook payload from stdin (hashes `workspace_dir`/`cwd` into `project_hash`) |
127
+ | `agycraft-mcp clear-local-data` | Delete `~/.config/agycraft/usage.jsonl`, `.salt`, `cache/`, and `rollups/` |
128
+
129
+ ## Registered MCP Tools
130
+
131
+ 1. **`analyze_token_usage`**
132
+ - 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"`).
133
+ - 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`).
134
+ 2. **`get_saving_recommendations`**
135
+ - Parameters: `window` (`"24h" | "7d"`, default `"24h"`), `scope` (`"global" | "project"`), `transcript_path`, `loopThreshold` (default `4`), `workspace_dir`, `timezone`.
136
+ - 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.
137
+ 3. **`diagnose_error`**
138
+ - Parameters: `error_text` (required), `product` (`"agy" | "cli" | "api" | "web"`), `auth_mode` (optional explicit channel ID/alias), `doctor_summary`.
139
+ - 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.
140
+ 4. **`lookup_model_guide`**
141
+ - Parameters: `task`, `model_id`, `provider` (`"google" | "antigravity" | "anthropic" | "all"`), `include_history` (boolean).
142
+ 5. **`get_ecosystem_status`**
143
+ - Parameters: `plan` (`"free" | "pro" | "ultra"`), `product` (`"agy" | "cli" | "api" | "web"`), `timezone`, `scope` (`"global" | "project"`), `workspace_dir`, `auth_mode`.
144
+ - 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.
145
+
146
+ ## Development
147
+
148
+ ```bash
149
+ git clone https://github.com/YuchengWang/agycraft-mcp.git && cd agycraft-mcp && pnpm install && pnpm build && node dist/index.js doctor
150
+ ```
151
+
152
+ Run tests and typechecking:
153
+
154
+ ```bash
155
+ pnpm typecheck
156
+ pnpm test
157
+ pnpm build
158
+ ```
159
+
160
+ ## Benchmarks & Community Acknowledgements
161
+
162
+ Special thanks to **Dr. Jessica Rudd** — Google Developer Expert (GDE) in GenAI and author of the [*Data Bytes*](https://funsizedatabytes.substack.com/) 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*](https://funsizedatabytes.substack.com/p/snowball-sensor-agycraft-mcp-modelcraft):
163
+
164
+ | Metric | Unguarded Runaway Loop | With `agycraft-mcp` (`loopThreshold=4`) | Impact |
165
+ | :--- | :--- | :--- | :--- |
166
+ | Loop Termination | Turn 22 | **Turn 4** | Halted 18 turns early |
167
+ | Cumulative Input Tokens | 361,372 | **18,040** | **95.0% reduction** |
168
+ | Detection Latency (`get_saving_recommendations`) | — | **2.86 ms** | Sub-3 ms overhead |
169
+
170
+ ## Release History / Changelog
171
+
172
+ ### `v0.2.1` (2026-12-02)
173
+
174
+ - **`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.
175
+ - **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`).
176
+ - **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`).
177
+ - **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`).
178
+ - **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.
179
+ - [verification/v0.2.1/ENVIRONMENT.md](verification/v0.2.1/ENVIRONMENT.md)
180
+ - [verification/v0.2.1/cli-e2e-cases.md](verification/v0.2.1/cli-e2e-cases.md)
181
+ - [verification/v0.2.1/mcp-e2e-cases.md](verification/v0.2.1/mcp-e2e-cases.md)
182
+ - [verification/v0.2.1/EVALUATION.md](verification/v0.2.1/EVALUATION.md)
183
+
184
+ ### `v0.2.0` (2026-12-02)
185
+
186
+ - **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.
187
+ - **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.
188
+ - **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`).
189
+ - **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`).
190
+ - **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.
191
+ - **`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"`.
192
+ - **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*](https://funsizedatabytes.substack.com/p/snowball-sensor-agycraft-mcp-modelcraft), demonstrating 95.0% token reduction from 361,372 to 18,040 tokens and 2.86 ms detection latency).
193
+ - **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.
194
+ - [verification/v0.2.0/ENVIRONMENT.md](verification/v0.2.0/ENVIRONMENT.md)
195
+ - [verification/v0.2.0/mcp-e2e-cases.md](verification/v0.2.0/mcp-e2e-cases.md)
196
+ - [verification/v0.2.0/cli-e2e-cases.md](verification/v0.2.0/cli-e2e-cases.md)
197
+ - [verification/v0.2.0/EVALUATION.md](verification/v0.2.0/EVALUATION.md)
198
+
199
+ ### `v0.1.0` (2026-11-26)
200
+
201
+ - 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.
202
+
203
+ ## License
204
+
205
+ MIT
@@ -0,0 +1,3 @@
1
+ declare function main(argv?: string[]): Promise<void>;
2
+
3
+ export { main };