DBHub

DBHub

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

编程文档访问
数据库交互
访问服务器

README

<p align="center"> <a href="https://dbhub.ai/" target="_blank"> <picture> <img src="https://raw.githubusercontent.com/bytebase/dbhub/main/resources/images/logo-full.webp" width="50%"> </picture> </a> </p>

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

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

Demo SSE Endpoint

https://demo.dbhub.ai/sse 连接到一个 示例员工数据库。您可以将 Cursor 或 MCP Inspector 指向它以查看它的实际效果。

mcp-inspector

支持的矩阵

数据库资源

资源名称 URI 格式 PostgreSQL MySQL SQL Server SQLite
schemas db://schemas
tables_in_schema db://schemas/{schemaName}/tables
table_structure_in_schema db://schemas/{schemaName}/tables/{tableName}
indexes_in_table db://schemas/{schemaName}/tables/{tableName}/indexes
procedures_in_schema db://schemas/{schemaName}/procedures
procedure_details_in_schema db://schemas/{schemaName}/procedures/{procedureName}

数据库工具

工具 命令名称 PostgreSQL MySQL SQL Server SQLite
Execute Query run_query
List Connectors list_connectors

Prompt 能力

Prompt 命令名称 PostgreSQL MySQL SQL Server SQLite
Generate SQL generate_sql
Explain DB Elements explain_db

安装

Docker

# PostgreSQL 示例
docker run --rm --init \
   --name dbhub \
   --publish 8080:8080 \
   bytebase/dbhub \
   --transport sse \
   --port 8080 \
   --dsn "postgres://user:password@localhost:5432/dbname?sslmode=disable"
# 带有示例员工数据库的演示模式
docker run --rm --init \
   --name dbhub \
   --publish 8080:8080 \
   bytebase/dbhub \
   --transport sse \
   --port 8080 \
   --demo

NPM

# PostgreSQL 示例
npx @bytebase/dbhub --transport sse --port 8080 --dsn "postgres://user:password@localhost:5432/dbname"
# 带有示例员工数据库的演示模式
npx @bytebase/dbhub --transport sse --port 8080 --demo

注意:演示模式包含一个捆绑的 SQLite 示例“employee”数据库,其中包含 employees、departments、salaries 等表。

Claude Desktop

claude-desktop

  • Claude Desktop 仅支持 stdio 传输 https://github.com/orgs/modelcontextprotocol/discussions/16
// claude_desktop_config.json
{
  "mcpServers": {
    "dbhub-postgres-docker": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "bytebase/dbhub",
        "--transport",
        "stdio",
        "--dsn",
        // 如果连接到本地数据库,请使用 host.docker.internal 作为主机
        "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"]
    }
  }
}

Cursor

cursor

用法

配置您的数据库连接

您可以使用 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 创建 .env
    DSN=postgres://user:password@localhost:5432/dbname?sslmode=disable
    

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

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

数据库 DSN 格式 示例
PostgreSQL postgres://[user]:[password]@[host]:[port]/[database] postgres://user:password@localhost:5432/dbname?sslmode=disable
SQLite sqlite:///[path/to/file]sqlite::memory: sqlite:///path/to/database.dbsqlite::memory:
SQL Server sqlserver://[user]:[password]@[host]:[port]/[database] sqlserver://user:password@localhost:1433/dbname
MySQL mysql://[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"
    

命令行选项

选项 描述 默认值
demo 在演示模式下使用示例员工数据库运行 false
dsn 数据库连接字符串 如果不在演示模式下,则为必需
transport 传输模式:stdiosse stdio
port HTTP 服务器端口(仅在使用 --transport=sse 时适用) 8080

演示模式使用加载了 示例员工数据库 的内存 SQLite 数据库,该数据库包括 employees、departments、titles、salaries、department employees 和 department managers 的表。示例数据库包括用于表创建、数据加载和测试的 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 调试

stdio

# PostgreSQL 示例
TRANSPORT=stdio DSN="postgres://user:password@localhost:5432/dbname?sslmode=disable" npx @modelcontextprotocol/inspector node /path/to/dbhub/dist/index.js

SSE

# 使用 SSE 传输启动 DBHub
pnpm dev --transport=sse --port=8080

# 在另一个终端中启动 MCP Inspector
npx @modelcontextprotocol/inspector

连接到 DBHub 服务器 /sse 端点

Star History

Star History Chart

推荐服务器

e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选
AIO-MCP Server

AIO-MCP Server

🚀 集成了 AI 搜索、RAG 和多服务(GitLab/Jira/Confluence/YouTube)的一体化 MCP 服务器,旨在增强 AI 驱动的开发工作流程。来自 Folk。

精选
本地
Knowledge Graph Memory Server

Knowledge Graph Memory Server

为 Claude 实现持久性记忆,使用本地知识图谱,允许 AI 记住用户的信息,并可在自定义位置存储,跨对话保持记忆。

精选
本地
Hyperbrowser

Hyperbrowser

欢迎来到 Hyperbrowser,人工智能的互联网。Hyperbrowser 是下一代平台,旨在增强人工智能代理的能力,并实现轻松、可扩展的浏览器自动化。它专为人工智能开发者打造,消除了本地基础设施和性能瓶颈带来的麻烦,让您能够:

精选
本地
any-chat-completions-mcp

any-chat-completions-mcp

将 Claude 与任何 OpenAI SDK 兼容的聊天完成 API 集成 - OpenAI、Perplexity、Groq、xAI、PyroPrompts 等。

精选
Exa MCP Server

Exa MCP Server

一个模型上下文协议服务器,它使像 Claude 这样的人工智能助手能够以安全和受控的方式,使用 Exa AI 搜索 API 执行实时网络搜索。

精选
BigQuery MCP Server

BigQuery MCP Server

这是一个服务器,可以让你的大型语言模型(LLM,比如Claude)直接与你的BigQuery数据对话!可以把它想象成一个友好的翻译器,它位于你的AI助手和数据库之间,确保它们可以安全高效地进行交流。

精选
MCP Web Research Server

MCP Web Research Server

一个模型上下文协议服务器,使 Claude 能够通过集成 Google 搜索、提取网页内容和捕获屏幕截图来进行网络研究。

精选