One MCP server for every database. Edit one .env file, run docker compose up, and Claude / Codex / Gemini / Cursor / Windsurf can read your PostgreSQL, MySQL, ClickHouse, MongoDB, Redis, SQLite, and Elasticsearch.
One MCP server for every database. Drop your .env, run docker compose up, and any LLM — Claude, Codex, Gemini, Cursor, Windsurf — can read your PostgreSQL, MySQL, ClickHouse, MongoDB, Redis, SQLite, and Elasticsearch.
星數
3
工具
—
可用率
—
open-db-mcp is a self-hostable Model Context Protocol (MCP) server, written in Go, that turns any database you can reach into a tool an LLM can call. No code changes — every database is added by editing .env.
What you get
🔌 Add a database with one block of env vars. No code, no plugin install.
🛡️ Read-only by default — safe to point at production.
🐳 Single tiny Docker image (~12 MB, Alpine). Starts in under a second.
⚡ Works with every MCP client — Claude Desktop, Claude Code, Codex, Gemini CLI, Cursor, Windsurf, Zed, Continue, Cline.
🔑 Per-user API tokens with roles (reader / writer / admin).
git clone https://github.com/alinemone/open-db-mcp.git
cd open-db-mcp
cp .env.example .env
Step 2 — Edit .env to point at one database
Open .env in any editor. At the top you'll see a token line — this is the secret your AI client will use to call the server. Change changeme to something only you know:
Now scroll down and uncomment one database block. Here's a complete PostgreSQL example — just remove the # from each line and fill in your real values:
PG_MAIN_HOST=host.docker.internal # your DB host (see notes below)
PG_MAIN_PORT=5432
PG_MAIN_USER=postgres
PG_MAIN_PASSWORD=your-postgres-password
PG_MAIN_DB=your_database_name
What goes in HOST?
DB on the same laptop, outside Docker → host.docker.internal
DB in another Docker container on the same machine → the container's name (e.g. postgres) and make sure the two containers share a network
DB on a remote server → its IP or hostname (e.g. db.example.com)
The word MAIN in PG_MAIN_* is just a name you pick — you'll see this source listed as MAIN later. If you have a second Postgres, add another block with a different name (e.g. PG_ANALYTICS_*).
Then restart: docker compose up -d. The URL your AI client uses becomes http://localhost:3001/mcp?api_key=....
Add more users (with different tokens)
Each MCP_USER_<NAME>_TOKEN line creates a token. The role defaults to reader if you don't say otherwise:
MCP_USER_ADMIN_TOKEN=my-secret-token-123
MCP_USER_ADMIN_ROLE=admin
MCP_USER_ALI_TOKEN=ali-token-456 # role is "reader" by default → read-only
MCP_USER_DEV_TOKEN=dev-token-789
MCP_USER_DEV_ROLE=writer # can run db_execute_write on writable sources
Hand the ALI token to someone who should only read; keep the ADMIN one for yourself.
Allow writes on a specific source (opt-in)
By default every source is read-only. To let db_execute_write work on one source, add _ALLOW_WRITE=true:
PG_DEV_HOST=host.docker.internal
PG_DEV_ALLOW_WRITE=true # ← this source becomes writable
The caller also needs a writer or admin role. Both gates must agree — even admin cannot write to a source where _ALLOW_WRITE isn't true. This is a deliberate safety: a deployment-level kill switch.
💡 For production, prefer leaving WRITE=false and creating a DB user with only SELECT grants. That gives you defence in depth.
Advanced
Authorization model
Every authenticated user has a role. Reads are unrestricted for any valid token. Writes require two independent gates:
The caller's role is writer or admin.
The source is marked writable (<PREFIX>_<NAME>_ALLOW_WRITE=true).
Caller role
Source _ALLOW_WRITE=true
db_execute_write result
reader
any
forbidden: user X (role=reader)…
writer
true
✅ allowed
writer
false
source X is read-only; set …WRITE=true
admin
true
✅ allowed
admin
false
source X is read-only; …
Every call is audit-logged with user, role, source, tool, duration_ms, and on deny a reason. Token comparison is constant-time and tokens are sha256-hashed in memory.
Read-only enforcement
Three independent layers keep reads honest:
Statement guard — db_execute_query rejects any non-SELECT/WITH/EXPLAIN/SHOW/DESCRIBE at parse time.
Driver-level read-only — Postgres opens a read-only transaction; SQLite carries query_only; MySQL wraps reads in a READ ONLY transaction; ClickHouse sets readonly=2 per query.
RBAC — writes additionally require role >= writer (see above).
MongoDB / Redis / Elasticsearch use their own tool families (mongo_*, redis_*, es_*) and don't flow through db_execute_*. mongo_find / mongo_aggregate reject $out, $merge, $function, $accumulator, $where, $eval.
Each internal/adapters/<dbname>/<dbname>.go is self-contained: discovery, connection pool, schema introspection, query execution. Adding a new family is one file plus a blank import.
MCP server · Model Context Protocol · LLM database tools · Claude MCP · Claude Code · Codex MCP · Gemini CLI MCP · Cursor MCP · Windsurf MCP · Continue MCP · PostgreSQL MCP · MySQL MCP · ClickHouse MCP · MongoDB MCP · Redis MCP · SQLite MCP · Elasticsearch MCP · self-hosted MCP · open source MCP · Docker MCP · AI database access · LLM SQL · agentic SQL · LLM data platform · TOON format
O
Open Db
alinemone·3 顆星·
One MCP server for every database. Drop your .env, run docker compose up, and any LLM — Claude, Codex, Gemini, Cursor, Windsurf — can read your PostgreSQL, MySQL, ClickHouse, MongoDB, Redis, SQLite, a
One MCP server for every database. Drop your .env, run docker compose up, and any LLM — Claude, Codex, Gemini, Cursor, Windsurf — can read your PostgreSQL, MySQL, ClickHouse, MongoDB, Redis, SQLite, and Elasticsearch.
上次檢查時間:2026-10-28。 One MCP server for every database. Drop your .env, run docker compose up, and any LLM — Claude, Codex, Gemini, Cursor, Windsurf — can read your PostgreSQL, MySQL, ClickHouse, MongoDB, Redis, SQLite, and Elasticsearch.