SuperAPIAI Directory

cost-guard-mcp

github.com · AI developer platforms

cost-guard-mcp is a data warehouse query cost and result-size guardrail tool for AI agents, running as a local stdio process and supporting BigQuery, Snowflake, and Databricks. It provides cost estimates before a query actually executes and labels the estimate precision level (PRECISE, UPPER_BOUND, HEURISTIC), preventing agents from mistaking heuristic numbers for exact values. Core tools include: check_credentials, used to verify credentials and connectivity without running a real query; describe_engine_capabilities, which explains which metrics are exact and which are approximate for each engine; estimate_query_cost, which provides a pre-check cost estimate; and run_query_bounded, which refuses to execute a query when the estimate exceeds the caller-set byte, row, or dollar limits. Each call can independently set max_bytes_billed, max_rows (default 1000), and max_estimated_cost_usd; serialized results are capped at 8 MiB and truncated by whole rows when exceeded. By default only read-only statements are allowed, and write statements can be enabled via an environment variable; Snowflake roles are forcibly restricted, rejecting administrative roles such as ACCOUNTADMIN, and a statement timeout is set. No database, gateway, or Docker is required, making it suitable for scenarios where it is necessary to prevent agents from triggering full table scans or returning massive amounts of data, thereby causing high costs or context overflow.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)
PlatformsLinux

About this tool

Purpose

cost-guard-mcp provides pre-query cost and result-size guardrails for AI agents that use data warehouses. When an agent issues a query through a warehouse MCP, it may inadvertently trigger a full table scan, incurring hundreds of dollars in costs, or return millions of rows of data that overwhelm its own context window. This tool provides estimates of cost and returned data volume before a query runs, and allows the caller to set hard limits.

Main capabilities

  • Cost estimation: estimate_query_cost accepts engine, SQL, optional warehouse, warehouse size, and version parameters, and returns a pre-check estimate with a precision level. The precision level describes bytes rather than dollars: PRECISE corresponds to BigQuery dryRun; UPPER_BOUND corresponds to Snowflake EXPLAIN and to cases where BigQuery reports UPPER_BOUND or UNKNOWN; HEURISTIC corresponds to Databricks EXPLAIN COST.
  • Bounded execution: run_query_bounded refuses to run when the estimate exceeds the caller-set max_bytes_billed, max_rows, or max_estimated_cost_usd. max_rows defaults to 1000, serialized results are capped at 8 MiB, and when exceeded, results are truncated by whole rows and result_size_exceeded is returned. The executed field in the returned result indicates whether the query actually ran.
  • Credential check: check_credentials verifies credentials and connectivity without running a real query or dry run, and supports all three engines.
  • Capability description: describe_engine_capabilities explains which metrics are exact and which are approximate for the specified engine.
  • Zero infrastructure: a single local stdio process, with no database, gateway, or Docker Compose required.
  • Read-only by default: estimate_query_cost and run_query_bounded by default accept only read-only statements, and the first keyword must be SELECT, WITH, VALUES, SHOW, DESCRIBE, DESC, or EXPLAIN.
  • Snowflake role constraints: SNOWFLAKE_ROLE is required; ACCOUNTADMIN, SECURITYADMIN, and ORGADMIN are rejected before a connection is established; the session only activates that role, and secondary roles are fixed to NONE by default.
  • Statement timeout: The Snowflake session sets a statement deadline; check_credentials and estimate_query_cost are 60 seconds, and run_query_bounded is 120 seconds.
  • Concurrency limit: COST_GUARD_MAX_IN_FLIGHT_QUERIES defaults to 8, limiting the number of concurrent run_query_bounded calls.

Usage

Start this server as a subprocess through an MCP client (such as Claude Desktop). Credentials must be written directly into the host machine's server configuration block, not only set in shell environment variables.

  • BigQuery: Set GOOGLE_APPLICATION_CREDENTIALS to the path of the service account key file, or run gcloud auth application-default login.
  • Snowflake: Set SNOWFLAKE_ACCOUNT, SNOWFLAKE_USER, SNOWFLAKE_ROLE, and either SNOWFLAKE_PRIVATE_KEY_PATH (preferred) or SNOWFLAKE_PASSWORD. Optionally set SNOWFLAKE_EDITION (standard, enterprise, business_critical, or vps).
  • Databricks: Set DATABRICKS_SERVER_HOSTNAME, DATABRICKS_HTTP_PATH, and either DATABRICKS_TOKEN or DATABRICKS_CLIENT_ID plus DATABRICKS_CLIENT_SECRET.

Optional environment variables include COST_GUARD_SNOWFLAKE_ALLOW_WAREHOUSE_RESUME, COST_GUARD_DATABRICKS_ALLOW_WAREHOUSE_START, COST_GUARD_ALLOW_WRITE_STATEMENTS, COST_GUARD_ALLOW_MULTI_STATEMENT_SQL, etc.; values must match exactly.

For a quick start, you can use a public BigQuery dataset: a GCP project with the BigQuery API enabled, obtain application default credentials, add the server to the MCP client configuration, restart the client, call check_credentials to verify, and then call estimate_query_cost on the public dataset.

Use cases

  • An agent needs to estimate cost and data volume before executing queries on BigQuery, Snowflake, or Databricks.
  • You need to set independent byte, row, or dollar limits for each query to avoid shared session state.
  • You need to distinguish exact estimates from heuristic estimates to prevent the agent from over-trusting approximate numbers.
  • You want to deploy with read-only permissions to reduce the risk of the agent performing write operations.

Limitations

  • Dollar figures for Snowflake and Databricks are based on fixed runtime placeholder values and may underestimate.
  • Warehouse types whose rates are not modeled (Snowpark-optimized, Databricks Classic/Pro) return only byte estimates, not dollar figures.
  • Only BigQuery enforces maximumBytesBilled on the provider side; on Snowflake and Databricks, the 120-second limit is the only hard stop condition for query runtime.
  • On Snowflake warehouses that are not STARTED, cloud provider and query history queries are skipped; on Databricks warehouses that are not RUNNING or whose status cannot be read, no session is opened and no byte or dollar figures are returned.
  • Each call accepts only one SQL statement; multiple statements require explicitly enabling COST_GUARD_ALLOW_MULTI_STATEMENT_SQL.
  • The read-only gate is defense in depth; the real authorization boundary is the permissions of the deployed credentials, so a read-only principal should be used.
  • This tool has been published in the official MCP Registry under the identifier io.github.mcpsmiths/cost-guard-mcp.
Up/Down to navigate · Enter to open · ESC to closeBrowse all tools