DBHub 是一个通用数据库网关,实现了模型上下文协议 (MCP) 服务器接口。该网关允许兼容 MCP 的客户端连接并探索不同的数据库。
+------------------+ +--------------+ +------------------+
| | | | | |
| | | | | |
| Claude Desktop +--->+ +--->+ PostgreSQL |
| | | | | |
| Cursor +--->+ DBHub +--->+ SQL Server |
| | | | | |
| Other MCP +--->+ +--->+ SQLite |
| Clients | | | | |
| | | +--->+ MySQL |
| | | | | |
| | | +--->+ MariaDB |
| | | | | |
| | | +--->+ Oracle |
| | | | | |
+------------------+ +--------------+ +------------------+
MCP Clients MCP Server Databases
演示 SSE 端点
https://demo.dbhub.ai/sse连接了一个示例员工数据库。您可以将 Cursor 或 MCP Inspector 指向该数据库,以查看其实际运行情况。

Related MCP server: Supabase MCP Server
支持矩阵
数据库资源
资源名称 | URI 格式 | PostgreSQL | MySQL | MariaDB | SQL 服务器 | SQLite | 甲骨文 |
模式 | db://schemas
| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
表结构 | db://schemas/{schemaName}/tables
| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
表结构 | db://schemas/{schemaName}/tables/{tableName}
| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
表中索引 | db://schemas/{schemaName}/tables/{tableName}/indexes
| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
过程_在_架构中 | db://schemas/{schemaName}/procedures
| ✅ | ✅ | ✅ | ✅ | ❌ | ✅ |
过程详细信息 | db://schemas/{schemaName}/procedures/{procedureName}
| ✅ | ✅ | ✅ | ✅ | ❌ | ✅ |
数据库工具
工具 | 命令名称 | PostgreSQL | MySQL | MariaDB | SQL 服务器 | SQLite | 甲骨文 |
执行 SQL | execute_sql
| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
列出连接器 | list_connectors
| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
提示功能
迅速的 | 命令名称 | PostgreSQL | MySQL | MariaDB | SQL 服务器 | SQLite | 甲骨文 |
生成 SQL | generate_sql
| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
解释数据库元素 | explain_db
| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
安装
Docker
# PostgreSQL example
docker run --rm --init \
--name dbhub \
--publish 8080:8080 \
bytebase/dbhub \
--transport sse \
--port 8080 \
--dsn "postgres://user:password@localhost:5432/dbname?sslmode=disable"
# Demo mode with sample employee database
docker run --rm --init \
--name dbhub \
--publish 8080:8080 \
bytebase/dbhub \
--transport sse \
--port 8080 \
--demo
# Oracle example
docker run --rm --init \
--name dbhub \
--publish 8080:8080 \
bytebase/dbhub \
--transport sse \
--port 8080 \
--dsn "oracle://username:password@localhost:1521/service_name"
# Oracle example with thick mode for connecting to 11g or older
docker run --rm --init \
--name dbhub \
--publish 8080:8080 \
bytebase/dbhub-oracle-thick \
--transport sse \
--port 8080 \
--dsn "oracle://username:password@localhost:1521/service_name"
新公共管理
# PostgreSQL example
npx @bytebase/dbhub --transport sse --port 8080 --dsn "postgres://user:password@localhost:5432/dbname?sslmode=disable"
# Demo mode with sample employee database
npx @bytebase/dbhub --transport sse --port 8080 --demo
注意:演示模式包括捆绑的 SQLite 示例“员工”数据库,其中包含员工、部门、工资等表。
克劳德桌面

// claude_desktop_config.json
{
"mcpServers": {
"dbhub-postgres-docker": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"bytebase/dbhub",
"--transport",
"stdio",
"--dsn",
// Use host.docker.internal as the host if connecting to the local db
"postgres://user:password@host.docker.internal:5432/dbname?sslmode=disable"
]
},
"dbhub-postgres-npx": {
"command": "npx",
"args": [
"-y",
"@bytebase/dbhub",
"--transport",
"stdio",
"--dsn",
"postgres://user:password@localhost:5432/dbname?sslmode=disable"
]
},
"dbhub-demo": {
"command": "npx",
"args": ["-y", "@bytebase/dbhub", "--transport", "stdio", "--demo"]
}
}
}
光标

