Installation & Setup¶
Prerequisites¶
- Python: 3.10 or higher
- Google Cloud SDK: Required for authentication
- BigQuery API: Must be enabled in your GCP project
Installation¶
From PyPI (Recommended)¶
Or with uv:
From Source¶
Verify Installation¶
Authentication¶
Quick Setup (Local Development)¶
# Login with your Google account
gcloud auth application-default login
# Set default project
gcloud config set project YOUR_PROJECT_ID
# Verify authentication
gcloud auth application-default print-access-token
Service Account (Production)¶
# Create service account
gcloud iam service-accounts create mcp-bigquery \
--display-name="MCP BigQuery Service Account"
# Grant permissions
gcloud projects add-iam-policy-binding YOUR_PROJECT_ID \
--member="serviceAccount:mcp-bigquery@YOUR_PROJECT_ID.iam.gserviceaccount.com" \
--role="roles/bigquery.jobUser"
# Generate key file
gcloud iam service-accounts keys create key.json \
--iam-account="mcp-bigquery@YOUR_PROJECT_ID.iam.gserviceaccount.com"
# Use the key
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/key.json"
Required Permissions¶
MCP BigQuery needs these IAM roles: - roles/bigquery.jobUser
- Create and run dry-run jobs - roles/bigquery.dataViewer
- Access table metadata
Configuration¶
Environment Variables¶
# Google Cloud Project (optional, uses default from gcloud)
export BQ_PROJECT="your-project-id"
# BigQuery Location (optional)
export BQ_LOCATION="US" # or EU, asia-northeast1, etc.
# Cost estimation price per TiB (optional, default: 5.0)
export SAFE_PRICE_PER_TIB="5.0"
# Service account key (optional)
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/key.json"
Claude Code Configuration¶
Add to your Claude Code configuration file:
{
"mcpServers": {
"mcp-bigquery": {
"command": "mcp-bigquery",
"env": {
"BQ_PROJECT": "your-project-id",
"BQ_LOCATION": "US",
"SAFE_PRICE_PER_TIB": "5.0"
}
}
}
}
Or if installed from source:
{
"mcpServers": {
"mcp-bigquery": {
"command": "python",
"args": ["-m", "mcp_bigquery"],
"env": {
"BQ_PROJECT": "your-project-id"
}
}
}
}
Quick Start¶
Your First Validation¶
Validate a simple SQL query:
Response:
Check Query Cost¶
Estimate cost using a public dataset:
{
"tool": "bq_dry_run_sql",
"arguments": {
"sql": "SELECT * FROM `bigquery-public-data.samples.shakespeare` WHERE word_count > 100"
}
}
Response:
{
"totalBytesProcessed": 65536,
"usdEstimate": 0.00032,
"referencedTables": [{
"project": "bigquery-public-data",
"dataset": "samples",
"table": "shakespeare"
}],
"schemaPreview": [
{"name": "word", "type": "STRING", "mode": "NULLABLE"},
{"name": "word_count", "type": "INT64", "mode": "NULLABLE"}
]
}
Using Parameters¶
{
"tool": "bq_validate_sql",
"arguments": {
"sql": "SELECT * FROM users WHERE created_date = @date",
"params": {
"date": "2024-01-01"
}
}
}
Troubleshooting¶
Authentication Errors¶
"Could not automatically determine credentials"
"Permission denied"
gcloud projects add-iam-policy-binding YOUR_PROJECT \
--member="user:your-email@example.com" \
--role="roles/bigquery.jobUser"
Common Issues¶
Command 'mcp-bigquery' not found
Project not found
BigQuery API not enabled
Security Best Practices¶
- Never commit credentials - Use environment variables or secret managers
- Use service accounts - Create dedicated accounts with minimal permissions
- Rotate keys regularly - Set up key rotation policies
- Enable audit logging - Track all BigQuery operations
Next Steps¶
- Learn about SQL Validation and Analysis
- See API Reference for detailed tool documentation
- Check out Examples for real-world use cases