Skip to main content
Glama
erayguner

GCP BigQuery MCP Server

by erayguner

GCP BigQuery MCP 服务器

CI MegaLinter TypeScript Node MCP SDK OpenTelemetry License: MIT PRs Welcome

用于 Google Cloud Platform BigQuery 的企业级 MCP (Model Context Protocol) 服务器,采用 工作负载身份联合 (Workload Identity Federation) 认证。通过模型上下文协议提供对 BigQuery 的安全、无密钥访问。

主要功能

  • 零服务账号密钥 - 100% 工作负载身份联合

  • Google Workspace 集成 - OIDC 用户认证

  • 符合 MCP 协议 - 遵循官方 MCP SDK 最佳实践

  • 多租户 - YAML 允许列表 + BigQuery 数据集上的 IAM 条件

  • 安全中间件 - 速率限制、提示注入检测、数据脱敏

  • Model Armor 预检 - 工具执行前的可选内容安全筛选

  • 私有服务连接 (PSC) - 面向企业消费者的可选私有入口

  • 客户管理加密 (CMEK) - BigQuery 数据集的 CMEK 加密

  • 全面的审计日志 - 7 年保留期以满足合规性要求

  • Terraform 基础设施 - 用于可重复部署的完整 IaC

  • Cloud Run 部署 - 无服务器、自动扩缩容架构

  • OpenTelemetry - 分布式追踪和按租户指标

Related MCP server: bq_mcp_server

项目结构

db-mcp/
├── src/                       # TypeScript source code
│   ├── auth/                  # WIF authentication modules
│   ├── bigquery/              # BigQuery client, discovery, optimization
│   ├── mcp/                   # MCP protocol handlers and tools
│   ├── security/              # Security middleware
│   ├── monitoring/            # Health checks and monitoring
│   ├── telemetry/             # OpenTelemetry instrumentation
│   ├── config/                # Configuration management
│   └── utils/                 # Logging utilities
├── tests/                     # Unit, integration, and performance tests
├── terraform/                 # Infrastructure as Code
│   └── modules/               # Reusable Terraform modules
├── docs/                      # Comprehensive documentation
├── scripts/                   # Deployment and utility scripts
├── examples/                  # Usage examples
├── .github/workflows/         # CI/CD automation
└── Dockerfile                 # Production container image

安全架构

传统方法(已弃用)

  • 存储在文件/密钥中的服务账号密钥

  • 永不过期的永久凭据

  • 需要手动轮换密钥

  • 凭据泄露风险高

工作负载身份联合(已实现)

  • 系统中无任何密钥

  • 1 小时令牌有效期,自动轮换

  • 基于属性的访问控制,实现细粒度权限管理

  • 完整的审计追踪,记录所有访问行为

  • 攻击面减少 90%

快速入门

前置条件

  • 已启用计费的 GCP 项目

  • Terraform >= 1.5.0

  • Node.js >= 22.0.0

  • Docker (用于容器化)

安装

# Clone and install dependencies
npm install

# Copy environment configuration
cp .env.example .env

# Build the project
npm run build

本地开发

# Development mode with hot reload
npm run dev

# Run tests
npm test

# Type checking
npm run typecheck

生产部署

# Build Docker image
docker build -t mcp-bigquery-server .

# Deploy infrastructure with Terraform
cd terraform
terraform init
terraform apply

# Deploy to Cloud Run
gcloud run deploy mcp-bigquery-server \
  --image gcr.io/YOUR_PROJECT/mcp-bigquery-server \
  --region us-central1

MCP 工具

该服务器提供以下 MCP 工具:

工具

描述

query_bigquery

在 BigQuery 数据集上执行 SQL 查询

list_datasets

列出所有可用的 BigQuery 数据集

list_tables

列出特定数据集中的表

get_table_schema

获取表的模式信息

服务器能力

  • 资源:BigQuery 数据集列表

  • 工具:查询执行和模式检查

  • Stderr 日志记录:所有日志输出到 stderr (兼容 JSON-RPC)

  • 优雅关闭:支持 SIGTERM/SIGINT 处理

架构

Client Request
  ↓
MCP Protocol Layer (JSON-RPC)
  ↓
Security Middleware (rate limiting, injection detection)
  ↓
Workload Identity Federation
  ↓ (OIDC Token)
Identity Pool
  ↓ (Attribute Mapping)
Service Account Impersonation
  ↓ (1-hour access token)
BigQuery API

核心组件

  1. 工作负载身份联合 - 带有 OIDC 提供商的开发/测试/生产身份池

  2. 安全中间件 - 速率限制、提示注入检测、SQL 注入防护

  3. BigQuery 集成 - 连接池、查询优化、数据集发现

  4. 监控 - 健康检查、OpenTelemetry 追踪、Cloud Monitoring 集成

文档

文档

描述

使用指南

本地开发、测试和生产的完整指南

架构

系统设计和组件文档

安全

安全中间件和最佳实践

WIF 指南

工作负载身份联合详细信息

部署

完整生产部署指南

Docker

容器配置

监控

可观测性设置

文档索引

完整文档地图

测试

# Run all tests
npm test

# Run specific test suites
npm run test:unit
npm run test:integration
npm run test:performance

# Run with coverage
npm run test:coverage

# Watch mode
npm run test:watch

开发命令

npm run build       # Build TypeScript
npm run dev         # Development with hot reload
npm run start       # Start production server
npm run lint        # Run ESLint
npm run lint:fix    # Fix linting issues
npm run format      # Format with Prettier
npm run typecheck   # TypeScript type checking

CI/CD

GitHub Actions 工作流自动执行:

  1. 在拉取请求上运行测试

  2. 构建并推送 Docker 镜像

  3. 在主分支上部署到 Cloud Run

  4. 使用工作负载身份联合(无密钥)

监控

  • Cloud Monitoring: 预配置仪表板,在 mcp.tool.calls.totalmcp.tool.call.duration 上具有 tenant_id 维度

  • Cloud Logging: 结构化 JSON 日志

  • Cloud Trace: 通过 OpenTelemetry 进行分布式追踪,带有 tenant.id 跨度属性

  • 审计日志: 在 BigQuery 中保留 7 年

  • 警报: 电子邮件/Slack 通知

合规性

  • GDPR: 数据驻留和访问日志记录

  • HIPAA: 访问控制和审计追踪

  • SOC 2: 身份管理和监控

  • PCI-DSS: 认证和授权

贡献

欢迎贡献!请参阅 CONTRIBUTING.md 获取指南。

许可证

MIT 许可证 - 详情请参阅 LICENSE

致谢


状态: 生产就绪 版本: 1.0.0 最后更新: 2026 年 4 月

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.

No tool schema history has been recorded yet.

Maintenance

ActivitySlowing
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    B
    maintenance
    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.
    1
    MIT
  • A
    license
    A
    quality
    C
    maintenance
    A Python MCP server that retrieves and caches BigQuery metadata (datasets, tables, columns) and enables secure SQL query execution with cost control, file export, and keyword search.
    6
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Production-ready MCP server for BigQuery that translates natural language questions to SQL, executes queries securely, and delivers results via stdio or HTTP for integration with GitHub Copilot, Power BI, and web applications.
    237
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    MCP server for secure BigQuery access across multiple Google Cloud projects, enabling querying, schema exploration, and data analysis with SQL validation and read-only controls.
    2
    MIT

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/erayguner/db-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server