# DBHub

> A token-efficient MCP server that lets AI agents explore and query your SQL databases

- Category: Agents & Automation / Workflow Automation
- Language: TypeScript
- Licence: MIT
- Repository: https://github.com/bytebase/dbhub
- Website: https://dbhub.ai
- Canonical page: https://ai-tldr.dev/tools/dbhub/

## In short

DBHub is an open-source Model Context Protocol (MCP) server from Bytebase that sits between an MCP client — Claude Desktop, Claude Code, Cursor, VS Code, Copilot CLI and others — and your databases. It sits in the Workflow Automation category of the Agents & Automation tools and is open-source, written in TypeScript and licensed MIT.

## Overview

DBHub is an open-source Model Context Protocol (MCP) server from Bytebase that sits between an MCP client — Claude Desktop, Claude Code, Cursor, VS Code, Copilot CLI and others — and your databases. One DBHub process speaks to PostgreSQL, MySQL, MariaDB, SQL Server, Oracle and SQLite, so an agent can browse schemas and run SQL through a single interface instead of a separate server per database. It is the example the Claude Code documentation uses for connecting to PostgreSQL over MCP.

The design goal is a small tool surface. By default DBHub loads only two tools — `execute_sql` and `search_objects`, which explores schemas, tables, columns, indexes and procedures with progressive disclosure — at about 1.4k tokens, which the project compares with 19k+ for some alternatives. `explain_sql` (a query plan without running the query) and `health_check` are opt-in, and you can define your own parameterized SQL tools in a `dbhub.toml` file. Guardrails include read-only mode, row limits and query timeouts, and connections can go through SSH tunnels and SSL/TLS.

Run with HTTP transport, DBHub also serves a built-in web Workbench: you can execute queries, run custom tools through a form, and read a trace of recent requests in the browser without any MCP client. It ships on npm as `@bytebase/dbhub` (Node.js 22.5.0 or later), as the `bytebase/dbhub` Docker image, as a read-only one-click MCP Bundle and as a Claude Code plugin. The project is written in TypeScript and MIT licensed; Bytebase points teams that need approval flows, access control, data masking and audit logging to its separate Bytebase product.

## What it does

- One MCP server for PostgreSQL, MySQL, MariaDB, SQL Server, Oracle and SQLite
- Two default tools (`execute_sql`, `search_objects`) at about 1.4k tokens, plus opt-in `explain_sql` and `health_check`
- Custom tools: reusable, parameterized SQL statements defined in `dbhub.toml` and exposed as MCP tools
- Multiple databases at once through `[[sources]]` in a TOML config, with per-tool `readonly` and `max_rows` and hot reload on file changes
- Guardrails against runaway queries: read-only mode, row limits and server-side query timeouts
- SSH tunnelling and SSL/TLS for secure connections, and a built-in web Workbench with request traces

## Getting started

Try the built-in demo database first, then point DBHub at your own database, register it with your MCP client, and move to a `dbhub.toml` file for multiple databases and guardrails. The npm package needs Node.js 22.5.0 or later; the Docker image bundles its own runtime.

1. Try demo mode and open the Workbench

   Demo mode starts DBHub with a sample database. With HTTP transport, open http://localhost:8080 in your browser to use the Workbench.

```bash
npx @bytebase/dbhub@latest --transport http --port 8080 --demo
```

2. Connect your own database

   Pass a connection string with `--dsn`, via npx or the Docker image. From inside Docker, reach a database on your host with `host.docker.internal` instead of `localhost`.

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

# or with Docker
docker run --rm --init \
  --name dbhub \
  --publish 8080:8080 \
  bytebase/dbhub \
  --transport http \
  --port 8080 \
  --dsn "postgres://user:password@localhost:5432/dbname?sslmode=disable"
```

3. Register it with your MCP client

   In Claude Code, add DBHub over stdio for a local database, or point at a running HTTP server. Everything after `--` is the DBHub command. Codex works the same way with `codex mcp add`.

```bash
# stdio (local)
claude mcp add --transport stdio dbhub -- npx @bytebase/dbhub@latest --transport stdio --dsn "postgres://user:password@localhost:5432/dbname"

# HTTP (a DBHub server already running on port 8080)
claude mcp add --transport http dbhub http://localhost:8080/mcp
```

4. Configure several databases with dbhub.toml

   Define each database as a `[[sources]]` entry and set guardrails per tool, then start DBHub with `--config` (a `./dbhub.toml` in the working directory is loaded automatically). `--config` and `--dsn` cannot be combined.

```toml
[[sources]]
id = "production"
dsn = "postgres://user:pass@localhost:5432/mydb"
connection_timeout = 60

[[sources]]
id = "staging"
dsn = "mysql://root:pass@localhost:3306/myapp"

[[tools]]
name = "execute_sql"
source = "production"
readonly = true
max_rows = 1000

[[tools]]
name = "execute_sql"
source = "staging"
readonly = false
```

5. Add a custom tool

   A custom tool is a fixed SQL statement with typed parameters. Agents call it like any other MCP tool, and the Workbench renders it as a form with a read-only preview of the generated SQL.

```toml
[[tools]]
name = "delete_employee_salaries"
description = "Delete salary records for a specific employee"
source = "local_pg"
readonly = false  # Explicitly allow DELETE operations
statement = "DELETE FROM salary WHERE emp_no = $1"

[[tools.parameters]]
name = "emp_no"
type = "integer"
description = "Employee number"
required = true
```

## When to use it

- Exploring schemas, validating queries and debugging data from Claude Code, Cursor or VS Code during local development
- Giving non-technical colleagues curated, read-only database access through Claude Desktop or another MCP client
- Replacing a separate MCP server per database with a single DBHub process
- Read-only production troubleshooting, with row limits and query timeouts guarding against runaway queries
