# DB Connect MCP

Gives an agent read-only access to PostgreSQL, MySQL and ClickHouse: schemas, tables, relationships and column profiles.

- MCP server · `type=mcp` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline, Zed, Gemini CLI · ★ 6
- Author: yugui923
- License: MIT · policy=link-only · description only; the file stays with the author
- Source: https://github.com/yugui923/db-connect-mcp
- Updated: 2026-10-21
- HTML: https://affpapa.org/en/nevibecode/mcp/db-connect-mcp

## What it does

The server stays read-only. It accepts `SELECT` and `WITH` only, and adds limits so a query cannot drag back a whole table. Every connection is opened with read-only parameters.

Three adapters sit inside: PostgreSQL with metadata and statistics, MySQL and MariaDB, and ClickHouse for analytical workloads. You get column profiling (mean, median, quartiles, value frequency), data sampling, object search and query plans. PostgreSQL also has hypothetical indexes through the HypoPG extension — opt-in, requiring `DB_HYPOPG_ENABLED=true` and an administrator who installed the extension. Those are planner estimates, not measured speedups.

You need Python 3.10 or higher and a connection string in `DATABASE_URL`. Databases behind a firewall are reachable over SSH tunnels with a password or a private key. The server does better with databases whose tables and columns carry comments: the agent then understands the data model instead of guessing from names alone.

## Requirements
- Needs: Python and uv (commands run via uvx)
- Environment variables: `DATABASE_URL` — keys and tokens: ask the human for the values, never commit them or put them in shared files.

## Install

### Claude Code (native platform)

**Platform CLI**
```bash
claude mcp add db-connect-mcp -e DATABASE_URL=<DATABASE_URL> -- uvx db-connect-mcp
```
Replace <…> with your own values. uvx runs the command named after the package; if the README names another one, use uvx --from db-connect-mcp <command>

### Codex

**Platform CLI**
```bash
codex mcp add db-connect-mcp --env DATABASE_URL=<DATABASE_URL> -- uvx db-connect-mcp
```
Replace <…> with your own values. uvx runs the command named after the package; if the README names another one, use uvx --from db-connect-mcp <command>

### Cursor

**Config file**
File `.cursor/mcp.json`:
```json
{
    "mcpServers": {
        "db-connect-mcp": {
            "command": "uvx",
            "args": [
                "db-connect-mcp"
            ],
            "env": {
                "DATABASE_URL": "<DATABASE_URL>"
            }
        }
    }
}
```
Replace <…> with your own values. uvx runs the command named after the package; if the README names another one, use uvx --from db-connect-mcp <command>

### GitHub Copilot

**Config file**
File `.vscode/mcp.json`:
```json
{
    "servers": {
        "db-connect-mcp": {
            "type": "stdio",
            "command": "uvx",
            "args": [
                "db-connect-mcp"
            ],
            "env": {
                "DATABASE_URL": "<DATABASE_URL>"
            }
        }
    }
}
```
Replace <…> with your own values. uvx runs the command named after the package; if the README names another one, use uvx --from db-connect-mcp <command>

### Gemini CLI

**Platform CLI**
```bash
gemini mcp add -e DATABASE_URL=<DATABASE_URL> db-connect-mcp uvx db-connect-mcp
```
Replace <…> with your own values. uvx runs the command named after the package; if the README names another one, use uvx --from db-connect-mcp <command>

## When to use it
- explore an unfamiliar database schema without a manual client
- pull the value distribution of a column
- find tables and indexes by name
- check a query plan before running the query
- compare a hypothetical index against the current plan

## Example prompts
- List all schemas and show tables with their sizes
- Describe the `orders` table and its foreign key relationships
- Profile the `status` column in the `orders` table

## Similar
- [database-optimization](https://affpapa.org/en/nevibecode/agents/database-optimization.md) — subagent · 3924 installs
- [DBHub](https://affpapa.org/en/nevibecode/mcp/dbhub.md) — MCP server · ★ 3730
- [MCP Database Server](https://affpapa.org/en/nevibecode/mcp/mcp-database-server.md) — MCP server · ★ 19
- [DataClawe — Database as a Utility](https://affpapa.org/en/nevibecode/mcp/dataclawe-database-as-a-utility.md) — MCP server
- [sql-pro](https://affpapa.org/en/nevibecode/skills/httpsgithubcomjeffallan-sql-pro.md) — skill · 6400 installs
- [database-cloud-optimization-database-optimizer](https://affpapa.org/en/nevibecode/agents/database-cloud-optimization-database-optimizer.md) — subagent · ★ 41823

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
