Skip to main content

cost-guard-mcp

PyPI Python MCP Registry License: MIT tests

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 tierPRECISE (BigQuery dryRun), UPPER_BOUND (Snowflake EXPLAIN), or HEURISTIC (Databricks, not yet shipped) — so your agent never over-trusts a heuristic number.
  • Per-call boundsrun_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).

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 mcpServersservers, 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_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).

More docs

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

cost_guard_mcp-0.1.1.tar.gz (142.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cost_guard_mcp-0.1.1-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

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

Hashes for cost_guard_mcp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 158b34940218c57fe820d8ceeac55c81b8f51c1aed6e4163fd70321d394d8dc2
MD5 a951c7eae18ee44149a1bc2b2013ac45
BLAKE2b-256 a30ce5397503298d97a31f350ff85c05c29ed5a8a52e67d91abbd0e357e390f1

See more details on using hashes here.

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

Hashes for cost_guard_mcp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 22c700678a18b6385128ffa103c228bddf37cfc385919910407adcabd739972f
MD5 f33b1bdd9cd8f8c60b25672e18a4b88e
BLAKE2b-256 a2eb176cb68410629803fe4f9d7b2d2d0ae87e6a05a255f798415b913df3cc07

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page