DBHub Documentation

repository·main·Indexed 25 days ago

https://github.com/bytebase/dbhub

A lightweight, zero-dependency Model Context Protocol (MCP) server that acts as a gateway between AI clients and databases. DBHub 1.0.0 supports PostgreSQL, MySQL, MariaDB, SQL Server, and SQLite, providing token-efficient database exploration and execution via tools like execute_sql and search_objects. It features read-only enforcement, row limiting, SSH tunneling, and support for multi-database configurations via TOML.

Tokens
34.7K
Snippets
84
Records
224
Agent score
82%

What's inside DBHub

  1. Overview of DBHub

    main

    DBHub is a zero-dependency, token-efficient MCP (Model Context Protocol) server that acts as a lightweight gateway between MCP-compatible clients (like Claude Desktop, Claude Code, Cursor, or VS Code) and various databases. It allows AI assistants to explore and interact with database schemas and data through a standardized interface.

    Supported Databases:

    • PostgreSQL
    • MySQL
    • SQL Server
    • MariaDB
    • SQLite
  2. Available DBHub Tools

    main

    DBHub provides three types of tools for interacting with databases via AI models:

    1. Execute SQL (execute_sql or execute_sql_{id}): Executes single or multiple SQL statements (separated by semicolons).
    2. Search Objects (search_objects or search_objects_{id}): Searches and lists database objects like schemas, tables, columns, procedures, and indexes using pattern matching.
    3. Custom Tools: User-defined, parameterized SQL operations defined in your dbhub.toml configuration file.
  3. Compare Postgres MCP Servers by vendor neutrality and specificity

    main

    Postgres MCP servers can be categorized based on whether they are vendor-neutral or vendor-specific, and whether they are PostgreSQL-specific or data source agnostic.

    • Postgres-specific & Vendor-neutral: Anthropic's original reference implementation, Postgres MCP Pro by Crystal DBA.
    • Postgres-specific & Vendor-specific: Supabase MCP Server, Neon MCP Server.
    • Multi-database & Vendor-neutral: DBHub.
    • Multi-database & Vendor-specific: MCP Toolbox for Databases by Google.
  4. Install DBHub via Docker

    main

    Run DBHub as a Docker container to expose an HTTP transport for your database. Use the --dsn flag to provide your database connection string.

    docker run --rm --init \
       --name dbhub \
       --publish 8080:8080 \
       bytebase/dbhub \
       --transport http \
       --port 8080 \
       --dsn "postgres://user:password@localhost:5432/dbname?sslmode=disable"
  5. Configure database sources in dbhub.toml

    main

    Database sources define the connections DBHub uses to interact with databases. Each source is defined in a [[sources]] block within your dbhub.toml file. You can identify sources using a unique id and provide a description to help AI models understand the data's purpose.

    Sources can be configured using a single Data Source Name (dsn) or by specifying individual connection parameters (useful for handling special characters in passwords without URL encoding).

    [[sources]]
    id = "production"
    description = "Production PostgreSQL database containing customer and order data"
    dsn = "postgres://user:pass@prod.example.com:5432/myapp?sslmode=require"
  6. Develop DBHub from source

    main

    Development requires Node.js >= 22.5.0. Use pnpm for managing the project.

    # Install dependencies
    pnpm install
    
    # Run in development mode
    pnpm dev
    
    # Build and run for production
    pnpm build && pnpm start --transport stdio --dsn "postgres://user:password@localhost:5432/dbname"
  7. Install the Claude Code Plugin for DBHub

    main

    To install DBHub as a native plugin in Claude Code, use the marketplace commands within the Claude Code interface. This registers the DBHub MCP server and adds two specialized skills: /dbhub:setup and /dbhub:explore.

    Prerequisites:

    • Node.js >= 22.5.0 installed on the machine running Claude Code.
    • The database must be network-reachable from the machine running Claude Code (e.g., via VPN or allow-list).

    Installation Steps:

    1. Add the DBHub marketplace: /plugin marketplace add bytebase/dbhub
    2. Install the plugin: /plugin install dbhub@dbhub

    During installation, Claude Code will prompt for your database connection string (DSN). This is stored in secure storage and is not saved in a config file. An example DSN is postgres://user:password@localhost:5432/dbname.

    /plugin marketplace add bytebase/dbhub
    /plugin install dbhub@dbhub
  8. Integrate DBHub with Codex

    main

    Integrate DBHub with Codex using the CLI or by editing the TOML configuration file at ~/.codex/config.toml.

    [mcp_servers.dbhub]
    command = "npx"
    args = ["@bytebase/dbhub@latest", "--transport", "stdio", "--dsn", "postgres://user:password@localhost:5432/dbname"]
  9. Create Custom MCP Tools with predefined SQL

    main

    You can create reusable, parameterized database operations that are automatically registered as MCP tools by defining a statement and parameters in the [[tools]] section.

    Requirements for Custom Tools:

    • name: The name of the tool.
    • description: A human-readable description (required for custom tools) to help AI models understand usage.
    • source: The source ID to use.
    • statement: The SQL query containing placeholders (e.g., $1 for PostgreSQL, ? for MySQL/SQLite, @p1 for SQL Server).
    • parameters: An array of parameter definitions matching the placeholders in the statement.
    [[tools]]
    name = "get_user_by_id"
    description = "Retrieve user details by their unique ID"
    source = "production"
    statement = "SELECT id, name, email, created_at FROM users WHERE id = $1"
    
    [[tools.parameters]]
    name = "user_id"
    type = "integer"
    description = "The unique user ID"
  10. Start the DBHub Workbench

    main

    The Workbench is a web-based interface for interacting with database tools, executing queries, running custom tools, and viewing request traces. To use the Workbench, you must run DBHub with the http transport.

    After starting the server, access the interface by opening http://localhost:8080 in your web browser.

    npx @bytebase/dbhub --transport http --port 8080 --dsn "postgres://..."
  11. Install DBHub via NPM

    main

    Use npx to run DBHub. This requires Node.js version 22.5.0 or higher.

    npx @bytebase/dbhub@latest --transport http --port 8080 --dsn "postgres://user:password@localhost:5432/dbname?sslmode=disable"