Skip to main content

db-mcp-py

Multi-database MCP server with built-in SSH tunnels, read-only mode, and schema filtering.

Credits & References

This project is a Python reimplementation inspired by FreePeak/db-mcp-server (Go, MIT License, 372+ stars). The original project provides multi-database MCP support for MySQL, PostgreSQL, SQLite, Oracle, and TimescaleDB.

Why rewrite? We needed features the upstream doesn't provide and the solo-maintainer project has slow response times:

  • Built-in SSH tunnel management (jump hosts, port forwarding)
  • Read-only mode by default (no accidental writes)
  • Schema filtering (whitelist specific schemas per connection)
  • Environment variable expansion in config
  • Graceful degradation (if 1 of N databases is unreachable, serve the rest)
  • VPN/network detection before connecting
  • Python ecosystem integration (uvx, PyPI, MCP SDK)

Features

  • Multi-database: Connect to PostgreSQL, MySQL/MariaDB, Oracle, and MongoDB simultaneously
  • SSH tunnels: Built-in asyncssh tunnels with jump host support — no external scripts needed
  • Read-only: Only query and schema tools exposed. No execute, transaction, or DDL
  • Schema filtering: Per-connection schemas whitelist — only expose relevant tables
  • Env var expansion: Use ${DB_PASSWORD}, ${HOME} etc. in config
  • Graceful degradation: Unreachable databases are skipped, rest keeps working
  • Network detection: Optional VPN check before attempting connections (TCP probe fallback)
  • Reconnect: Automatic retry on connection loss with exponential backoff
  • Unified tools: Single query tool with database parameter (inspired by FreePeak v1.9.0)

Installation

# Via uvx (recommended)
uvx db-mcp-py --config config.json

# Via pip
pip install db-mcp-py
db-mcp-py --config config.json

Configuration

{
  "defaults": {
    "read_only": true,
    "query_timeout": 30,
    "max_connections": 5
  },
  "connections": [
    {
      "id": "mir_dev",
      "host": "10.202.171.138",
      "port": 5433,
      "database": "p9scdevmir",
      "user": "mir_intranet",
      "password": "${MIR_DEV_PASSWORD}",
      "schemas": ["mir", "public"],
      "require_vpn": true
    },
    {
      "id": "sicar_dev",
      "host": "localhost",
      "port": 5433,
      "database": "car_nacional",
      "user": "car_nacional",
      "schemas": ["usr_geocar_aplicacao"],
      "tunnel": {
        "ssh_host": "coreapi-sicar-dev",
        "remote_host": "localhost",
        "remote_port": 5433,
        "local_port": 5435
      }
    },
    {
      "id": "coreapi_dev",
      "host": "localhost",
      "port": 5433,
      "database": "pgsc_dev_coreapi",
      "user": "postgres",
      "tunnel": {
        "ssh_host": "coreapi-db-dev",
        "remote_host": "localhost",
        "remote_port": 5433,
        "local_port": 5434
      }
    }
  ]
}

Tunnel with jump host

{
  "tunnel": {
    "ssh_host": "target-server",
    "jump_host": "bastion.example.com",
    "remote_host": "localhost",
    "remote_port": 5433,
    "local_port": 5435
  }
}

MySQL/MariaDB connection

{
  "id": "my_mysql",
  "type": "mysql",
  "host": "mysql-server.internal",
  "port": 3306,
  "database": "app_db",
  "user": "readonly_user",
  "password": "${MYSQL_PASSWORD}",
  "schemas": ["app_db"],
  "require_vpn": true
}

Install the MySQL driver: pip install db-mcp-py[mysql] or uvx --with aiomysql db-mcp-py

MCP Tools

Tool Description
list_databases List all connected databases with status
query Execute read-only SQL query on a database
schema Get table/column information for a database

License

MIT — see LICENSE.

Metadata

Release files for db-mcp-py 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for db-mcp-py 0.3.1
File Size Uploaded
db_mcp_py-0.3.1.tar.gz 33.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for db-mcp-py 0.3.1
File Interpreter ABI Platform
db_mcp_py-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 50.9 kB

Release files / db_mcp_py-0.3.1.tar.gz

Download URL db_mcp_py-0.3.1.tar.gz
Size 33.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f63e58dfba5602807c5c3416627f0c9cc0e830c93740032174028aa3a312c4c7
BLAKE2b-256 checksum
How to use checksums
46dd04f39aa2c0535b962be94fbe86ea75557b7f7a5bfabeaf876771047a2e35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / db_mcp_py-0.3.1-py3-none-any.whl

Download URL db_mcp_py-0.3.1-py3-none-any.whl
Size 17.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e85a7d414980e6aebcc0be62d6ed0c9a0195db062ab2b89db6c73da14694763
BLAKE2b-256 checksum
How to use checksums
1681e591e34227ad6206facb767911dda45d281848c4426206fbe1c7a7cd044f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page