用法
SSL 连接
您可以使用 DSN 字符串中的sslmode参数指定 SSL 模式:
数据库 | sslmode=disable
| sslmode=require
| 默认 SSL 行为 |
PostgreSQL | ✅ | ✅ | 证书验证 |
MySQL | ✅ | ✅ | 证书验证 |
MariaDB | ✅ | ✅ | 证书验证 |
SQL 服务器 | ✅ | ✅ | 证书验证 |
甲骨文 | ✅ | ✅ | N/A(使用 Oracle 客户端配置) |
SQLite | ❌ | ❌ | N/A(基于文件) |
SSL 模式选项:
如果不指定sslmode ,大多数数据库默认使用证书验证,这提供了最高级别的安全性。
使用示例:
# Disable SSL
postgres://user:password@localhost:5432/dbname?sslmode=disable
# Require SSL without certificate verification
postgres://user:password@localhost:5432/dbname?sslmode=require
# Standard SSL with certificate verification (default)
postgres://user:password@localhost:5432/dbname
只读模式
您可以在只读模式下运行 DBHub,这会将 SQL 查询执行限制为只读操作:
# Enable read-only mode
npx @bytebase/dbhub --readonly --dsn "postgres://user:password@localhost:5432/dbname"
在只读模式下,只允许进行只读 SQL 操作。
这在连接到生产数据库时提供了额外的安全层。
配置数据库连接
您可以在演示模式下使用 DBHub 和示例员工数据库进行测试:
npx @bytebase/dbhub --demo
对于真实数据库,需要数据库源名称 (DSN)。您可以通过以下几种方式提供此信息:
命令行参数(最高优先级):
npx @bytebase/dbhub --dsn "postgres://user:password@localhost:5432/dbname?sslmode=disable"
环境变量(第二优先级):
export DSN="postgres://user:password@localhost:5432/dbname?sslmode=disable"
npx @bytebase/dbhub
环境文件(第三优先级):
警告:在 Docker 中运行时,请使用host.docker.internal而不是localhost来连接主机上运行的数据库。例如: mysql://user:password@host.docker.internal:3306/dbname
DBHub支持以下数据库连接字符串格式:
数据库 | DSN 格式 | 例子 |
MySQL | mysql://[user]:[password]@[host]:[port]/[database]
| mysql://user:password@localhost:3306/dbname?sslmode=disable
|
MariaDB | mariadb://[user]:[password]@[host]:[port]/[database]
| mariadb://user:password@localhost:3306/dbname?sslmode=disable
|
PostgreSQL | postgres://[user]:[password]@[host]:[port]/[database]
| postgres://user:password@localhost:5432/dbname?sslmode=disable
|
SQL 服务器 | sqlserver://[user]:[password]@[host]:[port]/[database]
| sqlserver://user:password@localhost:1433/dbname?sslmode=disable
|
SQLite | sqlite:///[path/to/file]
或 sqlite::memory:
| sqlite:///path/to/database.db
sqlite:C:/Users/YourName/data/database.db (windows)
或 sqlite::memory:
|
甲骨文 | oracle://[user]:[password]@[host]:[port]/[service_name]
| oracle://username:password@localhost:1521/service_name?sslmode=disable
|
甲骨文
如果您看到错误“NJS-138:在 Thin 模式下,node-oracledb 不支持与此数据库服务器版本的连接”,则需要按照如下所述使用 Thick 模式。
Docker
使用bytebase/dbhub-oracle-thick代替bytebase/dbhub docker 镜像。
NPX
下载并安装适合您的平台的Oracle Instant Client
将ORACLE_LIB_DIR环境变量设置为 Oracle Instant Client 的路径:
# Set environment variable to Oracle Instant Client directory
export ORACLE_LIB_DIR=/path/to/instantclient_19_8
# Then run DBHub
npx @bytebase/dbhub --dsn "oracle://username:password@localhost:1521/service_name"
SQL 服务器
额外的查询参数:
验证
运输
命令行选项
选项 | 描述 | 默认 |
演示 | 使用示例员工数据库以演示模式运行 | false
|
域名系统 | 数据库连接字符串 | 如果非处于演示模式则为必填项 |
运输 | 传输模式: stdio
或 sse
| stdio
|
港口 | HTTP 服务器端口(仅在使用 --transport=sse
时适用) | 8080
|
只读 | 将 SQL 执行限制为只读操作 | false
|
演示模式使用内存 SQLite 数据库,其中加载了示例员工数据库,其中包含员工、部门、职称、薪资、部门员工和部门经理等表格。示例数据库包含用于创建表、加载数据和测试的 SQL 脚本。
发展
安装依赖项:
以开发模式运行:
为生产而构建:
pnpm build
pnpm start --transport stdio --dsn "postgres://user:password@localhost:5432/dbname?sslmode=disable"
测试
项目采用Vitest进行测试:
预提交钩子(针对开发人员)
该项目包括预提交挂钩,用于在每次提交之前自动运行测试:
克隆存储库后,设置预提交挂钩:
这可确保每次创建提交时测试套件都会自动运行,从而防止破坏测试的提交。
标准输入输出
# PostgreSQL example
TRANSPORT=stdio DSN="postgres://user:password@localhost:5432/dbname?sslmode=disable" npx @modelcontextprotocol/inspector node /path/to/dbhub/dist/index.js
上交所
# Start DBHub with SSE transport
pnpm dev --transport=sse --port=8080
# Start the MCP Inspector in another terminal
npx @modelcontextprotocol/inspector
连接到 DBHub 服务器/sse端点
贡献者
星史
