mcp-multi-db
以下摘录自该仓库的 README(片段) · 在 GitHub 读完整 README →
**One MCP server for all your SQL databases — read-only and safe by default.**
Connect an AI agent to PostgreSQL, MySQL, and SQLite at the same time through a
single Model Context Protocol server. List
your databases in one config file and the agent picks which one to query by
database_id. Every query is enforced read-only at the database level, so it's
safe to point at real data.
- **Multi-engine, one server** — Postgres, MySQL, and SQLite side by side; no
separate server per database.
- **Read-only & safe by default** — two-layer enforcement (SQL-text guard +
database-level read-only transactions) plus row limits and query timeouts.
See SECURITY.md.
- **Schema-aware** — the agent can discover databases, tables/views, and column
metadata before it writes a query.
- **Zero query language to learn** — just ask in natural language.
> The clip drives the real server over stdio (via the MCP SDK) against a seeded
> SQLite database. Regenerate it with npm run build && vhs examples/demo.tape.
Tools
| Tool | Description |
|------|-------------|
| list_databases | List configured database connections |
| list_tables | List tables/views in a database |
| describe_table | Show column metadata for a table |
| run_query | Run read-only SQL (SELECT, WITH, EXPLAIN) |
Quick start
No install needed — npx fetches the package on first use.
1. Create databases.json
Copy the example and edit with your connection details:
> **Never commit databases.json** — it contains credentials. It's already
> gitignored if you cloned the repo. Prefer read-only database users (see
> Security).
2. Register the server with your MCP client
The server speaks MCP over **stdio**, so it works with any MCP-capable client.
Use npx mcp-multi-db as the command and pass MCP_DB_CONFIG (the path to
your databases.json). See mcp.example.json and
databases.example.json for templates.
Claude Desktop
Edit claude_desktop_config.json (macOS:
~/Library/Application Support/Claude/claude_desktop_config.json):
Restart Claude Desktop afterward.
Claude Code
Cursor
Add to ~/.cursor/mcp.json (or .cursor/mcp.json in your project), then open
**Cursor Settings → Tools & MCP**, restart the server, and use **Agent** mode:
Cline / Windsurf / other MCP clients
Any client that supports stdio MCP servers uses the same shape: command npx,
args ["-y", "mcp-multi-db"], and env MCP_DB_CONFIG pointing at your
databases.json. Consult your client's docs for where its MCP config lives.
> **Prefer a pinned global install?** npm install -g mcp-multi-db, then use
> command mcp-multi-db with no args.
Configuration reference
Config is loaded from one of two environment variables, in order:
1. **MCP_DB_CONFIG** — path to a JSON file (recommended).
2. **MCP_DATABASES** — inline JSON (useful when a file path is awkward).
The JSON may be either { "databases": [ ... ] } or a bare array. Each entry:
| Field | Required | Notes |
|-------|----------|-------|
| id | yes | Unique; the agent references this as database_id |
| type | yes | postgres \| mysql \| sqlite |
| connectionString | postgres/mysql | Standard connection URI |