Skip to main content

db-mcp-server

MCP server for MySQL, PostgreSQL, MongoDB, and SQLite databases. One instance per database, no Docker required.

Installation

uvx db-mcp-server

Configuration

Configure via environment variables. Each instance connects to a single database.

MySQL

Variable Required Default Description
DB_TYPE Yes — mysql
DB_DATABASE Yes — Database name
DB_PASSWORD Yes — Password
DB_HOST No localhost Host
DB_PORT No 3306 Port
DB_USER No root User
DB_MODE No read-only read-only or read-write

PostgreSQL

Variable Required Default Description
DB_TYPE Yes — postgresql
DB_DATABASE Yes — Database name
DB_PASSWORD Yes — Password
DB_HOST No localhost Host
DB_PORT No 5432 Port
DB_USER No postgres User
DB_MODE No read-only read-only or read-write

MongoDB

Variable Required Default Description
DB_TYPE Yes — mongodb
DB_DATABASE Yes — Database name
DB_URL Yes — Connection URL (mongodb://...)
DB_MODE No read-only read-only or read-write

SQLite

Variable Required Default Description
DB_TYPE Yes — sqlite
DB_PATH Yes — Path to .db file (local or remote with SSH)
DB_DATABASE No filename Display name
DB_MODE No read-only read-only or read-write

SSH Tunnel (MySQL / PostgreSQL)

Optionally connect through an SSH bastion host. Set SSH_HOST to activate.

For SQLite over SSH, the remote .db file is downloaded via SFTP before querying. In read-write mode, changes are uploaded back on shutdown.

Variable Required Default Description
SSH_HOST No — SSH bastion host (activates tunneling)
SSH_PORT No 22 SSH port
SSH_USER No Current OS user SSH username
SSH_KEY No — Path to private key (~/.ssh/id_rsa)
SSH_PASSWORD No — SSH password (if no key)

At least one of SSH_KEY or SSH_PASSWORD is required when SSH_HOST is set. SSH tunneling is not supported for MongoDB.

Usage in .mcp.json

SQLite (local)

{
  "mcpServers": {
    "db-local": {
      "command": "uvx",
      "args": ["db-mcp-server"],
      "env": {
        "DB_TYPE": "sqlite",
        "DB_PATH": "/path/to/database.db"
      }
    }
  }
}

SQLite over SSH

{
  "mcpServers": {
    "db-remote": {
      "command": "uvx",
      "args": ["db-mcp-server"],
      "env": {
        "DB_TYPE": "sqlite",
        "DB_PATH": "/remote/path/to/database.db",
        "SSH_HOST": "server.example.com",
        "SSH_USER": "deploy",
        "SSH_KEY": "~/.ssh/id_rsa"
      }
    }
  }
}
{
  "mcpServers": {
    "db-prod": {
      "command": "uvx",
      "args": ["db-mcp-server"],
      "env": {
        "DB_TYPE": "mysql",
        "DB_MODE": "read-only",
        "DB_HOST": "db.example.com",
        "DB_PORT": "3306",
        "DB_USER": "root",
        "DB_PASSWORD": "secret",
        "DB_DATABASE": "myapp"
      }
    }
  }
}

With SSH tunnel

{
  "mcpServers": {
    "db-behind-bastion": {
      "command": "uvx",
      "args": ["db-mcp-server"],
      "env": {
        "DB_TYPE": "postgresql",
        "DB_HOST": "10.0.0.5",
        "DB_PORT": "5432",
        "DB_USER": "postgres",
        "DB_PASSWORD": "secret",
        "DB_DATABASE": "myapp",
        "SSH_HOST": "bastion.example.com",
        "SSH_USER": "deploy",
        "SSH_KEY": "~/.ssh/id_rsa"
      }
    }
  }
}

For multiple databases, add multiple instances:

{
  "mcpServers": {
    "db-prod": {
      "command": "uvx",
      "args": ["db-mcp-server"],
      "env": { "DB_TYPE": "mysql", "DB_DATABASE": "prod", "..." : "..." }
    },
    "db-analytics": {
      "command": "uvx",
      "args": ["db-mcp-server"],
      "env": { "DB_TYPE": "postgresql", "DB_DATABASE": "analytics", "..." : "..." }
    },
    "db-staging": {
      "command": "uvx",
      "args": ["db-mcp-server"],
      "env": { "DB_TYPE": "mongodb", "DB_DATABASE": "staging", "..." : "..." }
    }
  }
}

Tools

MySQL

  • query — Execute read-only SQL (SELECT, SHOW, DESCRIBE, EXPLAIN, WITH)
  • execute — Execute write SQL (INSERT, UPDATE, DELETE) — requires DB_MODE=read-write
  • describe — Describe table structure
  • list_tables — List all tables
  • status — Show connection info

PostgreSQL

  • query — Execute read-only SQL (SELECT, SHOW, DESCRIBE, EXPLAIN, WITH)
  • execute — Execute write SQL (INSERT, UPDATE, DELETE) — requires DB_MODE=read-write
  • describe — Describe table structure (column info from information_schema)
  • list_tables — List all tables in the public schema
  • status — Show connection info

SQLite

  • query — Execute read-only SQL (SELECT, SHOW, DESCRIBE, EXPLAIN, WITH)
  • execute — Execute write SQL (INSERT, UPDATE, DELETE) — requires DB_MODE=read-write
  • describe — Describe table structure (PRAGMA table_info)
  • list_tables — List all tables
  • status — Show connection info

MongoDB

  • query — Find documents in a collection
  • describe — Collection stats ($collStats)
  • list_collections — List all collections
  • aggregate — Execute aggregation pipelines ($out/$merge blocked on read-only)
  • status — Show connection info

License

MIT

Metadata

Release files for db-mcp-server 1.2.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-server 1.2.1
File Size Uploaded
db_mcp_server-1.2.1.tar.gz 14.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for db-mcp-server 1.2.1
File Interpreter ABI Platform
db_mcp_server-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 32.2 kB

Release files / db_mcp_server-1.2.1.tar.gz

Download URL db_mcp_server-1.2.1.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
095c964ac2e245a636ab42e3233834799f486294c39b49cc651d13dd09e4a405
BLAKE2b-256 checksum
How to use checksums
80ab1099b128d80c6bac538abbca644653682cdb33cbaf02349df0214cbc4a78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Release files / db_mcp_server-1.2.1-py3-none-any.whl

Download URL db_mcp_server-1.2.1-py3-none-any.whl
Size 17.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eb1eaae26f524f9daeeecdb074b7cbf526f1fd5ca22286bad1da9da8db872094
BLAKE2b-256 checksum
How to use checksums
4a07809cfd669c7b81f88801db8bce5dd2c5cdf6237afe197ebf86e291becbc8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.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