Back to MCP directory
publicPublicdnsLocal runtime

bigquery-analysis-mcp-server

BigQuery查询分析与执行MCP服务器

article

README

🚀 BigQuery 分析 MCP 服务器

这是一个运行于 Google BigQuery 之上的 MCP 服务器,可执行 SQL 查询。它具备查询验证、安全查询执行等功能,还能以结构化 JSON 格式返回查询结果,为数据查询工作提供了便利与保障。

🚀 快速开始

本 MCP 服务器可在 Google BigQuery 上执行 SQL 查询,具备查询验证、安全执行和以 JSON 格式返回结果等功能。

✨ 主要特性

工具

  • dry_run_query - 执行 BigQuery 查询的预执行操作
    • 验证查询并估计其处理规模
    • 检查查询大小是否符合 1TB 的限制
  • run_query_with_validation - 带验证地运行 BigQuery 查询
    • 检测并拒绝 DML 语句(数据修改查询)
    • 拒绝超过 1TB 数据处理的查询
    • 执行通过验证的查询并返回结果

📦 安装指南

前提条件

  • Node.js (v16 或更高版本)
  • Google Cloud 身份认证设置(gcloud CLI 或服务账户)

安装依赖项

npm install

构建

npm run build

开发模式(自动重建)

npm run watch

在 Claude Desktop 上使用

要在 Claude Desktop 上使用,请添加服务器配置:

  • MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "bigquery": {
      "command": "node",
      "args": ["/path/to/bigquery-server/build/index.js"]
    }
  }
}

调试

MCP 服务器通过标准输入输出(stdio)通信,因此调试可能较为困难。我们推荐使用 MCP Inspector

npm run inspector

Inspector 会提供一个 URL,用于在浏览器中访问调试工具。

身份认证设置

此服务器需要 Google Cloud 份数据进行认证。请按照以下方法之一完成设置:

  1. 使用 gcloud CLI 登录:
gcloud auth application-default login
  1. 使用服务账户密钥:
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account-key.json"

💻 使用示例

基础用法

# 查询预执行
dry_run_query("SELECT * FROM `bigquery-public-data.samples.shakespeare` LIMIT 10")

高级用法

# 带验证的查询执行
run_query_with_validation("SELECT word, word_count FROM `bigquery-public-data.samples.shakespeare` WHERE corpus='hamlet' LIMIT 10")
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client