Purpose
mcp-multi-db is a read-only MCP (Model Context Protocol) server used to let AI agents query PostgreSQL, MySQL, and SQLite databases. It unifies multiple SQL databases into a single server, avoiding the need to deploy separate services for each database.
Main capabilities
- Multi-engine, single server: PostgreSQL, MySQL, and SQLite can be connected at the same time, with no need to run an independent server for each database.
- Read-only and safe by default: uses a two-layer enforcement mechanism (SQL text guard + database-level read-only transactions), along with row limits and query timeouts.
- Schema-aware: agents can discover databases, tables/views, and column metadata before writing queries.
- No need to learn a query language: just ask questions in natural language.
How to use
- Create databases.json: copy the example file and fill in the connection information. Never commit databases.json, because it contains credentials; if you cloned the repository, this file is already gitignored. It is recommended to use a read-only database user.
- Register the server with an MCP client: the server uses MCP over stdio, so it works with any client that supports MCP. Use the command npx mcp-multi-db and pass MCP_DB_CONFIG (the path to databases.json). You can refer to the mcp.example.json and databases.example.json templates.
- Claude Desktop: edit claude_desktop_config.json (macOS path: ~/Library/Application Support/Claude/claude_desktop_config.json), then restart Claude Desktop.
- Cursor: add it to ~/.cursor/mcp.json (or .cursor/mcp.json in the project), then open Cursor Settings → Tools & MCP, restart the server, and use Agent mode.
- Any client that supports stdio MCP servers uses the same structure: command is npx, args is ["-y", "mcp-multi-db"], and MCP_DB_CONFIG in env points to databases.json. For the specific MCP configuration location, please consult the client documentation.
- For a globally installed pinned version: npm install -g mcp-multi-db, then use the command mcp-multi-db with no arguments.
Configuration reference
Configuration is loaded from one of the following two environment variables, in order:
- MCP_DB_CONFIG — JSON file path (recommended).
- MCP_DATABASES — inline JSON (use when a file path is inconvenient). The JSON can be { "databases": [ ... ] } or a bare array. Each entry contains connection information.
Example prompts
- "List my configured databases"
- "What tables are in local-sqlite?"
- "Describe the users table in analytics-pg"
- "Run SELECT COUNT(*) FROM orders on reporting-mysql"
Limitations and security
- Read-only only: INSERT, UPDATE, DELETE, DDL, and so on are all blocked—both intercepted by the SQL text guard and by running database-level read-only transactions within each query (SQLite is opened in read-only mode). SELECT statements that call functions with side effects will still be rejected.
- Row limit: results are capped (default 100, maximum 1000).
- Query timeout: statements are bounded (30 seconds) to avoid runaway queries.
- Least privilege is still recommended: prefer dedicated read-only database users and read-only replicas. Full details and reporting are in SECURITY.md.
Deployment and scaling
- Docker: includes a multi-stage Dockerfile. Build and run, mounting databases.json. The image runs as a non-root user, contains only the built JS and runtime node_modules (no toolchain), and uses MCP over stdio, just like the npx installation, and can be connected to any setup by replacing the command and arguments with the corresponding docker run -i invocation MCP client.
- Testing: uses Node's built-in test runner (no extra dependencies), covering the read-only SQL guard and end-to-end tests for the SQLite adapter. CI runs build and tests on every push and pull request.
- Adding other database engines: add a config variant in src/config.ts, implement a new adapter for the SqlDatabasePort interface under src/adapters/, and register it in the adapter factory. New adapters must enforce read-only at the connection level—they cannot rely on the text guard alone. See docs/extending.md for the full checklist.
- Documentation: architecture (components, request lifecycle, and port family design, with diagrams), extending (adding SQL engines or non-SQL families), security (the two-layer read-only model and secure deployment). Full index in docs/.
- Contributing: issues and pull requests are welcome—see CONTRIBUTING.md for setup, read-only invariants, and how to add a database engine.
- License: ISC—see LICENSE.