# dbmole-mcp [Health: Active]

**Category:** 🗄️ Databases  
**Repository:** https://github.com/ed-smartass/dbmole-mcp  
**GitHub Stars:** 1  
**npm Downloads (last month):** 292  
**Views:** 0  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/dbmole-mcp

## Description
MCP server for PostgreSQL and MySQL: the agent adds and edits its own connections at runtime (per-project file, hot reload), SSH tunnels, TLS, readonly sessions

## Tools
Capabilities this server exposes over MCP:

- **list_connections** — List database connections with the layer each comes from: project (.dbmole.json, found by walking up from the project dir) or global (user store). Also shows invalid entries and broken files. Secrets are omitted.
- **add_connection** — Add a named postgres/mysql connection. scope "global" (default) saves it to the user store; "project" saves it to .dbmole.json in the project root. Supports an optional ssh tunnel and a readonly flag. Optional ssl: true or { rejectUnauthorized, ca } (ca = PEM or file path).
- **update_connection** — Patch a connection by name in the layer it lives in (project or global). Set a field to null to remove it (e.g. "ssh": null); an ssh object is merged field by field, e.g. { "ssh": { "hostKey": "SHA256:..." } }. queryTimeoutMs sets the per-statement timeout (null restores the 60 s default). ssl is replaced as a whole, not merged like ssh.
- **remove_connection** — Remove a connection by name from the layer it lives in (invalid entries too) and drop its cached pools/tunnel.
- **test_connection** — Verify a connection works end to end (including ssh tunnel if configured). Reports server version and connect+query latency.
- **execute_sql** — Execute a single SQL statement on a named connection. SELECT returns columns/rows; DML returns rowCount (and lastInsertId for mysql). Use positional params: $1.. for postgres, ? for mysql.
- **list_databases** — List databases on a connection with size in bytes. Hides postgres template databases and mysql system schemas.
- **list_tables** — List tables and views (type: table | view) with approximate row counts. For postgres, optionally filter by schema; for mysql, schema is the database.
- **describe_table** — Describe a table or view: columns (type, nullable, default), primary key, indexes and foreign keys.

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

```json
"mcpServers": {
  "dbmole-mcp": {
    "command": "npx",
    "args": ["-y","dbmole-mcp"]
  }
}
```

## Documentation

## What dbmole-mcp does

dbmole-mcp exposes PostgreSQL and MySQL databases to MCP-compatible agents. It supports multiple named connections and lets the agent manage those connections through MCP rather than requiring a server restart or manual client configuration change.

Connections can be stored at project scope in `.dbmole.json` or globally in `~/.config/dbmole/connections.json`. A project entry takes precedence over a global entry with the same name. Credentials are not returned by connection-listing operations, which instead show details such as host, port, database, readonly status, source layer, and SSH usage.

## How it works

The server communicates over stdio. It reloads the project and global connection files before each tool call, so edits made by an agent, a user, or another session apply to subsequent operations. When connection settings change, the previous pool is closed and a new one is created.

Project-file discovery starts at the server working directory and searches upward for `.dbmole.json`. Git worktrees without their own file can use the main checkout’s file. Project and global files are written atomically with mode `0600`.

SSH access supports password, private-key, or agent authentication. Host keys can be checked through `known_hosts` or a pinned fingerprint. TLS includes certificate and hostname verification and can operate through an SSH tunnel.

## Setup and configuration

Node.js 22 or newer is required. The server starts without connection settings; add connections later with `add_connection` or create the JSON files directly. Install it for a compatible MCP client with `npx -y dbmole-mcp`, or build and run the supplied Docker image.

For project-scoped connections, keep `.dbmole.json` out of version control because it may contain credentials. In Docker, mount the project at `/work`, persist the global store with a volume, and provide `known_hosts`, private keys, or an SSH agent socket when tunnel connections need them.

## Tools and capabilities

- `list_connections` reports resolved connections, shadowed names, invalid entries, and broken files.
- `add_connection`, `update_connection`, and `remove_connection` manage project or global entries.
- `test_connection` checks the complete path, including SSH tunneling, and reports server version and latency.
- `execute_sql` runs one statement with PostgreSQL `$1` or MySQL `?` parameters. Results default to 100 rows, allow up to 1,000, and are capped at 40 KB.
- `list_databases` returns database names and sizes while excluding PostgreSQL templates and MySQL system schemas.
- `list_tables` finds tables, views, and materialized views with approximate row counts.
- `describe_table` returns columns, primary keys, indexes, and foreign keys for qualified tables or views.

## Limitations and notes

Readonly mode is enforced by the database session rather than only by the agent’s behavior. A broken project file prevents all project connections from loading, while a broken global store affects names not supplied by the project layer. Credentials entered through chat pass through the model context; production secrets should be written into the connection file directly.

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

