bq-guard-mcp
Provides policy-guarded access to Google BigQuery, letting agents list datasets and tables, inspect schemas, dry-run queries, and run read-only queries with byte, row, and statement-type limits enforced.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@bq-guard-mcp run a dry run on SELECT COUNT(*) FROM analytics.sessions"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
bq-guard-mcp
An MCP server that gives AI agents BigQuery access through a policy. Every query is parsed, checked, and dry-run before anything is billed.
Letting an agent query a warehouse directly means trusting it not to scan a 40 TB table, run a
DELETE, or read the PII dataset. bq-guard-mcp is the one thing the agent talks to. It
exposes five tools, and each request goes through the guards in bq-guard.yaml. A refusal
says what to change, so the agent can fix the query instead of failing blind.
run_query("SELECT * FROM analytics.events")
-> Refused by bq-guard policy: the query would scan 3.41 TB, over the 5.00 GB limit;
filter on partition or clustering columns, or select fewer columnsTools
Tool | What it does |
| Datasets the policy allows. Denied datasets are hidden. |
| Tables in |
| Schema (with nested fields), row count, size, partitioning, and clustering. |
| Bytes the query would scan, the tables it touches, and whether |
| Runs one statement after every guard. Returns rows as JSON, |
Related MCP server: Secure BigQuery MCP Gateway
Guards on run_query
Parse with sqlglot (BigQuery dialect), not regex. SQL that doesn't parse is refused, and so are scripts and multiple statements.
Statement type. Only queries run by default (
read_only: true). Everything else is blocked:INSERT,UPDATE,DELETE,MERGE,CREATE_*,DROP_*,ALTER,TRUNCATE,EXPORT,GRANT, and so on. Withread_only: false, only the types listed inallow_statementsrun.Dataset and table allow and deny lists. These check every table the SQL names, and every table the dry run reports, so a view over a denied table is caught too. Deny wins over allow. A wildcard table like
events_*is refused while table deny rules exist, because it could include a denied table.LIMIT. A
SELECTwithout a top-levelLIMITgetsLIMIT default_limitappended to the original text. The SQL is not regenerated, so it runs exactly as written plus the limit.Dry run first, always. If the estimate exceeds
max_bytes_billed, the query is refused before any job exists.maximum_bytes_billedon the real job, always, so BigQuery itself enforces the cap even if the estimate was wrong.Row cap. At most
max_rowsrows come back.total_rowsandtruncatedsay what was left out.Labels. Every job carries your
labelsplusbq_guard=trueandbq_guard_tool=run_query|dry_run, so you can find agent traffic inINFORMATION_SCHEMA.JOBSand billing exports.Audit log. One JSON line per request and decision.
dry_run runs checks 1, 3, and 4 before estimating. It reports statement-type and byte-limit
problems as run_query_blockers instead of refusing, because a dry run executes nothing.
Install
pip install git+https://github.com/rk-chavali/bq-guard-mcp@v0.1.0or with uv: uv tool install git+https://github.com/rk-chavali/bq-guard-mcp@v0.1.0. Python 3.11+.
Authentication uses Application Default Credentials. Locally, run
gcloud auth application-default login. On a server, use a service account (workload
identity, or GOOGLE_APPLICATION_CREDENTIALS). No credentials are needed to start the server.
They are loaded on the first tool call, and a clear error names the fix if they are missing.
Connect it to your agent
Claude Code
claude mcp add --transport stdio --scope project bq-guard -- bq-guard-mcp --policy bq-guard.yamlor commit a .mcp.json at the project root:
{
"mcpServers": {
"bq-guard": {
"command": "bq-guard-mcp",
"args": ["--policy", "bq-guard.yaml"]
}
}
}Cursor
.cursor/mcp.json in the project, or ~/.cursor/mcp.json for every project:
{
"mcpServers": {
"bq-guard": {
"command": "bq-guard-mcp",
"args": ["--policy", "/absolute/path/to/bq-guard.yaml"]
}
}
}VS Code
.vscode/mcp.json:
{
"servers": {
"bq-guard": {
"type": "stdio",
"command": "bq-guard-mcp",
"args": ["--policy", "${workspaceFolder}/bq-guard.yaml"]
}
}
}Docker
docker build -t bq-guard-mcp .
docker run -i --rm \
-v "$HOME/.config/gcloud:/home/app/.config/gcloud:ro" \
-v "$PWD/bq-guard.yaml:/app/bq-guard.yaml:ro" \
bq-guard-mcpThe image runs as a non-root user, reads /app/bq-guard.yaml, and writes the audit log to
/tmp. Mount a volume and set BQ_GUARD_AUDIT_LOG to keep the log. The same snippets are in
examples/clients/.
Policy reference
The policy is found in this order: --policy PATH, $BQ_GUARD_POLICY, ./bq-guard.yaml. If
none exists, the built-in defaults apply: read-only, a 1 GB byte cap, LIMIT 1000, and 1000
rows. Unknown keys and invalid values stop the server at startup with a clear message.
project: acme-analytics # default: the ADC project
location: US
max_bytes_billed: 5000000000 # per query; dry run must be under it and the job is capped at it
read_only: true # only SELECT (default)
allow_statements: [] # with read_only: false, e.g. [INSERT, MERGE, "CREATE_*"]
datasets: # patterns: "dataset" or "project.dataset"
allow: ["analytics", "marts"]
deny: ["*_pii", "raw_*"]
tables: # patterns: "dataset.table" or "project.dataset.table"
deny: ["*.users", "*.*_secrets"]
enforce_limit: true
default_limit: 1000
max_rows: 500
timeout_seconds: 120
labels: # lowercase keys and values, BigQuery label rules
team: data-platform
audit_log: bq-guard-audit.jsonl # relative to the policy file; null disables; $BQ_GUARD_AUDIT_LOG overrides
audit_sql: hash # hash (default) or fullPatterns are shell-style globs (*, ?) and are case-sensitive, like BigQuery names. An empty
allow list allows everything that isn't denied. The full example is
examples/bq-guard.yaml.
Audit log
{"ts": "2026-09-23T14:02:11+00:00", "tool": "run_query", "decision": "blocked", "sql_sha256": "5f1c...", "reason": "DELETE statements are blocked: the server is in read-only mode"}
{"ts": "2026-09-23T14:02:40+00:00", "tool": "run_query", "decision": "allowed", "sql_sha256": "a93e...", "statement_type": "SELECT", "bytes_estimated": 52428800, "bytes_billed": 52428800, "rows_returned": 500, "job_id": "job_ab12", "limit_added": true}SQL is stored as a SHA-256 hash by default, because queries can contain customer data in
literals. Set audit_sql: full to keep the text. A failure to write the log is reported on
stderr and never blocks a request.
Security notes
BigQuery IAM is the real boundary. Give the server's identity only
roles/bigquery.jobUseron the billing project androles/bigquery.dataVieweron the datasets the agent should read. Grant write roles only if you allow writes in the policy. The policy is defense in depth, and it produces refusals the agent understands. It is not a substitute for IAM.The server runs over stdio and opens no network port.
Tool errors report BigQuery's message but never credentials. Query results go to the agent, and so to the model provider, so keep sensitive datasets out of the allow list.
Limitations
Table checks see the tables in the SQL and in the dry run's
referenced_tables. Access that neither shows, such as data read inside a remote function, is only limited by IAM.LIMITis added only at the top level of aSELECT. It limits rows returned, not bytes scanned, which is whatmax_bytes_billedis for.Multi-statement scripts,
DECLARE, and procedural SQL are refused rather than analyzed.Region-level
INFORMATION_SCHEMAviews (region-us.INFORMATION_SCHEMA.JOBS) are treated as a table in a dataset named after the region. Deny them explicitly if you need to.
Development
uv sync
uv run ruff check . && uv run mypy && uv run pytestThe tests use a fake BigQuery backend and an in-memory MCP client. They need no GCP credentials and make no network calls.
License
MIT
Available Tools
5 toolsdescribe_tableA
Schema, row count, size, partitioning, and clustering for dataset.table or
project.dataset.table.
Inputs: table (required). Returns: object
dry_runA
Estimate bytes scanned for one statement without running it, and report whether run_query would allow it and why not.
Inputs: sql (required). Returns: object
list_datasetsA
List datasets the policy allows. project defaults to the configured project.
Inputs: project. Returns: object
list_tablesB
List tables in a dataset, given as dataset or project.dataset.
Inputs: dataset (required). Returns: object
run_queryA
Run one statement after the policy checks and a dry run. Returns at most the row cap;
truncated says when more rows exist.
Inputs: sql (required). Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
Each tool targets a distinct action: listing datasets, listing tables, describing a table, dry-running a query, and running a query. There is no overlap or ambiguity between them.
All tool names follow a consistent verb_noun snake_case pattern (list_datasets, list_tables, describe_table, dry_run, run_query). The naming is predictable and uniform.
Five tools is well-scoped for a BigQuery guard server, covering metadata exploration and query execution without excess or redundancy. Each tool earns its place.
The surface covers the core workflow: discover datasets, browse tables, inspect schema, estimate cost, and run queries. Minor gaps like dataset-level metadata or query cancellation are not essential for the stated purpose.
Maintenance
Related MCP Connectors
The BigQuery remote MCP server is a fully managed service that uses the Model Context Protocol to connect AI applications and LLMs to BigQuery data sources. It provides secure, standardized tools for AI agents to list datasets and tables, retrieve schemas, generate and execute SQL queries through natural language, and analyze data—enabling direct access to enterprise analytics data without requiring manual SQL coding.
Scoped agent execution. Server-side credentials, policy, budgets and verifiable receipts.
Deterministic allow/require_approval/deny verdicts for agent actions, before they happen.
Security gateway for AI agents: policy, approval, and audited execution, no secrets shared.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables LLMs to explore BigQuery datasets and tables, run safe read-only queries, and optionally perform vector search using BigQuery embeddings.82 PyPI10MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to query BigQuery read-only via MCP with enforced dataset boundaries, result limits, and audit labels.MIT
- FlicenseNot gradedqualityDmaintenanceEnables AI agents to analyze BigQuery datasets through MCP, using tools to inspect datasets and execute read-only SQL queries.-
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to inspect, query, test, and safely fix dbt projects and BigQuery warehouses under policy-enforced controls, with read-only direct queries and dbt-only allowlisted writes.Apache 2.0