Labsco
takuya0206 logo

BigQuery

โ˜… 5

from takuya0206

Access Google BigQuery to understand dataset structures and execute SQL queries.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeAdvanced setup

BigQuery MCP Server

A Model Context Protocol (MCP) server for accessing Google BigQuery. This server enables Large Language Models (LLMs) to understand BigQuery dataset structures and execute SQL queries.

Features

Authentication and Connection Management

  • Supports Application Default Credentials (ADC) or service account key files
  • Configurable project ID and location settings
  • Authentication verification on startup

Tools

  1. query

    • Execute read-only (SELECT) BigQuery SQL queries
    • Configurable maximum results and bytes billed
    • Security checks to prevent non-SELECT queries
  2. list_all_datasets

    • List all datasets in the project
    • Returns an array of dataset IDs
  3. list_all_tables_with_dataset

    • List all tables in a specific dataset with their schemas
    • Requires a datasetId parameter
    • Returns table IDs, schemas, time partitioning information, and descriptions
  4. get_table_information

    • Get table schema and sample data (up to 20 rows)
    • Support for partitioned tables with partition filters
    • Warnings for queries on partitioned tables without filters
  5. dry_run_query

    • Check query validity and estimate cost without execution
    • Returns processing size and estimated cost

Security Features

  • Only SELECT queries are allowed (read-only access)
  • Default limit of 500GB for query processing to prevent excessive costs
  • Partition filter recommendations for partitioned tables
  • Secure handling of authentication credentials

Testing

You can use inspector for testing and debugging.

npx @modelcontextprotocol/inspector dist/bigquery-mcp-server --project-id={{your_own_project}}

Required Permissions

The service account or user credentials should have one of the following:

  • roles/bigquery.user (recommended)

Or both of these:

  • roles/bigquery.dataViewer (for reading table data)
  • roles/bigquery.jobUser (for executing queries)

Error Handling

The server provides detailed error messages for:

  • Authentication failures
  • Permission issues
  • Invalid queries
  • Missing partition filters
  • Excessive data processing requests

Code Structure

The server is organized into the following structure:

src/
โ”œโ”€โ”€ index.ts              # Entry point
โ”œโ”€โ”€ server.ts             # BigQueryMcpServer class
โ”œโ”€โ”€ types.ts              # Type definitions
โ”œโ”€โ”€ tools/                # Tool implementations
โ”‚   โ”œโ”€โ”€ query.ts          # query tool
โ”‚   โ”œโ”€โ”€ list-datasets.ts  # list_all_datasets tool
โ”‚   โ”œโ”€โ”€ list-tables.ts    # list_all_tables_with_dataset tool
โ”‚   โ”œโ”€โ”€ table-info.ts     # get_table_information tool
โ”‚   โ””โ”€โ”€ dry-run.ts        # dry_run_query tool
โ””โ”€โ”€ utils/                # Utility functions
    โ”œโ”€โ”€ args-parser.ts    # Command line argument parser
    โ””โ”€โ”€ query-utils.ts    # Query validation and response formatting