Skip to main content

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

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

db_mcp_py-0.3.0.tar.gz (33.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

db_mcp_py-0.3.0-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file db_mcp_py-0.3.0.tar.gz.

File metadata

  • Download URL: db_mcp_py-0.3.0.tar.gz
  • Upload date:
  • Size: 33.5 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for db_mcp_py-0.3.0.tar.gz
Algorithm Hash digest
SHA256 cc73348abe64e2005146d61ef32089802044e39aeef1ede637b93020dbc4b112
MD5 4241d843f01cd13115eb03198ec51a3b
BLAKE2b-256 4cb41bde7279c222ad23b1cbf1592ee7349233a65fd0d2ce90f52b75df258595

See more details on using hashes here.

File details

Details for the file db_mcp_py-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: db_mcp_py-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for db_mcp_py-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 47b10dc4f33e914c8c80778d55f8f5b0dbc98bf08f7b668e62c05fcc8a139796
MD5 41ba589d79f7a59ec77f3abbe17d6f39
BLAKE2b-256 a0de401a607c54fc22fa598ba7b010aeacc0d4a89a7e82b20fd0b35b4efb1103

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page