DBHub

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Integrations

  • Provides Docker container deployment options for running the DBHub server with configurable database connections and transport options.

  • Supports connecting to DuckDB databases to explore tables, access schema information, and perform read-only SQL queries with safety measures.

  • Provides access to MySQL databases for browsing tables, viewing schema information, and executing read-only SQL queries with safety protections.

DBHub 是一个通用数据库网关,实现了模型上下文协议 (MCP) 服务器接口。该网关允许兼容 MCP 的客户端连接并探索不同的数据库。

+------------------+ +--------------+ +------------------+ | | | | | | | | | | | | | Claude Desktop +--->+ +--->+ PostgreSQL | | | | | | | | Cursor +--->+ DBHub +--->+ SQL Server | | | | | | | | Other MCP +--->+ +--->+ SQLite | | Clients | | | | | | | | +--->+ MySQL | | | | | | | | | | +--->+ Other Databases | | | | | | | +------------------+ +--------------+ +------------------+ MCP Clients MCP Server Databases

演示 SSE 端点

https://demo.dbhub.ai/sse连接了一个示例员工数据库。您可以将 Cursor 或 MCP Inspector 指向该数据库,以查看其实际运行情况。

支持矩阵

数据库资源

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

数据库工具

工具命令名称PostgreSQLMySQLSQL 服务器SQLite
执行查询run_query
列出连接器list_connectors

提示功能

迅速的命令名称PostgreSQLMySQLSQL 服务器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

新公共管理

# PostgreSQL example npx @bytebase/dbhub --transport sse --port 8080 --dsn "postgres://user:password@localhost:5432/dbname"
# 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"] } } }

光标

用法

配置数据库连接

您可以在演示模式下使用 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 GXP10 创建.env

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

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

数据库DSN 格式例子
PostgreSQLpostgres://[user]:[password]@[host]:[port]/[database]postgres://user:password@localhost:5432/dbname?sslmode=disable
SQLitesqlite:///[path/to/file]sqlite::memory:sqlite:///path/to/database.dbsqlite::memory:
SQL 服务器sqlserver://[user]:[password]@[host]:[port]/[database]sqlserver://user:password@localhost:1433/dbname
MySQLmysql://[user]:[password]@[host]:[port]/[database]mysql://user:password@localhost:3306/dbname

运输

  • 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

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

发展

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

使用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

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

  1. Supported Matrix
    1. Database Resources
    2. Database Tools
    3. Prompt Capabilities
  2. Installation
    1. Docker
    2. NPM
    3. Claude Desktop
    4. Cursor
  3. Usage
    1. Configure your database connection
    2. Transport
    3. Command line options
  4. Development
    1. Debug with MCP Inspector
  5. Star History
    ID: a01xnguu8x