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(BigQuerydryRun),UPPER_BOUND(SnowflakeEXPLAIN), orHEURISTIC(Databricks, not yet shipped) — so your agent never over-trusts a heuristic number. - Per-call bounds —
run_query_boundedtakesmax_bytes_billed/max_rows/max_estimated_cost_usdon 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).
A note on credentials with MCP hosts
Whatever MCP client/host you use (Claude Desktop, etc.) spawns this server as its own subprocess — it does not automatically inherit your shell's environment variables, even if they're set in your .zshrc/.bashrc. Put them directly in the host's server config instead — see .mcp.json.example for the exact block, and the "Use with other AI coding tools" section below for where each specific tool wants it.
Install
uvx cost-guard-mcp
Also published on the official MCP Registry as io.github.mcpsmiths/cost-guard-mcp.
For local development instead:
git clone https://github.com/mcpsmiths/cost-guard-mcp.git
cd cost-guard-mcp
uv sync
uv run cost-guard-mcp
Use with other AI coding tools
cost-guard-mcp is a standard stdio MCP server — any MCP-compatible client works, not just Claude Desktop. Every client ultimately runs the same command/args/env; only the wrapping file format differs, so there's one canonical definition — .mcp.json.example — instead of a separately maintained copy per tool below.
There is no single file every tool reads automatically (each looks in its own location), but three of the four use the exact same mcpServers wrapper .mcp.json.example already has, so those need nothing more than copying it into place. Fill in your real credential values, then:
| Client | Where it goes | Change needed from .mcp.json.example |
|---|---|---|
| Claude Code | .mcp.json (project) |
None — copy as-is, or claude mcp add-json cost-guard-mcp '<the "cost-guard-mcp" object>' |
| Claude Desktop | claude_desktop_config.json |
None — copy as-is |
| Cursor | .cursor/mcp.json or ~/.cursor/mcp.json |
Add "type": "stdio" inside the server object |
| GitHub Copilot (VS Code) | .vscode/mcp.json |
Rename top-level key mcpServers → servers, add "type": "stdio" |
| OpenAI Codex CLI | ~/.codex/config.toml |
Same fields, TOML syntax instead of JSON (below) — or codex mcp add cost-guard-mcp -- uvx cost-guard-mcp |
Codex is the one genuine exception (TOML, not JSON), so it still needs its own block:
[mcp_servers.cost-guard-mcp]
command = "uvx"
args = ["cost-guard-mcp"]
[mcp_servers.cost-guard-mcp.env]
GOOGLE_APPLICATION_CREDENTIALS = "/path/to/service-account.json"
BIGQUERY_PROJECT = "your-project-id"
SNOWFLAKE_ACCOUNT = "your-account"
SNOWFLAKE_USER = "your-user"
SNOWFLAKE_ROLE = "your-role"
SNOWFLAKE_PRIVATE_KEY_PATH = "/path/to/rsa_key.p8"
Known limitations
- Databricks is not yet supported (deferred past v1).
- Snowflake's
UPPER_BOUNDestimate 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).
More docs
ARCHITECTURE.md— component/data-flow mapDECISIONS.md— why the design looks the way it doesCONTEXT.md— terminology glossary (BigQuery/Snowflake concepts that sound alike but aren't)CHANGELOG.md— release historyCONTRIBUTING.md/AGENTS.md— contributing and build/test/lint commandsSECURITY.md— vulnerability reporting
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cost_guard_mcp-0.1.1.tar.gz.
File metadata
- Download URL: cost_guard_mcp-0.1.1.tar.gz
- Upload date:
- Size: 142.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
158b34940218c57fe820d8ceeac55c81b8f51c1aed6e4163fd70321d394d8dc2
|
|
| MD5 |
a951c7eae18ee44149a1bc2b2013ac45
|
|
| BLAKE2b-256 |
a30ce5397503298d97a31f350ff85c05c29ed5a8a52e67d91abbd0e357e390f1
|
File details
Details for the file cost_guard_mcp-0.1.1-py3-none-any.whl.
File metadata
- Download URL: cost_guard_mcp-0.1.1-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22c700678a18b6385128ffa103c228bddf37cfc385919910407adcabd739972f
|
|
| MD5 |
f33b1bdd9cd8f8c60b25672e18a4b88e
|
|
| BLAKE2b-256 |
a2eb176cb68410629803fe4f9d7b2d2d0ae87e6a05a255f798415b913df3cc07
|