db-conn-mcp
Provides tools for connecting to and querying PostgreSQL databases, including schema exploration, read-only queries, and gated write operations, with support for read-only roles and YOLO mode.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@db-conn-mcpshow me the users table schema"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
db-conn-mcp
A dead-simple, self-hosted Model Context Protocol (MCP) server for querying your databases with AI agents (Claude, Cursor, Windsurf, VS Code, Zed, and more).
It does one thing well: let an agent safely explore and query a database you point it at — with security delegated to the simplest possible primitives (a static JSON file and your database's own read-only transactions), not custom auth servers or fragile SQL parsing.
v1 ships PostgreSQL only. All database-specific code lives behind a
Dialectseam, so adding MySQL/SQLite later is a single new file.
Why
Read stays read. A
readdatabase runs every query in a native read-only transaction, and the read tool only accepts a single read-only statement (SELECT/WITH/VALUES/TABLE/SHOW/EXPLAIN) — so an agent can't slip in a write or aSET … READ WRITEto flip the session. For a hard, privilege-level guarantee that holds no matter what, point the DSN at a read-only database role (see Use a read-only role).No secret leaks. DSNs/passwords are never logged or returned by any tool. Connection failures come back as sanitized diagnostics (a category + fix), never a raw traceback with your host and credentials in it.
Tiered write safety. Writes are gated server-side:
mode(hard, native) →yolo(per-database trust) →user_consent(explicit per-operation approval).Zero-friction setup. An interactive wizard registers your database and injects the server into your AI client's config for you — across 8 popular clients, each in its own format.
Related MCP server: mcpolyglot
Install
Requires Python 3.10+.
# Recommended: isolated but globally available on your PATH
pipx install db-conn-mcp
# or plain pip
pip install db-conn-mcpThis installs the db-conn-mcp command.
Quick start
db-conn-mcp setupThe wizard asks for:
Scope — global (
~/.db-conn-mcp/connections.json) or repo (./connections.json).Connection name — e.g.
prod.DSN — e.g.
postgresql://user:pass@host:5432/dbname.Mode —
read(recommended) orwrite.Client injection — pick which detected MCP clients to wire up (e.g.
1,3orall).
It then writes your config and (optionally) registers the server in your chosen AI clients. Restart/reconnect the client and the tools are available.
Cancelling is safe. Press Ctrl+C at any prompt and nothing is written.
Configuration
The single source of truth is connections.json, resolved in this order (first match wins):
--config /path/to/connections.json./connections.json(repo-scoped)~/.db-conn-mcp/connections.json(global-scoped)
{
"connections": [
{ "name": "prod", "dsn": "postgresql://…", "mode": "read" },
{ "name": "dev", "dsn": "postgresql://…", "mode": "write", "yolo": false }
]
}Field | Required | Meaning |
| yes | Unique identifier the agent uses to pick a database. |
| yes | Connection string. Secret — never shown by any tool. |
| yes |
|
| no (default | If |
connections.jsonis git-ignored by this project's.gitignore— never commit real DSNs.
The security model
Writes pass through three gates, in order:
mode(hard, native). If the database isn't"mode": "write", the write is rejected — and the connection is opened read-only at the PostgreSQL session level regardless, so it's blocked twice over.yoloanduser_consentcan never make areaddatabase writable.yolo(persisted trust). On awritedatabase withyolo: true, writes proceed without prompting.user_consent(per-operation). Otherwise the agent must first read the schema, show you the exact SQL, get your "yes", and re-call withuser_consent=true.
Reads always run inside a native read-only transaction, and execute_read_query accepts only a single read-only statement (SELECT/WITH/VALUES/TABLE/SHOW/EXPLAIN). That allowlist is what stops an agent from sending SET SESSION CHARACTERISTICS AS TRANSACTION READ WRITE to flip the session, or piggy-backing a ; DELETE … onto a read — there's no SQL parsing involved, just a leading-keyword check plus the driver's single-command protocol.
Use a read-only role (strongest guarantee)
The application-level checks above are defense-in-depth. The hardest boundary is a privilege one: connect with a PostgreSQL role that simply cannot write, so a write fails even if every layer above were bypassed. Create one per database and use its DSN for read connections:
CREATE ROLE agent_ro LOGIN PASSWORD '…';
GRANT CONNECT ON DATABASE mydb TO agent_ro;
GRANT USAGE ON SCHEMA public TO agent_ro;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO agent_ro;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO agent_ro;This is the recommended setup for any database that holds data you care about.
MCP tools
The server exposes 12 tools and 2 prompts:
Tool | Kind | Description |
| explore | Configured databases (name, mode, yolo — no DSN). |
| explore | Tables and views in a database. |
| explore | Columns, types, primary/foreign keys for a table. |
| explore | The whole database's schema in one deterministic call. |
| export | Byte-faithful schema dump via the database's own |
| explore | First N rows of a table (default 10). |
| search | Find columns by name across all tables (fuzzy, case-insensitive). |
| search | Find where a value appears across tables (fuzzy); returns table/column hits + samples. Pass |
| execute | Run a single read-only statement ( |
| execute | Run a mutation — gated by the safety model above. |
| config | Enable/disable |
| doctor | Test one database (or all) → |
Prompts:
troubleshoot_connection— a discoverable, full connection-gotchas checklist (host/port, firewall,sslmode, Dockerlocalhost, db-name case, pool limits, …).faithful_schema_export— how to choose between the self-contained SQL export and the faithfulpg_dumpone, including how to offer installingpg_dump.
CLI reference
db-conn-mcp is both the server and a management tool.
Command | What it does |
| Run the server over stdio (the default an MCP client uses). Run directly in a terminal it prints guidance and exits — it does not hang. |
| Run over HTTP (SSE) instead. |
| Guided setup; shows status + an action menu if already configured. |
| List configured databases and which clients have the server injected. |
| Add another database connection. |
| Inject the server into detected MCP clients. |
| Uninject the server from chosen clients. |
| Probe connectivity (exit |
| Remove one connection. |
| Remove all connections (delete |
| Toggle |
| Print the installed version and the exact build commit, then exit. |
--config <path> works before or after any subcommand.
Connecting an AI client
db-conn-mcp setup (or db-conn-mcp clients) auto-detects and writes the right config for:
Claude Desktop · Cursor · Windsurf · Agy (Antigravity) · Claude Code · Cline · VS Code · Zed
Prefer to wire it manually? Use the absolute path the wizard would (so the client can find it regardless of PATH). For a mcpServers-style client (Claude Desktop, Cursor, Windsurf, …):
{
"mcpServers": {
"db-conn-mcp": {
"command": "db-conn-mcp",
"args": ["--config", "/absolute/path/to/connections.json"]
}
}
}If
db-conn-mcpisn't on the client's PATH (e.g. a project-venv install), use the interpreter form instead:"command": "/abs/path/to/python", "args": ["-m", "db_conn_mcp", "--config", "…"]. Thesetup/clientscommands figure this out for you automatically.
VS Code (servers key, "type": "stdio") and Zed (context_servers, nested command) use different shapes — the wizard handles those too.
Provider notes
Railway / managed Postgres over a public proxy: use the public connection URL (e.g. Railway's
DATABASE_PUBLIC_URL, not the internal*.railway.internalone) and append?sslmode=require— these proxies require SSL with a self-signed cert, whichsslmode=requireaccepts without verification.
Development
git clone https://github.com/Idle-Sync/db-conn-mcp
cd db-conn-mcp
python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\Activate.ps1
pip install -e ".[dev]"
ruff check . && ruff format --check .
pytest -qpyproject.toml is the single source of dependency truth. The codebase is split into single-purpose layers (config, models, dialects/, safety, diagnostics, handlers, server, cli); only the dialect layer knows a specific database exists. See ARCHITECTURE.md, PRD.md, and PLAN.md.
Star this repo
If db-conn-mcp saved you time, a ⭐ helps other people find it — it's the only signal that surfaces a small self-hosted tool. Star it here.
License
MIT — see LICENSE.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Alicense-qualityFmaintenanceMCP-Server from your Database optimized for LLMs and AI-Agents. Supports PostgreSQL, MySQL, ClickHouse, Snowflake, MSSQL, BigQuery, Oracle Database, SQLite, ElasticSearch, DuckDBLast updated532Apache 2.0
- Alicense-qualityCmaintenanceOne config, one CLI that turns your databases (Postgres, MySQL, SQLite, MongoDB) into MCP servers for Claude, GPT, Cursor, and any MCP-compatible agent.Last updated1MIT
- Flicense-qualityCmaintenanceAn MCP server that exposes relational databases (PostgreSQL/MySQL) to AI agents with natural language to SQL query support.Last updated18
- AlicenseAqualityAmaintenanceRead-only MCP server for querying PostgreSQL, MySQL, and SQLite from AI agents — multi-database, safe by default.Last updated4181ISC
Related MCP Connectors
Analytical memory for AI agents: a real Postgres queried in plain English over MCP. One command.
GibsonAI MCP server: manage your databases with natural language
Self-hosted MCP gateway: turn any API, database or MCP server into AI connectors — no code.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/Idle-Sync/db-conn-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server