Database MCP

Configuration

Configure dbmcp with CLI flags, environment variables, and backend-specific defaults

Database MCP is configured through CLI flags and environment variables. This page documents every available option.

Precedence

Configuration values are resolved in this order (highest priority first):

  1. CLI flags — explicitly passed on the command line
  2. Environment variables — set by the MCP client (via env or envFile in server config)
  3. Built-in defaults — backend-aware defaults described below

When the same option is set in multiple places, the higher-priority source wins.

Database Connection

CLI FlagEnvironment VariableDefaultDescription
--db-backendDB_BACKENDmysqlDatabase backend: mysql, mariadb, postgres, sqlite
--db-hostDB_HOSTlocalhostDatabase host
--db-portDB_PORTBackend-dependentDatabase port (see Backend Defaults)
--db-userDB_USERBackend-dependentDatabase user (see Backend Defaults)
--db-passwordDB_PASSWORDDatabase password
--db-nameDB_NAMEDatabase name, or file path for SQLite

Character Set

CLI FlagEnvironment VariableDefaultDescription
--db-charsetDB_CHARSETCharacter set (MySQL/MariaDB only)

Backend Defaults

Default values for --db-port and --db-user depend on the selected backend:

BackendDefault PortDefault User
MySQL3306root
MariaDB3306root
PostgreSQL5432postgres
SQLiteN/AN/A

SQLite does not use host, port, or user — only --db-name (the file path) is required.

SSL / TLS

CLI FlagEnvironment VariableDefaultDescription
--db-sslDB_SSLfalseEnable SSL for the database connection
--db-ssl-caDB_SSL_CAPath to CA certificate
--db-ssl-certDB_SSL_CERTPath to client certificate
--db-ssl-keyDB_SSL_KEYPath to client key
--db-ssl-verify-certDB_SSL_VERIFY_CERTtrueVerify the server certificate

When --db-ssl is enabled, the server validates that any provided certificate paths exist before connecting.

Server Behavior

CLI FlagEnvironment VariableDefaultDescription
--db-read-onlyDB_READ_ONLYtrueEnable read-only mode
--db-max-pool-sizeDB_MAX_POOL_SIZE5Maximum database connection pool size
--db-connection-timeoutDB_CONNECTION_TIMEOUTConnection timeout in seconds
--db-query-timeoutDB_QUERY_TIMEOUT30Query execution timeout in seconds
--db-page-sizeDB_PAGE_SIZE100Max items per paginated tool response (range 1–500)
--log-levelLOG_LEVELinfoLog level: error, warn, info, debug, trace

Security note: Read-only mode is enabled by default. In this mode, write tools (writeQuery, createDatabase) are hidden from the AI assistant. Only read tools are available, and readQuery enforces SQL validation (SELECT, SHOW, DESCRIBE, USE, EXPLAIN only). Set --db-read-only=false or DB_READ_ONLY=false to enable write tools.

The page size applies uniformly to every paginated tool; see the Cursor Pagination section on the Features page for the full protocol.

HTTP Transport

These options are available only when running in HTTP mode (dbmcp http):

CLI FlagDefaultDescription
--host127.0.0.1Bind host for the HTTP server
--port9001Bind port for the HTTP server
--allowed-originshttp://localhost,http://127.0.0.1,https://localhost,https://127.0.0.1Allowed CORS origins (comma-separated)
--allowed-hostslocalhost,127.0.0.1Allowed host names (comma-separated)

A transport subcommand is required — running dbmcp with no subcommand prints usage help and exits with a non-zero status. The stdio transport requires no additional configuration beyond the database options above.

Client Configuration Examples

MCP clients configure servers through JSON files. Each tool uses a slightly different file path, but the format is nearly identical. The examples below connect to a local MySQL database.

Claude Code

Create a .mcp.json file in your project root:

{
  "mcpServers": {
    "dbmcp": {
      "command": "dbmcp",
      "args": ["stdio"],
      "env": {
        "DB_BACKEND": "mysql",
        "DB_HOST": "localhost",
        "DB_USER": "root",
        "DB_PASSWORD": "secret",
        "DB_NAME": "myapp"
      }
    }
  }
}

Claude Code also supports HTTP transport for remote servers:

{
  "mcpServers": {
    "dbmcp": {
      "type": "http",
      "url": "http://127.0.0.1:9001/mcp"
    }
  }
}

File locations: .mcp.json (project, shareable) · ~/.claude.json (user, global)

Using Docker:

