Airgap DB Bridge
Bridge your AI assistant to PostgreSQL databases — query, execute, migrate, and analyze without cloud dependencies.
Features
- 6 Database Tools: Query, Execute, List Tables, Describe Table, Run Migration, Explain Analyze
- Security First: Parameterized queries only, read-only mode, connection pooling, audit logging
- Production Ready: Async connection pooling, configurable timeouts, structured logging
- Developer Experience: Type-safe Pydantic models, comprehensive tests, MCP Inspector compatible
Installation
From PyPI (when published)
pip install airgap-db-bridge
From Source
git clone https://github.com/airgap-fleet/db-bridge.git
cd db-bridge
pip install -e .
Docker
docker pull ghcr.io/airgap-fleet/db-bridge:latest
Quick Start
1. Configure Environment
cp .env.example .env
# Edit .env with your PostgreSQL connection details
2. Run Server
# Direct execution
airgap-db-bridge
# Or with Docker Compose (includes PostgreSQL)
docker-compose up -d
3. Configure MCP Client
Add to your MCP client configuration (Claude Desktop, Cursor, VS Code, etc.):
{
"mcpServers": {
"postgresql": {
"command": "airgap-db-bridge",
"env": {
"DB_BRIDGE_DSN": "postgresql://user:***@localhost:5432/db"
}
}
}
}
Configuration
| Environment Variable | Default | Description |
|---|---|---|
DB_BRIDGE_DSN |
postgresql://postgres:***@localhost:5432/postgres |
PostgreSQL connection string |
DB_BRIDGE_POOL_SIZE |
10 |
Connection pool size (1-100) |
DB_BRIDGE_READ_ONLY |
false |
Enable read-only mode (blocks write operations) |
DB_BRIDGE_QUERY_TIMEOUT |
30.0 |
Query timeout in seconds (0-300) |
DB_BRIDGE_LOG_LEVEL |
INFO |
Structured logging level |
Tools Reference
| Tool | Description | Parameters | Read-Only Safe |
|---|---|---|---|
query |
Execute parameterized SELECT query | sql (string), params (array, optional) |
✅ |
execute |
Execute INSERT/UPDATE/DELETE | sql (string), params (array, optional) |
❌ |
list_tables |
List tables in a schema | schema (string, default: "public") |
✅ |
describe_table |
Get table structure (columns, indexes, constraints) | table (string), schema (string, default: "public") |
✅ |
run_migration |
Run DDL statements in transaction | sql (string) |
❌ |
explain_analyze |
Get query execution plan with costs | sql (string), params (array, optional) |
✅ |
Usage Examples
Query Data
{
"tool": "query",
"arguments": {
"sql": "SELECT * FROM users WHERE age > $1 AND active = $2",
"params": [18, true]
}
}
Insert Data
{
"tool": "execute",
"arguments": {
"sql": "INSERT INTO users (name, email, age) VALUES ($1, $2, $3)",
"params": ["John Doe", "john@example.com", 30]
}
}
List Tables
{
"tool": "list_tables",
"arguments": {
"schema": "public"
}
}
Describe Table Structure
{
"tool": "describe_table",
"arguments": {
"table": "users",
"schema": "public"
}
}
Run Migration
{
"tool": "run_migration",
"arguments": {
"sql": "CREATE TABLE products (id SERIAL PRIMARY KEY, name TEXT NOT NULL, price DECIMAL(10,2)); CREATE INDEX idx_products_name ON products(name);"
}
}
Analyze Query Plan
{
"tool": "explain_analyze",
"arguments": {
"sql": "SELECT * FROM users JOIN orders ON users.id = orders.user_id WHERE users.id = $1",
"params": [1]
}
}
Security Model
Parameterized Queries Only
All SQL execution uses parameterized queries ($1, $2, etc.). String concatenation or interpolation is not supported — this prevents SQL injection by design.
Read-Only Mode
Set DB_BRIDGE_READ_ONLY=true to disable:
execute(INSERT/UPDATE/DELETE)run_migration(DDL)
Read operations (query, list_tables, describe_table, explain_analyze) remain available.
Connection Pooling
- Configurable pool size (1-100 connections)
- Automatic connection lifecycle management
- Query timeout enforcement
Audit Logging
All operations are logged with structured JSON including:
- Operation type and parameters (sanitized)
- Execution time
- Row counts affected
- Error details (if any)
Development
Prerequisites
- Python 3.11+
- PostgreSQL 14+ (for local development)
- uv (recommended) or pip
Setup
# Install uv if not present
pip install uv
# Create virtual environment and install dependencies
uv sync --dev
# Run tests
uv run pytest
# Type check
uv run mypy src/postgresql_mcp
# Lint and format
uv run ruff check .
uv run ruff format .
Running Tests with Local PostgreSQL
# Start PostgreSQL (Docker)
docker run -d --name pg-test -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres:16
# Run tests
DB_BRIDGE_TEST_DSN=postgresql://postgres:***@localhost:5432/postgres uv run pytest
# Cleanup
docker rm -f pg-test
MCP Inspector
npx @modelcontextprotocol/inspector uv run airgap-db-bridge
Architecture
db-bridge/
├── src/postgresql_mcp/
│ ├── __init__.py # Package exports
│ ├── models.py # Pydantic models (requests/responses/config)
│ ├── core.py # Business logic (asyncpg, zero FastMCP imports)
│ └── server.py # FastMCP app, tool registration, lifespan
├── tests/
│ ├── conftest.py # Test fixtures and setup
│ ├── test_models.py # Model validation tests
│ ├── test_core.py # Core business logic tests
│ └── test_tools.py # MCP tool integration tests
├── .github/workflows/ci.yml # CI/CD pipeline
├── Dockerfile # Multi-stage container build
├── docker-compose.yml # Local development stack
├── pyproject.toml # Project configuration (hatch)
└── README.md # This file
Design Principles
- Separation of Concerns:
core.pycontains zero FastMCP imports — fully testable in isolation - Type Safety: Pydantic v2 for all boundaries, mypy strict mode
- Async First: asyncpg for non-blocking database operations
- Security by Default: Parameterized queries, read-only mode, least privilege
- Observability: Structured JSON logging, execution timing, audit trails
CI/CD Pipeline
The GitHub Actions workflow (.github/workflows/ci.yml) runs on every push/PR:
- Lint — ruff check + format
- Type Check — mypy strict
- Test — pytest with PostgreSQL service, coverage ≥90%
- Build — hatch build + twine verify
- Publish — PyPI on release (trusted publishing)
- Docker — Multi-platform image on release
License
MIT License — see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make changes with tests
- Ensure CI passes (lint, typecheck, test, coverage)
- Submit a pull request
Support
- Issues: GitHub Issues
- Documentation: This README + inline docstrings
- MCP Specification: https://modelcontextprotocol.io
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file airgap_db_bridge-1.0.3.tar.gz.
File metadata
- Download URL: airgap_db_bridge-1.0.3.tar.gz
- Upload date:
- Size: 29.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f31a57bed499e3527d28824d2a3a8893f72f0d0135a326e3a50d73b5d205e650
|
|
| MD5 |
a57930a8110c9bdb596ca2a20ef9c120
|
|
| BLAKE2b-256 |
5b89b307ab95dcadd83caf1eb7bea48ab81753e9e48fa50bcd42be55ea426a6e
|
Provenance
The following attestation bundles were made for airgap_db_bridge-1.0.3.tar.gz:
Publisher:
ci.yml on Airgap-fleet/db-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
airgap_db_bridge-1.0.3.tar.gz -
Subject digest:
f31a57bed499e3527d28824d2a3a8893f72f0d0135a326e3a50d73b5d205e650 - Sigstore transparency entry: 2685028331
- Sigstore integration time:
-
Permalink:
Airgap-fleet/db-bridge@9f81213043231bc0e18880ad614d79cd84245c05 -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/Airgap-fleet
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@9f81213043231bc0e18880ad614d79cd84245c05 -
Trigger Event:
push
-
Statement type:
File details
Details for the file airgap_db_bridge-1.0.3-py3-none-any.whl.
File metadata
- Download URL: airgap_db_bridge-1.0.3-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69ace3de34c01402c01baa802a82d6e4306a77710c66113829ee4ecd9b229f7c
|
|
| MD5 |
08eefae2a8874a5729095139e4269f32
|
|
| BLAKE2b-256 |
fc8f334e7eef4ca1a86716143184dab22e084d2bab185625a18c7dd81b3e2316
|
Provenance
The following attestation bundles were made for airgap_db_bridge-1.0.3-py3-none-any.whl:
Publisher:
ci.yml on Airgap-fleet/db-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
airgap_db_bridge-1.0.3-py3-none-any.whl -
Subject digest:
69ace3de34c01402c01baa802a82d6e4306a77710c66113829ee4ecd9b229f7c - Sigstore transparency entry: 2685028340
- Sigstore integration time:
-
Permalink:
Airgap-fleet/db-bridge@9f81213043231bc0e18880ad614d79cd84245c05 -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/Airgap-fleet
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@9f81213043231bc0e18880ad614d79cd84245c05 -
Trigger Event:
push
-
Statement type: