Metadata-Version: 2.4
Name: bq_mcp_server
Version: 0.1.3
Summary: Python-based MCP (Model Context Protocol) server that retrieves dataset, table, and schema information from Google Cloud BigQuery
Project-URL: Homepage, https://github.com/takada-at/bq_mcp_server
Author-email: takada-at <takada-at@klab.com>
License: Copyright 2025 takada-at
        
        Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
License-File: LICENSE
Requires-Python: >=3.10
Requires-Dist: fastapi>=0.115.12
Requires-Dist: gcloud-aio-bigquery>=7.1.0
Requires-Dist: google-cloud-bigquery>=3.31.0
Requires-Dist: mcp[cli]>=1.6.0
Requires-Dist: pydantic>=2.11.3
Requires-Dist: python-dotenv>=1.1.0
Description-Content-Type: text/markdown

# BigQuery MCP Server

[![Python Version](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/)
[![Framework](https://img.shields.io/badge/Framework-FastAPI-green.svg)](https://fastapi.tiangolo.com/)

This is a Python-based MCP (Model Context Protocol) server that retrieves dataset, table, and schema information from Google Cloud BigQuery, caches it locally, and serves it via MCP. Its primary purpose is to enable generative AI systems to quickly understand BigQuery's structure and execute queries securely.

## Key Features

- **Metadata Management**: Retrieves and caches information about BigQuery datasets, tables, and columns
- **Keyword Search**: Supports keyword search of cached metadata
- **Secure Query Execution**: Provides SQL execution capabilities with automatic LIMIT clause insertion and cost control
- **MCP Compliance**: Offers tools via the Model Context Protocol

## MCP Server Tools

Available tools:

1. `get_datasets` - Retrieves a list of all datasets
2. `get_tables` - Retrieves all tables within a specified dataset (requires dataset_id, optionally accepts project_id)
3. `search_metadata` - Searches metadata for datasets, tables, and columns
4. `execute_query` - Safely executes BigQuery SQL queries with automatic LIMIT clause insertion and cost control
5. `check_query_scan_amount` - Retrieves the scan amount for BigQuery SQL queries

## Installation and Environment Setup
### Prerequisites

- Python 3.11 or later
- Google Cloud Platform account
- GCP project with BigQuery API enabled

### Install
uv

```bash
uv add bq_mcp_server
```

pip

```bash
pip install bq_mcp_server
```

### Installing Dependencies

This project uses `uv` for package management:

```bash
# Install uv if not already installed
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install dependencies
uv sync
```

### Configuring Option

For a list of configuration values, see:

[docs/settings.md](./docs/settings.md)


## MCP Setting

```json
{
    "mcpServers": {
        "bq_mcp_server": {
            "command": "uv",
            "args": [
                "run",
                "--directory",
                "<your install directory>",
                "bq_mcp_server"
            ],
            "env": {
                "PYTHONPATH": "<your install directory>",
                "PROJECT_IDS": "<your project id>"
            }
        }
    }
}
```

## Running Tests

### Running All Tests

```bash
pytest
```

### Running Specific Test Files

```bash
pytest tests/test_logic.py
```

### Running Specific Test Functions

```bash
pytest -k test_function_name
```

### Checking Test Coverage

```bash
pytest --cov=bq_mcp_server
```

## Local Development

### Starting the MCP Server

```bash
uv run bq_mcp_server
```

### Starting the FastAPI REST API Server

```bash
uvicorn bq_mcp_server.adapters.web:app --reload
```

### Development Commands

#### Code Formatting and Linting

```bash
# Code formatting
ruff format

# Linting checks
ruff check

# Automatic fixes
ruff check --fix
```

#### Dependency Management

```bash
# Adding new dependencies
uv add <package>

# Adding development dependencies
uv add --dev <package>

# Updating dependencies
uv sync
```
