BigQuery Readonly MCP
Enables reading BigQuery data from ChatGPT using read-only SQL queries, with OAuth authentication and project-level access control.
README
BigQuery Readonly MCP
BigQuery Readonly MCP is a FastAPI-based Custom MCP server for safely querying BigQuery from ChatGPT. It is designed as a reusable internal analytics MCP: each tool accepts project_id, while the initial validation project is ice-sh.
Scope
- GitHub repository:
Growth-Management/bigquery-readonly-mcp - Cloud Run deploy project:
ice-sh - Initial BigQuery validation project:
ice-sh - Allowed email domain:
impress.co.jp - Default
maximumBytesBilled: 1GB - Default
max_results: 1000 - Default query timeout: 60 seconds
Security Model
The MCP server uses Google OAuth and BigQuery calls run with the authenticated user's access token. It does not use a service account to impersonate users for BigQuery query execution.
Users should receive the minimum required IAM permissions:
roles/bigquery.jobUseron the project where jobs are createdroles/bigquery.dataVieweron only the datasets they may inspect
The server enforces readonly SQL before execution. run_readonly_query and dry_run_query only allow one SELECT or WITH statement and reject DML, DDL, EXPORT, LOAD, grants, revokes, and procedure calls.
MCP Tools
list_projectslist_datasetslist_tablesget_table_schemadry_run_queryrun_readonly_query
All tools accept project_id where applicable. If omitted, the default is ice-sh.
Endpoints
GET /healthzGET /healthPOST /mcpGET /oauth/authorizeGET /oauth/callbackGET /.well-known/oauth-authorization-server
Use /health for Cloud Run external health checks. Cloud Run can reserve /healthz before requests reach the container, causing Google Frontend 404 responses even when the FastAPI app is healthy.
Local Development
Create a local environment and install dependencies:
python -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
Set local environment variables. Do not commit real secrets.
export BASE_URL="http://localhost:8080"
export GOOGLE_OAUTH_CLIENT_ID="..."
export GOOGLE_OAUTH_CLIENT_SECRET="..."
export SESSION_SECRET="replace-with-random-value"
export ALLOWED_DOMAIN="impress.co.jp"
export DEFAULT_PROJECT_ID="ice-sh"
export MAXIMUM_BYTES_BILLED="1073741824"
export MAX_RESULTS="1000"
export QUERY_TIMEOUT_SECONDS="60"
Run the app:
uvicorn app.main:app --host 0.0.0.0 --port 8080 --reload
Run tests:
pytest
OAuth Setup
Configure a Google OAuth Web application in ice-sh:
- Consent screen: internal or equivalent organization-limited configuration
- Authorized domain:
impress.co.jp - Redirect URI:
https://<cloud-run-url>/oauth/callback - Scopes:
openidemailprofilehttps://www.googleapis.com/auth/bigquery.readonly
Store these values in Secret Manager rather than the repository:
google-oauth-client-idgoogle-oauth-client-secretbigquery-mcp-session-secret
Cloud Run Deployment
The GitHub Actions workflow expects these GitHub Secrets:
GCP_PROJECT_ID:ice-shGCP_WORKLOAD_IDENTITY_PROVIDERGCP_DEPLOY_SERVICE_ACCOUNTBASE_URL: deployed Cloud Run URL or custom domain
The deploy service account needs only deployment permissions, such as Artifact Registry write and Cloud Run deploy permissions. It is not used for BigQuery query execution.
Deployment is managed per GCP project. The initial deployment target is ice-sh; when this MCP is rolled out to another project, create that project's own Cloud Run service, Artifact Registry repository, Secret Manager secrets, Workload Identity Federation bindings, and GitHub Secrets.
See docs/cloud-run.md for the full Phase 5 deployment procedure, including required APIs, Artifact Registry, Secret Manager, manual deploy, /health, and Cloud Logging checks.
See docs/github-actions-deploy.md for the preferred GitHub Actions deployment path using Workload Identity Federation.
Initial Validation On ice-sh
Use a user account in the allowed domain with the required BigQuery IAM permissions, then verify:
- MCP connects to
/mcp - Google OAuth login succeeds
- dataset list can be retrieved from
ice-sh - table list can be retrieved
- schema can be retrieved
- dry run returns estimated bytes processed
SELECTexecutes within limits- DML and DDL are rejected before BigQuery execution
- unauthorized projects return Access Denied
- audit logs are emitted to Cloud Logging
Audit Logging
Every tool call writes a single-line JSON audit event to stdout. Cloud Run ingests stdout into Cloud Logging, where the message, event_type, severity, and tool-specific fields can be filtered.
Each audit event includes:
severitymessagetimestampevent_typeuser_emailtoolproject_iddatasettablebytes_processedsuccesserror
Some fields may be empty when the tool does not target a dataset or table, or when validation fails before a BigQuery job is created.
Example Cloud Logging filter:
jsonPayload.event_type="bigquery_mcp_tool_call"
jsonPayload.project_id="ice-sh"
Current Phase Coverage
- Phase 1: FastAPI app,
/healthz,/health,/mcp, OAuth authorize/callback skeleton, user email lookup - Phase 2: six initial BigQuery tools
- Phase 3: readonly SQL guard,
maximumBytesBilled,max_results, timeout, basic query error handling - Phase 4: structured JSON audit logs are emitted to stdout for Cloud Logging ingestion
- Phase 5 prep: Docker, env example, Secret Manager policy, and Cloud Run deployment procedure are documented; live deploy and
/healthverification still require agcloudenvironment - Phase 6 prep: GitHub Actions workflow exists; Workload Identity Federation, IAM, and GitHub Secrets setup are documented
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。