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
Metadata
Release files for airgap-db-bridge 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| airgap_db_bridge-1.0.3.tar.gz | 29.6 kB | With provenance | Details for airgap_db_bridge-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| airgap_db_bridge-1.0.3-py3-none-any.whl | Python 3 | none | any | Details for airgap_db_bridge-1.0.3-py3-none-any.whl |
Total release size: 41.1 kB
Release files / airgap_db_bridge-1.0.3.tar.gz
| Download URL | airgap_db_bridge-1.0.3.tar.gz |
|---|---|
| Size | 29.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f31a57bed499e3527d28824d2a3a8893f72f0d0135a326e3a50d73b5d205e650
|
|
BLAKE2b-256 checksum How to use checksums |
5b89b307ab95dcadd83caf1eb7bea48ab81753e9e48fa50bcd42be55ea426a6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.
Transparency logRelease files / airgap_db_bridge-1.0.3-py3-none-any.whl
| Download URL | airgap_db_bridge-1.0.3-py3-none-any.whl |
|---|---|
| Size | 11.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
69ace3de34c01402c01baa802a82d6e4306a77710c66113829ee4ecd9b229f7c
|
|
BLAKE2b-256 checksum How to use checksums |
fc8f334e7eef4ca1a86716143184dab22e084d2bab185625a18c7dd81b3e2316
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.
Transparency logSecurity for airgap-db-bridge 1.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for airgap_db_bridge-1.0.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.