DB MCP Server

io.github.stucchi由 GitHub 账号 stucchi 发布v1.2.1更新于 Oct 24, 2026

Database MCP server for MySQL, PostgreSQL, MongoDB, and SQLite with SSH tunneling support.

已验证STDIO仅桌面数据库开发者工具

概览

AI 生成的概览

本地 MCP 服务器,让助手查询 MySQL、PostgreSQL、MongoDB 或 SQLite 数据库,并在读写模式下修改数据,可选经 SSH 隧道连接。

可以做什么
在 MySQL、PostgreSQL 和 SQLite 上执行只读 SQL 查询并查看结果,或在 MongoDB 集合中查找文档并运行聚合管道(只读模式下阻止 $out/$merge)。列出表或集合,并描述表结构或集合统计信息。显示连接状态与信息。启用读写模式后可执行 INSERT、UPDATE、DELETE 等写入 SQL。MySQL 和 PostgreSQL 可经 SSH 堡垒机连接,远程 SQLite 文件会先通过 SFTP 下载再查询。
适用场景
适合让助手探查数据库结构、基于实时数据回答问题,或在不另开客户端的情况下做受控的数据修改。适用于本地桌面环境,包括只能通过堡垒机访问的数据库。
运行要求
以 Python 包形式通过 uvx 在本地运行,需要 Python/uv 运行环境。每个实例连接一个数据库。需设置 DB_TYPE 和 DB_DATABASE,并按需设置 DB_HOST、DB_PORT、DB_USER;MySQL 和 PostgreSQL 需要 DB_PASSWORD,MongoDB 需要 DB_URL,SQLite 需要 DB_PATH。使用 SSH 隧道需设置 SSH_HOST 并提供 SSH_KEY 或 SSH_PASSWORD。需要能访问数据库或堡垒机的网络。
安装前请注意
数据库凭据通过环境变量传入,包括 DB_PASSWORD、DB_URL 和 SSH_PASSWORD,以及通过 SSH_KEY 指定 SSH 私钥路径。默认模式为只读,但将 DB_MODE 设为 read-write 后,execute 工具可执行 INSERT、UPDATE 和 DELETE;SQLite 经 SSH 时,改动会在关闭时上传回远程文件。建议使用最小权限账号,非必要不要指向生产数据。

安装

在 SourceWeft 中

  1. 打开 控制台中的 DB MCP Server,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

db-mcp-server

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

Installation

bash
uvx db-mcp-server

Configuration

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

MySQL

VariableRequiredDefaultDescription
DB_TYPEYes—mysql
DB_DATABASEYes—Database name
DB_PASSWORDYes—Password
DB_HOSTNolocalhostHost
DB_PORTNo3306Port
DB_USERNorootUser
DB_MODENoread-onlyread-only or read-write

PostgreSQL

VariableRequiredDefaultDescription
DB_TYPEYes—postgresql
DB_DATABASEYes—Database name
DB_PASSWORDYes—Password
DB_HOSTNolocalhostHost
DB_PORTNo5432Port
DB_USERNopostgresUser
DB_MODENoread-onlyread-only or read-write

MongoDB

VariableRequiredDefaultDescription
DB_TYPEYes—mongodb
DB_DATABASEYes—Database name
DB_URLYes—Connection URL (mongodb://...)
DB_MODENoread-onlyread-only or read-write

SQLite

VariableRequiredDefaultDescription
DB_TYPEYes—sqlite
DB_PATHYes—Path to .db file (local or remote with SSH)
DB_DATABASENofilenameDisplay name
DB_MODENoread-onlyread-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.

VariableRequiredDefaultDescription
SSH_HOSTNo—SSH bastion host (activates tunneling)
SSH_PORTNo22SSH port
SSH_USERNoCurrent OS userSSH username
SSH_KEYNo—Path to private key (~/.ssh/id_rsa)
SSH_PASSWORDNo—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)

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

SQLite over SSH

json
{  "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"      }    }  }}
json
{  "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

json
{  "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:

json
{  "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

来源:README.md,提交 c45f307

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v1.2.1最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分