# db-conn-mcp [Health: Active]

**Category:** 🗄️ Databases  
**Repository:** https://github.com/Idle-Sync/db-conn-mcp  
**GitHub Stars:** 3  
**Views:** 5  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/db-conn-mcp

## Description
A dead-simple, self-hosted MCP server for securely querying databases via AI agents.

## Tools
Capabilities this server exposes over MCP:

- **list_databases** — databases
- **list_tables** — tables
- **find_columns** — columns
- **sample_table_rows** — rows
- **check_database** — results
- **doctor** — findings
- **get_table_schema** — Columns, types, primary/foreign keys for a table. Pass `include_indexes=true` to also get its indexes (`name`, key `columns` in index order — an INCLUDE payload is not listed — `unique`, `method`); omitted by default.
- **get_database_schema** — The whole database's schema in one call; its content is deterministic (tables sorted by schema and name, columns by position), and only `meta.elapsed_ms` varies between calls. `format="json"` (default) returns every table's columns/types/PK/FK; `format="sql"` returns a **self-contained, runnable DD…
- **dump_schema_faithful** — Byte-faithful** schema dump via the database's own `pg_dump --schema-only` — the most complete/runnable export. Requires the `pg_dump` binary on the server host; if missing, returns `pg_dump_not_found` with install guidance (see the `faithful_schema_export` prompt).
- **search_value** — Find **where** a value appears across tables (fuzzy); returns table/column hits + samples. Pass `tables=[…]` to scope it.
- **get_object_definition** — Faithful SQL definition of a **view / function / trigger / sequence / index** by name (native `pg_get_*def`; overloads and all schemas returned).
- **execute_read_query** — Run a single read-only statement (`SELECT`/`WITH`/…) inside a read-only transaction. Optional `params` (**real bind parameters** via `$1`/`$2` — no quoting pitfalls) and `timeout_ms`. Rendering follows the server's column type: bytea arrives as `\x` hex text, a `"char"` column (`relkind`, `contype`…
- **execute_write_query** — Run a mutation — gated by the safety model above. **Defaults to `dry_run=true`**: execute in a transaction, report would-be `rows_affected` or the `RETURNING` rows (their values are rolled back, and generated ids differ on commit; rendering follows the server's column type: bytea arrives as `\x` he…
- **explain_query** — EXPLAIN` (optionally `ANALYZE`) a validated read-only query — confirm index usage without any write access. Takes the same `params` (`$1`/`$2` bind parameters) as `execute_read_query`, so you explain the query you will actually run rather than a literal-substituted rewrite of it.
- **cancel_query** — Cancel the statement in a given backend `pid` (native `pg_cancel_backend`); the session survives. Find pids via `show_activity`.
- **open_query_cursor** — Open a server-side cursor over a read-only query for **large result sets**; returns a `cursor_id`. Max 5 open; 15-min idle auto-reap.
- **fetch_rows** — Fetch the next N rows from an open cursor; auto-closes when drained or when the read fails. A call made while another is running on the same cursor is refused and changes nothing. Values render as on `execute_read_query`: bytea as `\x` hex text, a `"char"` column as its character.
- **close_cursor** — Close a cursor and release its connection (idempotent).
- **diff_schemas** — Structural schema diff between two configured databases (tables, columns, types, defaults, PK/FK) — verify a migrated copy matches its source.
- **check_sequences** — Find sequences **behind** their column's max value (the silent post-migration breakage); fix with `setval()`. Lists only the problem sequences by default, with `total_sequences` saying how many were checked and `skipped` listing the ones it could not probe; `behind_count: 0` means all clear only wh…
- **table_stats** — Approximate row counts + disk/index sizes per table, largest first (statistics only, no scans). Ask the narrower question directly: `table` for one table, `min_size_bytes` to skip anything smaller, `limit` for the top N by total size (which adds `truncated` to the result).
- **show_activity** — Sanitized `pg_stat_activity`: pid, state, wait events, query age — **no user names, client addresses, or query text** (text is opt-in and truncated).
- **set_yolo_mode** — Enable/disable `yolo` for one database (persisted).

## Claude Desktop Quick Installation
Install path detected from listing signals. Uses `uvx` (confidence: high):

```json
"mcpServers": {
  "db-conn-mcp": {
    "command": "uvx",
    "args": ["caches"]
  }
}
```

## Documentation

## What db-conn-mcp does

PostgreSQL databases become available to MCP-compatible AI clients through a local server configured with named connections. Agents can inspect databases, tables, columns, keys, indexes, views, functions, triggers, sequences, and other objects; run read-only SQL; preview or commit mutations under server-side safety rules; and investigate operational issues.

The database catalog includes tools for finding columns and values, sampling rows, checking approximate table sizes, comparing schemas, identifying sequences that lag behind column values, and viewing sanitized activity information. Schema exports are available as structured JSON, runnable SQL, or a byte-faithful schema-only export generated with PostgreSQL’s `pg_dump`.

## How it works

Install the Python package and register one or more PostgreSQL DSNs in `connections.json`. Each connection has a name, DSN, and mode of `read` or `write`. Agents refer to the connection by name; database credentials are not exposed through listing or diagnostic tools.

Read-mode connections use PostgreSQL read-only transactions, and read queries accept one validated read-only statement such as `SELECT`, `WITH`, `VALUES`, `TABLE`, `SHOW`, or `EXPLAIN`. Query parameters use PostgreSQL bind markers such as `$1` and `$2`. Write operations are blocked unless the connection is in write mode. By default, a mutation must first run as a rolled-back dry run before an identical statement can commit. Per-operation consent or persisted `yolo` mode can control the remaining approval step, while `skip_dry_run` provides an explicitly requested bypass for that stage.

Large read results can be handled with server-side cursors. Opening a cursor returns an identifier, subsequent calls fetch batches, and closing or draining the cursor releases its connection.

## Setup and configuration

Python 3.12 or newer is required. Install the package with either:

- `pipx install db-conn-mcp`
- `pip install db-conn-mcp`

Run `db-conn-mcp setup` to choose global or repository scope, enter a connection name and PostgreSQL DSN, select read or write mode, optionally configure fallback ports, and inject the server into detected client configurations. The wizard supports Claude, Cursor, Windsurf, VS Code, Zed, Codex, and other detected MCP clients.

Configuration is resolved in this order: an explicit `--config` path, `./connections.json`, then `~/.db-conn-mcp/connections.json`. A connection can define `fallback_ports` for explicitly listed alternate ports. The active port is reported when a fallback succeeds. Configuration files created by the tool use user-only permissions, and DSNs should not be committed to source control.

## Tools and capabilities

- Discover configured databases without exposing DSNs.
- List tables and views with case-insensitive name filtering and row limits.
- Inspect table schemas, keys, and optionally indexes.
- Export complete database schemas as JSON, runnable SQL, or `pg_dump` output.
- Execute parameterized read queries and explain their plans, optionally with `ANALYZE`.
- Preview and commit writes under mode, dry-run, consent, and `yolo` controls.
- Open, fetch, and close cursors for large read results.
- Find columns or values across tables and retrieve representative rows.
- Compare databases, check sequences, inspect table statistics, and view sanitized activity.
- Test connections, change persisted `yolo` settings, and diagnose configuration or client-launch problems.

## Limitations and notes

The shipped database dialect is PostgreSQL. Faithful schema export requires the `pg_dump` executable on the server host; the tool reports an installation-oriented diagnostic when it cannot find it. Cursor usage is limited to five open cursors, with idle cursors reaped after 15 minutes.

Read-only transactions and SQL validation provide server-side safeguards, but the strongest privilege-level boundary comes from using a PostgreSQL role that is itself read-only. A connection configured with `mode: "read"` cannot be made writable by `yolo`, consent, or dry-run options.

_Full upstream README: https://allmcps.com/mcp/db-conn-mcp/readme_

