Skip to main content
DBHub connects to your database in one of two ways:
  • A DSN — one connection string for a single database.
  • A TOML file — passed with --config, for one or more databases plus per-source and per-tool settings.
Choose one. A TOML file defines its sources itself, so --config and --dsn cannot be combined. Environment variables are a different matter: DSN and DB_* stay available to a TOML file through ${VAR} interpolation, which is the recommended way to keep credentials out of the file. When you use a DSN, DBHub takes it from the first of:
  1. --dsn flag
  2. DSN environment variable
  3. DB_* environment variables
  4. .env file (.env.local in development, .env in production)
Every other option — transport, port, host, and so on — is set by flag or environment variable, in the same order:
  1. Command-line flag
  2. Environment variable
  3. .env file
  4. Built-in default
This page covers command-line flags and environment variables. For TOML configuration, see TOML Configuration.

—transport

string
default:"stdio"
Transport protocol for MCP communication. Env: TRANSPORT.Options:
  • stdio - For desktop tools (Claude Desktop, Claude Code, Cursor). Pure MCP-over-stdio with no HTTP server.
  • http - For browser and network clients. Starts HTTP server with MCP endpoint, workbench, and API.
Both transports serve the stateless 2026-07-28 MCP protocol revision natively and fall back to the 2025-era protocol for older clients on the same endpoint — no configuration needed. On http, 2026-era clients send the standard Mcp-Method / Mcp-Name headers with every request, so a fronting gateway or WAF can route and rate-limit individual tools without parsing request bodies.

—port

number
default:"8080"
HTTP server port. Only used when --transport=http. Ignored for stdio transport. Env: PORT.

—host

string
default:"0.0.0.0"
HTTP bind address. Only used when --transport=http. Ignored for stdio transport. Env: DBHUB_HOST.
The default 0.0.0.0 exposes DBHub on every network interface. For production, set --host 127.0.0.1 and place DBHub behind a reverse proxy (nginx/Caddy) or restrict with a firewall, or configure --auth-token (see below) to require a bearer token on every request.

—allowed-hosts

string
default:"(loopback + this machine)"
Comma-separated list of additional hostnames the HTTP transport accepts in the Host (and Origin) headers. This is DBHub’s DNS-rebinding protection: requests whose Host is not on the list are rejected with 403, so a malicious web page cannot rebind a hostname to your DBHub instance and drive its MCP tools from the victim’s browser. Only used when --transport=http. Env: DBHUB_ALLOWED_HOSTS.The list always includes loopback (localhost, 127.0.0.1, [::1]). When bound to a wildcard address (the default 0.0.0.0 / ::), this machine’s own hostname and external IP addresses are added automatically, so reaching DBHub by IP or machine name works without any extra configuration. You only need this flag for other names that resolve to DBHub — most commonly a reverse-proxy or public DNS name.
A port in an entry is ignored — only the hostname is matched. IPv6 literals must be bracketed, e.g. [2001:db8::1]. The active allow-list is printed at startup. If a legitimate client gets a 403 “Host … is not allowed”, add its hostname here.
--allowed-hosts "*" turns off DNS-rebinding protection. Use it only when DBHub sits behind your own authentication and/or proxy.

—auth-token

string
Comma-separated list of bearer tokens required on every HTTP request. Only used when --transport=http. Unset by default — auth is off unless you configure this. Env: DBHUB_AUTH_TOKEN.Clients must send a matching token as Authorization: Bearer <token>; requests without one get 401 Unauthorized with a WWW-Authenticate: Bearer header. /healthz is exempt so uptime monitors don’t need a token.
Client request (/api/sources is a plain GET; the MCP endpoint itself requires a JSON-RPC POST body, so it’s not a copy-pasteable example):
Configuring a token is the opt-in — there’s no separate “require auth” flag to remember. A comma-separated list lets you rotate a leaked or expiring token by adding the new one, redeploying, and then removing the old one, and lets you hand different tokens to different clients so one can be revoked without affecting the others.
This is a flat shared-secret check, not OAuth — it answers “does this request have the secret,” not “who is this user” (no per-user scopes or audit trail). If you need real identity-based authorization, front DBHub with your own OAuth-aware proxy or IdP-integrated gateway instead.

—dsn

string
Database connection string (Data Source Name). Format: database_type://username:password@host:port/database_name?options. Env: DSN (see the resolution order at the top of this page).
DSN Query Parameters:SSL/TLS Options:
  • sslmode=disable: All SSL/TLS encryption is turned off. Data is transmitted in plaintext.
  • sslmode=require: Connection is encrypted, but the server’s certificate is not verified.
  • sslmode=verify-ca: SSL with CA certificate verification, but no hostname check. PostgreSQL only. Use sslrootcert to specify the CA certificate path.
  • sslmode=verify-full: SSL with CA certificate and hostname verification. PostgreSQL only. Use sslrootcert to specify the CA certificate path.
Environment Variables (Alternative to —dsn)
environment
Recommended for databases with complex passwords containing special characters:

—id

string
Instance identifier to suffix tool names. Useful when running multiple DBHub instances (e.g., in Cursor). Env: ID.Tools will be named execute_sql_{id} for each instance.
Result: execute_sql_prod and execute_sql_staging tools
Cannot be used with --config (TOML configuration). TOML config defines source IDs directly in the configuration file. Use command-line DSN configuration instead if you need the --id flag.

—demo

boolean
default:"false"
Run DBHub with a bundled SQLite sample “employee” database for testing.

—config

string
Path to a TOML configuration file, for managing multiple database connections and advanced configurations.
See TOML Configuration for the complete reference, including source options, tool options, SSH tunnels, and custom tools.
A TOML file defines its own sources and source IDs, so --config is mutually exclusive with --dsn and --id. Use either a TOML file or command-line/environment configuration.

SSH Tunnel Options

SSH tunnel configuration for connecting to databases through bastion/jump hosts. Examples:
  • --ssh-key / SSH_KEY accepts either a file path or a base64-encoded private key. DBHub automatically detects the format: it first tries to read the value as a file path, and if that fails, decodes it as base64.
  • When --ssh-host is a plain alias (no dots, not an IP address), DBHub automatically resolves it from ~/.ssh/config, reading the HostName, User, IdentityFile, and ProxyJump directives. Explicit flags always override values from the config file.
  • ProxyJump hops that are themselves ~/.ssh/config aliases are resolved recursively — each hop uses its own HostName/User/Port/IdentityFile (and its own nested ProxyJump), matching how ssh connects. Cyclic ProxyJump chains are rejected with an error.
  • ProxyCommand is not supported (requires shell execution). Use ProxyJump instead.
  • Path expansion for ~/ is supported in file paths.

Quick Reference