agycraft-mcp 0.0.0-stage → 0.2.0

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,190 @@
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
+ Privacy-first local MCP server & offline CLI doctor for **Antigravity (AGY)** and **Gemini CLI** — part of the [ModelCraft](https://modelcraft.dev) open-source ecosystem.
4
+
5
+ > **Independent community project. Not affiliated with or endorsed by Google.**
6
+ >
7
+ > **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`)**.
8
+
9
+ ## Why agycraft-mcp?
10
+
11
+ - **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`).
12
+ - **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`).
13
+ - **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.
14
+ - **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.
15
+ - **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.
16
+
17
+ ## Privacy & Compliance Architecture (100% Auditable)
18
+
19
+ 1. **Zero User Data Upload**: All token analysis, incremental rollup aggregation, structural transcript counting, and doctor checks run 100% locally.
20
+ 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.
21
+ 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.
22
+ 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/`.
23
+ 5. **Zero Native Dependencies**: Pure TypeScript/JavaScript for Node 20+ (Node 22+ LTS recommended) — no `better-sqlite3` or C++ build steps.
24
+
25
+ ## Quick Start (30 Seconds)
26
+
27
+ ### 1. Run Offline Preflight Doctor & Live Status Guard
28
+
29
+ ```bash
30
+ # Run directly with npx (no global install required)
31
+ npx -y agycraft-mcp doctor
32
+ npx -y agycraft-mcp preflight
33
+
34
+ # Or install globally
35
+ npm install -g agycraft-mcp
36
+ agycraft-mcp doctor
37
+ agycraft-mcp preflight
38
+ ```
39
+
40
+ ### 2. Add to Antigravity CLI (`agy`), Gemini CLI (`gemini`), or JSON Config (`mcp_config.json` / `settings.json`)
41
+
42
+ **Antigravity CLI (`agy`) & Gemini CLI (`gemini`) one-liners:**
43
+
44
+ ```bash
45
+ # Antigravity CLI
46
+ agy mcp add agycraft npx -y agycraft-mcp
47
+
48
+ # Gemini CLI (project-scoped)
49
+ gemini mcp add --scope project agycraft npx -y agycraft-mcp
50
+ ```
51
+
52
+ *(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`)*
53
+
54
+ **Or JSON config (`~/.gemini/antigravity/mcp_config.json` / `~/.gemini/settings.json`):**
55
+
56
+ ```json
57
+ {
58
+ "mcpServers": {
59
+ "agycraft": {
60
+ "command": "npx",
61
+ "args": ["-y", "agycraft-mcp"]
62
+ }
63
+ }
64
+ }
65
+ ```
66
+
67
+ ### 3. Optional: View Non-Destructive Telemetry Setup Snippets
68
+
69
+ ```bash
70
+ npx -y agycraft-mcp setup
71
+ ```
72
+
73
+ ### 4. Clear All Local Data Anytime
74
+
75
+ ```bash
76
+ npx -y agycraft-mcp clear-local-data
77
+ ```
78
+
79
+ ### 5. Project-Scoped Sandbox Isolation (`AGYCRAFT_CONFIG_DIR` & `AGYCRAFT_BRAIN_DIR`)
80
+
81
+ 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):
82
+
83
+ **CLI one-liners:**
84
+
85
+ ```bash
86
+ # Gemini CLI (supports --scope project)
87
+ gemini mcp add --scope project --env AGYCRAFT_CONFIG_DIR=./sandbox_repo/.agycraft agycraft npx -y agycraft-mcp
88
+
89
+ # Antigravity CLI
90
+ agy mcp add --env AGYCRAFT_CONFIG_DIR=./sandbox_repo/.agycraft agycraft npx -y agycraft-mcp
91
+
92
+ # Shell sandbox isolation for CLI commands
93
+ AGYCRAFT_CONFIG_DIR=./sandbox_repo/.agycraft AGYCRAFT_BRAIN_DIR=none npx -y agycraft-mcp doctor
94
+ ```
95
+
96
+ **Or JSON config (`~/.gemini/settings.json` / `.gemini/settings.json`):**
97
+
98
+ ```json
99
+ {
100
+ "mcpServers": {
101
+ "agycraft": {
102
+ "command": "npx",
103
+ "args": ["-y", "agycraft-mcp"],
104
+ "env": {
105
+ "AGYCRAFT_CONFIG_DIR": "./sandbox_repo/.agycraft"
106
+ }
107
+ }
108
+ },
109
+ "toolPermission": "proceed-in-sandbox"
110
+ }
111
+ ```
112
+
113
+ > **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.
114
+
115
+ ## CLI Subcommands
116
+
117
+ | Command | Description |
118
+ | :--- | :--- |
119
+ | `agycraft-mcp` | Start Stdio MCP Server (default) |
120
+ | `agycraft-mcp doctor [--json]` | Run offline preflight & context hygiene checks |
121
+ | `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 |
122
+ | `agycraft-mcp setup` | Print opt-in AGY Hook, Gemini CLI OTel (`logPrompts: false`), & sandbox snippets |
123
+ | `agycraft-mcp record` | Append whitelisted numeric hook payload from stdin (hashes `workspace_dir`/`cwd` into `project_hash`) |
124
+ | `agycraft-mcp clear-local-data` | Delete `~/.config/agycraft/usage.jsonl`, `.salt`, `cache/`, and `rollups/` |
125
+
126
+ ## Registered MCP Tools
127
+
128
+ 1. **`analyze_token_usage`**
129
+ - 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"`).
130
+ - 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`).
131
+ 2. **`get_saving_recommendations`**
132
+ - Parameters: `window` (`"24h" | "7d"`, default `"24h"`), `scope` (`"global" | "project"`), `transcript_path`, `loopThreshold` (default `4`), `workspace_dir`, `timezone`.
133
+ - 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.
134
+ 3. **`diagnose_error`**
135
+ - Parameters: `error_text` (required), `product` (`"agy" | "cli" | "api" | "web"`), `doctor_summary`.
136
+ - Covers 5 fault domains + Structured Output/Function Calling + 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.
137
+ 4. **`lookup_model_guide`**
138
+ - Parameters: `task`, `model_id`, `provider` (`"google" | "antigravity" | "all"`), `include_history` (boolean).
139
+ 5. **`get_ecosystem_status`**
140
+ - Parameters: `plan` (`"free" | "pro" | "ultra"`), `product` (`"agy" | "cli" | "api" | "web"`), `timezone`, `scope` (`"global" | "project"`), `workspace_dir`, `auth_mode`.
141
+ - 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.
142
+
143
+ ## Development
144
+
145
+ ```bash
146
+ git clone https://github.com/YuchengWang/agycraft-mcp.git && cd agycraft-mcp && pnpm install && pnpm build && node dist/index.js doctor
147
+ ```
148
+
149
+ Run tests and typechecking:
150
+
151
+ ```bash
152
+ pnpm typecheck
153
+ pnpm test
154
+ pnpm build
155
+ ```
156
+
157
+ ## Benchmarks & Community Acknowledgements
158
+
159
+ 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):
160
+
161
+ | Metric | Unguarded Runaway Loop | With `agycraft-mcp` (`loopThreshold=4`) | Impact |
162
+ | :--- | :--- | :--- | :--- |
163
+ | Loop Termination | Turn 22 | **Turn 4** | Halted 18 turns early |
164
+ | Cumulative Input Tokens | 361,372 | **18,040** | **95.0% reduction** |
165
+ | Detection Latency (`get_saving_recommendations`) | — | **2.86 ms** | Sub-3 ms overhead |
166
+
167
+ ## Release History / Changelog
168
+
169
+ ### `v0.2.0` (2026-12-02)
170
+
171
+ - **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.
172
+ - **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.
173
+ - **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`).
174
+ - **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`).
175
+ - **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.
176
+ - **`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"`.
177
+ - **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).
178
+ - **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.
179
+ - [verification/v0.2.0/ENVIRONMENT.md](verification/v0.2.0/ENVIRONMENT.md)
180
+ - [verification/v0.2.0/mcp-e2e-cases.md](verification/v0.2.0/mcp-e2e-cases.md)
181
+ - [verification/v0.2.0/cli-e2e-cases.md](verification/v0.2.0/cli-e2e-cases.md)
182
+ - [verification/v0.2.0/EVALUATION.md](verification/v0.2.0/EVALUATION.md)
183
+
184
+ ### `v0.1.0` (2026-11-26)
185
+
186
+ - 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.
187
+
188
+ ## License
189
+
190
+ MIT
@@ -0,0 +1,3 @@
1
+ declare function main(argv?: string[]): Promise<void>;
2
+
3
+ export { main };