{
  "mcpServers": {
    "dbmcp": {
      "type": "stdio",
      "command": "docker",
      "args": ["run", "-i", "--rm",
        "-e", "DB_BACKEND", "-e", "DB_HOST", "-e", "DB_USER",
        "-e", "DB_PASSWORD", "-e", "DB_NAME",
        "ghcr.io/haymon-ai/dbmcp"
      ],
      "env": {
        "DB_BACKEND": "postgres",
        "DB_HOST": "host.docker.internal",
        "DB_USER": "postgres",
        "DB_PASSWORD": "secret",
        "DB_NAME": "myapp"
      }
    }
  }
}

Claude Desktop

Edit the config file at:

  • Linux: ~/.config/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "dbmcp": {
      "command": "dbmcp",
      "args": ["stdio"],
      "env": {
        "DB_BACKEND": "postgres",
        "DB_HOST": "localhost",
        "DB_USER": "postgres",
        "DB_PASSWORD": "secret",
        "DB_NAME": "myapp"
      }
    }
  }
}

Using Docker:

{
  "mcpServers": {
    "dbmcp": {
      "command": "docker",
      "args": ["run", "-i", "--rm",
        "-e", "DB_BACKEND", "-e", "DB_HOST", "-e", "DB_USER",
        "-e", "DB_PASSWORD", "-e", "DB_NAME",
        "ghcr.io/haymon-ai/dbmcp"
      ],
      "env": {
        "DB_BACKEND": "postgres",
        "DB_HOST": "host.docker.internal",
        "DB_USER": "postgres",
        "DB_PASSWORD": "secret",
        "DB_NAME": "myapp"
      }
    }
  }
}

Claude Desktop only supports stdio transport. For HTTP mode, use the Connectors UI under Settings > Connectors > Add custom connector.

Cursor

Create .cursor/mcp.json in your project root, or use ~/.cursor/mcp.json for global configuration:

{
  "mcpServers": {
    "dbmcp": {
      "type": "stdio",
      "command": "dbmcp",
      "args": ["stdio"],
      "env": {
        "DB_BACKEND": "mysql",
        "DB_HOST": "localhost",
        "DB_USER": "root",
        "DB_NAME": "myapp"
      },
      "envFile": ".env"
    }
  }
}

Using Docker:

{
  "mcpServers": {
    "dbmcp": {
      "type": "stdio",
      "command": "docker",
      "args": ["run", "-i", "--rm",
        "-e", "DB_BACKEND", "-e", "DB_HOST", "-e", "DB_USER",
        "-e", "DB_PASSWORD", "-e", "DB_NAME",
        "ghcr.io/haymon-ai/dbmcp"
      ],
      "env": {
        "DB_BACKEND": "mysql",
        "DB_HOST": "host.docker.internal",
        "DB_USER": "root",
        "DB_NAME": "myapp"
      },
      "envFile": ".env"
    }
  }
}

Cursor supports envFile to load variables from a .env file. Sensitive values like DB_PASSWORD can be kept there instead of in the JSON config.

Windsurf

Edit the config file at:

  • Linux: ~/.codeium/windsurf/mcp_config.json
{
  "mcpServers": {
    "dbmcp": {
      "command": "dbmcp",
      "args": ["stdio"],
      "env": {
        "DB_BACKEND": "mysql",
        "DB_HOST": "localhost",
        "DB_USER": "root",
        "DB_PASSWORD": "${env:DB_PASSWORD}",
        "DB_NAME": "myapp"
      }
    }
  }
}

Using Docker:

{
  "mcpServers": {
    "dbmcp": {
      "command": "docker",
      "args": ["run", "-i", "--rm",
        "-e", "DB_BACKEND", "-e", "DB_HOST", "-e", "DB_USER",
        "-e", "DB_PASSWORD", "-e", "DB_NAME",
        "ghcr.io/haymon-ai/dbmcp"
      ],
      "env": {
        "DB_BACKEND": "mysql",
        "DB_HOST": "host.docker.internal",
        "DB_USER": "root",
        "DB_PASSWORD": "${env:DB_PASSWORD}",
        "DB_NAME": "myapp"
      }
    }
  }
}

Windsurf supports ${env:VARIABLE_NAME} interpolation to reference values from your shell environment instead of hardcoding them.

Environment Variables vs. envFile

FeatureClaude CodeClaude DesktopCursorWindsurf
env objectYesYesYesYes
envFileNoNoYesNo
Variable interpolation${VAR}No${env:VAR}${env:VAR}
HTTP transport in configYesNoYesYes
Project-scoped configYesNoYesNo

On this page