bq-readonly-mcp

bq-readonly-mcp

A read-only BigQuery MCP server with auto-LIMIT injection, dry-run cost guard, and ADC authentication. Allows safe SQL querying of BigQuery by LLMs without risk of data modification or unexpected costs.

Category
访问服务器

README

bq-readonly-mcp

🔍 Read-only BigQuery MCP server with auto-LIMIT, dry-run cost guard, and ADC auth. Safe for LLMs to query your BigQuery — no DML, no surprises, no runaway bills.

PyPI CI Python License


✨ Why this exists

LLMs connected to BigQuery can accidentally scan terabytes if the MCP layer lets them run arbitrary SQL. bq-readonly-mcp prevents that by design: every query goes through a strict SELECT/WITH-only validator, gets an automatic LIMIT injected before it runs, and is priced via a dry-run before any bytes are billed. If the estimated cost exceeds the cap (default 1 GB), the query is refused outright — before a single byte hits your bill.

The server runs as a local stdio process under your OS account, uses Application Default Credentials, and exposes zero write operations. There is no INSERT, no UPDATE, no DELETE, no DDL — anywhere in the codebase. The only thing it can do is read, and it does that safely.


🛠️ The 7 tools

Tool What it does Use when…
list_datasets List datasets in the project, with optional name filter Starting exploration, finding what exists
list_tables List tables in a dataset, with optional name filter Drilling into a specific dataset
get_table_metadata Table type, partitioning, clustering, row count, size Checking if a table is large before querying
describe_columns Column schema for a table (no data scan) Understanding the shape of a table cheaply
get_table Full bundle: metadata + columns + 3 sample rows Onboarding to an unfamiliar table
run_query SELECT-only with auto-LIMIT, dry-run cost guard, and bytes-billed cap Running ad-hoc SQL
estimate_query_cost Standalone dry-run — returns estimated bytes and USD cost Checking query cost before running it

🚀 Quick start

Recommended — run directly via uvx (no install needed):

uvx bq-readonly-mcp --project your-project-id --location US

From PyPI (persistent install):

uv tool install bq-readonly-mcp
bq-readonly-mcp --project your-project-id --location US

From source:

git clone https://github.com/mariadb-RupeshBiswas/bq-readonly-mcp.git
cd bq-readonly-mcp
uv run bq-readonly-mcp --project your-project-id --location US

For a full walkthrough (five steps from zero), see docs/QUICKSTART.md.


🔐 Authentication

The server uses Application Default Credentials (ADC). Run this once:

gcloud auth application-default login

For non-interactive environments (CI, containers, service accounts), pass a key file:

bq-readonly-mcp --project your-project-id --key-file /path/to/service-account.json

Or set GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json.


🔌 Plug it into your editor

Full walkthroughs for each client — config file paths, JSON snippets, restart steps — are in docs/EDITOR_SETUP.md.

Covered clients: Claude Code, Claude Desktop, Cursor, Windsurf, GitHub Copilot (VS Code), Cline, Continue.dev, Zed, Gemini CLI.

Claude Code — quick example:

claude mcp add --transport stdio bq-readonly -- \
  uvx bq-readonly-mcp --project your-project-id --location US

Or add to ~/.claude.json (global) or .mcp.json (project-level):

{
  "mcpServers": {
    "bq-readonly": {
      "command": "uvx",
      "args": [
        "bq-readonly-mcp",
        "--project", "your-project-id",
        "--location", "US"
      ]
    }
  }
}

Ready-to-paste configs for all supported clients are in mcp-config-examples/.


⚙️ Configuration reference

All flags can also be set via environment variables. CLI flags take precedence over env vars; env vars take precedence over defaults.

CLI flag Env var Default Description
--project GCP_PROJECT_ID (required) GCP project to query
--location BIGQUERY_LOCATION US BigQuery processing location
--datasets BIGQUERY_ALLOWED_DATASETS (none — all allowed) Space-separated dataset allowlist; comma-separated in env var
--default-limit BIGQUERY_DEFAULT_LIMIT 50 Rows injected by auto-LIMIT
--max-limit BIGQUERY_MAX_LIMIT 10000 Hard cap on per-query LIMIT
--max-bytes-billed BIGQUERY_MAX_BYTES_BILLED 1073741824 (1 GB) Per-query bytes-billed cap
--sample-rows BIGQUERY_SAMPLE_ROWS 3 Rows returned by get_table preview
--key-file GOOGLE_APPLICATION_CREDENTIALS (uses ADC) Path to service-account JSON

🛡️ Safety model

  1. SELECT/WITH only — The SQL validator strips comments, then rejects any statement that doesn't start with SELECT or WITH, or that contains DML/DDL keywords (INSERT, UPDATE, DELETE, DROP, CREATE, MERGE, …).
  2. Auto-LIMITLIMIT N is injected if absent. The caller can raise it up to --max-limit (default 10,000).
  3. Dry-run cost guard — Every run_query call first runs a dry-run to estimate cost. Queries exceeding --max-bytes-billed are refused before any bytes are billed.
  4. Dataset allowlist — Optional --datasets flag restricts access to named datasets. A startup warning is logged when unset.
  5. Defense in depthmaximumBytesBilled is also set on the real job as a server-side backstop.

Full details and threat model → SECURITY.md


🚫 What it does NOT do

  • Write operations of any kind (INSERT, UPDATE, DELETE, DDL) — by design, forever
  • Vector / embedding search — deferred to a future release
  • Multi-project queries — one server, one GCP project
  • Job history / audit log access — privacy footgun, intentionally omitted
  • Storage API (export, streaming reads)

These are intentional omissions. v0.1 focuses on safe, read-only schema exploration and SQL queries.


🤔 vs other BigQuery MCPs

Feature bq-readonly-mcp pvoo/bigquery-mcp ecosystem
Read-only enforced ✅ validator + zero write tools Varies by fork
Dry-run cost guard ✅ refuses over-budget queries Not standard
Auto-LIMIT injection ✅ default 50, cap 10,000 Not standard
Dataset allowlist ✅ optional --datasets Not standard
ADC auth
Vector / embedding search No (v0.1) Some forks
PyPI package bq-readonly-mcp Varies

💻 Development

# Install with dev deps
uv sync --extra dev

# Run unit tests (fast, no BigQuery required)
uv run pytest tests/unit/ -q

# Run integration tests (requires ADC + BigQuery access)
uv run pytest -m integration -q

# Lint
uv run ruff check src tests

# Type check
uv run mypy src

📜 License

MIT — see LICENSE

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选