Skip to main content
Glama

DBHub

by bytebase

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 指向该数据库,以查看其实际运行情况。

mcp 检查器

支持矩阵

数据库资源

资源名称URI 格式PostgreSQLMySQLMariaDBSQL 服务器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}

数据库工具

工具命令名称PostgreSQLMySQLMariaDBSQL 服务器SQLite甲骨文
执行 SQLexecute_sql
列出连接器list_connectors

提示功能

迅速的命令名称PostgreSQLMySQLMariaDBSQL 服务器SQLite甲骨文
生成 SQLgenerate_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=disablesslmode=require默认 SSL 行为
PostgreSQL证书验证
MySQL证书验证
MariaDB证书验证
SQL 服务器证书验证
甲骨文N/A(使用 Oracle 客户端配置)
SQLiteN/A(基于文件)

SSL 模式选项:

  • sslmode=disable :关闭所有 SSL/TLS 加密。数据以明文形式传输。
  • sslmode=require :连接已加密,但不验证服务器证书。这可以防止数据包嗅探,但不能防止中间人攻击。您可以使用受信任的自签名 CA 进行此设置。

如果不指定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
  • 环境文件(第三优先级):
    • 对于开发:使用您的 DSN 创建.env.local
    • 对于生产:使用您的 DSN GXP14 创建.env

警告:在 Docker 中运行时,请使用host.docker.internal而不是localhost来连接主机上运行的数据库。例如: mysql://user:password@host.docker.internal:3306/dbname

DBHub支持以下数据库连接字符串格式:

数据库DSN 格式例子
MySQLmysql://[user]:[password]@[host]:[port]/[database]mysql://user:password@localhost:3306/dbname?sslmode=disable
MariaDBmariadb://[user]:[password]@[host]:[port]/[database]mariadb://user:password@localhost:3306/dbname?sslmode=disable
PostgreSQLpostgres://[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
SQLitesqlite:///[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
  1. 下载并安装适合您的平台的Oracle Instant Client
  2. 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 服务器

额外的查询参数:

验证
  • authentication=azure-active-directory-access-token 。 仅适用于从 Azure 运行时。请参阅DefaultAzureCredential

运输

  • stdio (默认)-用于与 Claude Desktop 等工具直接集成:
    npx @bytebase/dbhub --transport stdio --dsn "postgres://user:password@localhost:5432/dbname?sslmode=disable"
  • **sse——**适用于浏览器和网络客户端:
    npx @bytebase/dbhub --transport sse --port 5678 --dsn "postgres://user:password@localhost:5432/dbname?sslmode=disable"

命令行选项

选项描述默认
演示使用示例员工数据库以演示模式运行false
域名系统数据库连接字符串如果非处于演示模式则为必填项
运输传输模式: stdiossestdio
港口HTTP 服务器端口(仅在使用--transport=sse时适用)8080
只读将 SQL 执行限制为只读操作false

演示模式使用内存 SQLite 数据库,其中加载了示例员工数据库,其中包含员工、部门、职称、薪资、部门员工和部门经理等表格。示例数据库包含用于创建表、加载数据和测试的 SQL 脚本。

发展

  1. 安装依赖项:
    pnpm install
  2. 以开发模式运行:
    pnpm dev
  3. 为生产而构建:
    pnpm build pnpm start --transport stdio --dsn "postgres://user:password@localhost:5432/dbname?sslmode=disable"

测试

项目采用Vitest进行测试:

  • 运行测试: pnpm test
  • 在监视模式下运行测试: pnpm test:watch
预提交钩子(针对开发人员)

该项目包括预提交挂钩,用于在每次提交之前自动运行测试:

  1. 克隆存储库后,设置预提交挂钩:
    ./scripts/setup-husky.sh
  2. 这可确保每次创建提交时测试套件都会自动运行,从而防止破坏测试的提交。

使用MCP Inspector进行调试

标准输入输出
# 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端点

贡献者

星史

-
security - not tested
A
license - permissive license
-
quality - not tested

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

通用数据库 MCP 服务器连接到 MySQL、PostgreSQL、SQLite、DuckDB 等。

  1. 支持矩阵
    1. 数据库资源
    2. 数据库工具
    3. 提示功能
  2. 安装
    1. Docker
    2. 新公共管理
    3. 克劳德桌面
    4. 光标
  3. 用法
    1. SSL 连接
    2. 只读模式
    3. 配置数据库连接
    4. 运输
    5. 命令行选项
  4. 发展
    1. 测试
    2. 使用MCP Inspector进行调试
  5. 贡献者
    1. 星史

      Related MCP Servers

      • -
        security
        F
        license
        -
        quality
        An MCP server that provides safe, read-only access to SQLite databases through MCP. This server is built with the FastMCP framework, which enables LLMs to explore and query SQLite databases with built-in safety features and query validation.
        Last updated -
        49
        Python
      • -
        security
        A
        license
        -
        quality
        MCP to access any database accessible via JDBC such as Postgres, Oracle, mysql, mariadb, sqlite etc.
        Last updated -
        129
        Apache 2.0
      • A
        security
        A
        license
        A
        quality
        An MCP server that provides read-only access to MySQL databases.
        Last updated -
        4
        419
        17
        JavaScript
        MIT License
        • Linux
        • Apple

      View all related MCP servers

      MCP directory API

      We provide all the information about MCP servers via our MCP API.

      curl -X GET 'https://glama.ai/api/mcp/v1/servers/bytebase/dbhub'

      If you have feedback or need assistance with the MCP directory API, please join our Discord server