BigQuery MCP Server
A Model Context Protocol (MCP) server that enables LLMs to interact with Google BigQuery.
README
BigQuery MCP Server
A Model Context Protocol (MCP) server that enables LLMs to interact with Google BigQuery. Built with FastMCP (Python) and designed for ephemeral cloud environments where only environment variables are available (no file-based credentials).
Features
| Tool | Description |
|---|---|
bq_list_datasets |
List all datasets in the configured project |
bq_list_tables |
List tables in a dataset with row counts and size in MB |
bq_get_schema |
Get the full schema of a table (columns, types, descriptions) |
bq_dry_run |
Validate SQL and estimate query cost (~$6.25/TB) |
bq_run_query |
Execute SQL and return results (auto-appends LIMIT 1000 if missing) |
Project Structure
bigquery-mcp-server/
├── src/
│ ├── server.py # Entry point — starts the MCP server
│ ├── constants.py # Global constants (BigQuery config, limits)
│ ├── tools/
│ │ └── bigquery.py # All 5 BigQuery tools
│ └── services/
│ ├── bigquery_client.py # BigQuery client factory + row serialization
│ └── error_handler.py # Centralized BigQuery error handling
├── main.py # Root-level entry point wrapper
├── Dockerfile # Multi-stage Docker build
├── docker-compose.yml # Server + MCP Inspector
├── docker-compose.dev.yml # Dev mode with hot-reload
├── mcp.json # MCP client configuration
├── pyproject.toml # Project metadata and dependencies
└── requirements.txt # Pip-compatible dependencies
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
BIGQUERY_PROJECT_ID |
Yes | — | GCP project ID (e.g. my-project-123) |
BIGQUERY_SERVICE_ACCOUNT_JSON_CONTENT |
Yes | — | Raw JSON string of the service account key |
BIGQUERY_LOCATION |
No | US |
BigQuery dataset region |
TRANSPORT |
No | stdio |
Transport mode: stdio or http |
PORT |
No | 8000 |
HTTP server port |
HOST |
No | 127.0.0.1 |
HTTP server bind address |
Authentication
This server authenticates using a service account JSON provided directly via environment variable — no file paths, no gcloud CLI.
- Create a service account in the GCP Console with at least:
- BigQuery Data Viewer (
roles/bigquery.dataViewer) - BigQuery Job User (
roles/bigquery.jobUser)
- BigQuery Data Viewer (
- Generate a JSON key for the service account
- Set the full JSON string as
BIGQUERY_SERVICE_ACCOUNT_JSON_CONTENT
export BIGQUERY_PROJECT_ID="my-project-123"
export BIGQUERY_SERVICE_ACCOUNT_JSON_CONTENT='{"type":"service_account","project_id":"...","private_key":"...","client_email":"...","...":"..."}'
Quick Start
Option A — uvx (Recommended)
No manual install needed. uvx downloads the package from PyPI, creates an isolated environment, and runs the server:
uvx bigquery-mcp-server
For MCP clients (Claude Code, Cursor, etc.), configure the server in your client's MCP config:
{
"mcpServers": {
"bigquery-mcp": {
"command": "uvx",
"args": ["bigquery-mcp-server"],
"env": {
"BIGQUERY_PROJECT_ID": "my-project-123",
"BIGQUERY_SERVICE_ACCOUNT_JSON_CONTENT": "{ ... }"
}
}
}
}
Note: Env vars must be passed explicitly via the
envblock in your MCP client config.
Option B — Local (virtualenv)
# Create virtual environment and install
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -e .
# Set credentials (or use a .env file)
export BIGQUERY_PROJECT_ID="my-project-123"
export BIGQUERY_SERVICE_ACCOUNT_JSON_CONTENT='{ ... }'
# Run in stdio mode
python main.py
# Or HTTP mode (for MCP Inspector)
TRANSPORT=http python main.py
Option C — Docker
# Set env vars in a .env file or export them, then:
docker compose up --build
# Open MCP Inspector at http://localhost:6274
# Connect to: http://mcp-server:8000/mcp (Streamable HTTP)
Option D — Dev mode with hot-reload
docker compose -f docker-compose.dev.yml up --build
# In another terminal:
npx @modelcontextprotocol/inspector
# Connect to: http://localhost:8000/mcp (Streamable HTTP)
Testing with MCP Inspector CLI
# List all tools
npx @modelcontextprotocol/inspector --cli \
--config mcp.json --server bigquery-mcp \
--method tools/list
# List datasets
npx @modelcontextprotocol/inspector --cli \
--config mcp.json --server bigquery-mcp \
--method tools/call --tool-name bq_list_datasets
# List tables in a dataset
npx @modelcontextprotocol/inspector --cli \
--config mcp.json --server bigquery-mcp \
--method tools/call --tool-name bq_list_tables \
--tool-arg 'params={"dataset": "my_dataset"}'
# Get table schema
npx @modelcontextprotocol/inspector --cli \
--config mcp.json --server bigquery-mcp \
--method tools/call --tool-name bq_get_schema \
--tool-arg 'params={"dataset": "my_dataset", "table": "my_table"}'
# Dry run a query
npx @modelcontextprotocol/inspector --cli \
--config mcp.json --server bigquery-mcp \
--method tools/call --tool-name bq_dry_run \
--tool-arg 'params={"sql": "SELECT * FROM my_dataset.my_table"}'
# Run a query
npx @modelcontextprotocol/inspector --cli \
--config mcp.json --server bigquery-mcp \
--method tools/call --tool-name bq_run_query \
--tool-arg 'params={"sql": "SELECT * FROM my_dataset.my_table LIMIT 10"}'
Connect to Claude Code
Using uvx (recommended):
claude mcp add bigquery-mcp uvx -- bigquery-mcp-server
Or add to ~/.claude/mcp.json:
{
"mcpServers": {
"bigquery-mcp": {
"command": "uvx",
"args": ["bigquery-mcp-server"],
"env": {
"BIGQUERY_PROJECT_ID": "my-project-123",
"BIGQUERY_SERVICE_ACCOUNT_JSON_CONTENT": "{ ... }"
}
}
}
}
Transports
| Transport | How to activate | When to use |
|---|---|---|
| stdio | TRANSPORT=stdio python -m src.server |
Claude Code, Cursor, local integration |
| HTTP | TRANSPORT=http python -m src.server |
MCP Inspector, remote servers |
Safety Features
- Auto LIMIT:
bq_run_queryautomatically appendsLIMIT 1000if no LIMIT clause is detected, preventing accidental large data transfers - Dry run:
bq_dry_runvalidates SQL and estimates cost before execution - Input validation: All tool inputs validated with Pydantic v2
- Error handling: BigQuery exceptions (403, 404, 400, etc.) are caught and returned as human-readable strings — the server never crashes
- Type serialization: Dates, datetimes, decimals, and bytes are automatically converted to JSON-safe types
References
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。