cost-guard-mcp
# cost-guard-mcp
Pre-flight query cost & result-size guardrails for AI agents, across BigQuery and Snowflake — before the query ever runs.
## Why
An AI agent using a warehouse MCP can silently trigger a full-table scan that costs hundreds of dollars, or return millions of rows that flood its own context window. No existing warehouse MCP tells the agent "how much will this cost" or "how much data will this return" *before* running the query.
## What makes this different
- **Every cost estimate discloses its accuracy tier** — `PRECISE` (BigQuery `dryRun`), `UPPER_BOUND` (Snowflake `EXPLAIN`), or `HEURISTIC` (Databricks, not yet shipped) — so your agent never over-trusts a heuristic number.
- **Per-call bounds** — `run_query_bounded` takes `max_bytes_billed` / `max_rows` / `max_estimated_cost_usd` on each call; no shared session state required.
- **Zero infrastructure** — a single local stdio process. No database, no gateway, no Docker Compose.
## Tools
- `describe_engine_capabilities(engine)` — what's exact vs. approximate for this engine.
- `estimate_query_cost(engine, sql, warehouse?)` — pre-flight cost estimate, tagged with its accuracy tier.
- `run_query_bounded(engine, sql, max_bytes_billed?, max_rows?, max_estimated_cost_usd?)` — refuses to run if the estimate exceeds your bound.
## Setup
### BigQuery
Set `GOOGLE_APPLICATION_CREDENTIALS` to a service-account key file path (or run `gcloud auth application-default login`).
### Snowflake
Set `SNOWFLAKE_ACCOUNT`, `SNOWFLAKE_USER`, `SNOWFLAKE_ROLE` (required — no default, never `ACCOUNTADMIN`), and either `SNOWFLAKE_PRIVATE_KEY_PATH` (preferred) or `SNOWFLAKE_PASSWORD` (discouraged).
## Install
```bash
uvx cost-guard-mcp
```
## Known limitations
- Databricks is not yet supported (deferred past v1).
- Snowflake's `UPPER_BOUND` estimate excludes Cortex AI Function ("AI Credits") cost.
- BigQuery Editions/capacity-billed projects cannot get a dollar estimate — only a byte count (capacity billing has no fixed $/byte rate).
## License
MIT
TDQS
Scored across 3 tools
Each tool has a distinct role: capability discovery, pre-flight estimation, and bounded execution. However, estimate_query_cost and the internal estimating in run_query_bounded could cause slight confusion about when to use each, though descriptions clarify the difference.
All tool names use snake_case with a consistent verb_noun pattern (describe_, estimate_, run_). There are no deviations or mixed conventions.
Three tools form a minimal but focused set for a cost-guard server, each earning its place. The count sits at the low end of the typical 3-15 range, but is reasonable for the specialized scope.
The core lifecycle of advisory estimation and bounded execution is fully covered. There is a minor gap around tools for retrieving or setting quota/bound context, but agents can work around this for the stated purpose.