Universal Database MCP Server
Provides read-only SQL querying for DuckDB (columnar analytics, in-process) including native querying of Parquet, CSV, and JSON files while applying security layers.
Provides read-only SQL querying, schema inspection, and query explanation for MySQL databases with built-in injection prevention.
Provides read-only SQL querying, schema inspection, and query explanation for PostgreSQL databases with multi-layer injection prevention and security hardening.
Provides read-only SQL querying for SQLite databases (local files) with zero infrastructure and defense-in-depth security layers.
Click on "Deploy 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., "@Universal Database MCP Server list all tables in the database"
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.
Universal Database MCP Server
The security-first, Python-native MCP server for database access from AI agents.

Why This Exists
Most database MCP servers give AI agents raw SQL access and hope for the best. This server assumes the LLM is untrusted input and applies 8 layers of injection prevention before any query reaches your database — including blocking UNION attacks, stacked statements, time-based injection, and comment bypasses.
Supports: PostgreSQL · SQLite · MySQL · DuckDB (columnar analytics)
Related MCP server: mcp-database-universal
Zero Setup: Works on Your Laptop Right Now
No Docker. No cloud account. No database server to install. DuckDB and SQLite run in-process:
# Query a local SQLite database — one command, zero infra
SQLITE_PATH=./myapp.db uvx universal-db-mcp
# Query a local DuckDB file or parquet files
DUCKDB_PATH=./analytics.duckdb uvx universal-db-mcp
# In-memory DuckDB for throwaway analysis
DUCKDB_PATH=:memory: uvx universal-db-mcpAdd to Claude Code in ~/.claude/mcp_servers.json, or to Claude Desktop in
~/Library/Application Support/Claude/claude_desktop_config.json (macOS) /
%APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"mydb": {
"command": "uvx",
"args": ["universal-db-mcp"],
"env": {
"SQLITE_PATH": "/Users/you/projects/myapp/db.sqlite3",
"ALLOW_DESTRUCTIVE": "false"
}
}
}
}Restart Claude Desktop / Claude Code after saving — that's it.
That's it. Claude Code discovers the tools automatically.
More client configs (Claude Desktop, Cursor, Windsurf, Docker) in
examples/.
Security Model: 8 Layers
Read-only by default. Defense-in-depth. Every query validated before it touches the driver.
Layer | What it does |
1 | Driver-level read-only — PostgreSQL session flag, SQLite |
2 | Keyword blocking — |
3 | Injection pattern detection — UNION SELECT, stacked statements, SQL comments ( |
4 | Multiple statement rejection — |
5 | Parameter type enforcement — only |
6 | Result size limits — truncated at |
7 | Identifier sanitization — table/column names stripped of metacharacters in internally-generated SQL |
8 | DuckDB filesystem blocklist — |
Full threat model: docs/SECURITY.md
DuckDB: Analytics Without Infrastructure
DuckDB runs in-process (no server) and reads Parquet, CSV, JSON natively. Connect AI agents to your analytics data without spinning up a warehouse:
# Query parquet files directly
DUCKDB_PATH=:memory: uvx universal-db-mcpThen in Claude Code:
You: "Load sales.parquet and show me monthly revenue by region"
Claude: [uses query tool → SELECT region, strftime('%Y-%m', date) AS month, SUM(revenue) ...]Natural Language → SQL
No separate NL-to-SQL tool needed — Claude already does this. Give it the
schema tool and ask in plain English:
You: "Which customers placed more than 5 orders last month?"
Claude: [calls schema() to see table structure, then query() with the
generated SQL — every query still passes through all 8 security
layers before touching your database]Pair with dry_run: true (DRYRUN=true) while prototyping — Claude gets the
query plan back without anything executing.
Docker
docker build -t universal-db-mcp .
docker run -i --rm \
-e POSTGRES_URI=postgresql://readonly:pass@host.docker.internal:5432/mydb \
-e ALLOW_DESTRUCTIVE=false \
universal-db-mcpSee examples/docker_mcp_config.json for
wiring this into an MCP client.
All Databases
# PostgreSQL
POSTGRES_URI=postgresql://readonly:pass@localhost/mydb uvx universal-db-mcp
# SQLite (local file, zero infra)
SQLITE_PATH=./db.sqlite3 uvx universal-db-mcp
# MySQL
MYSQL_URI=mysql://readonly:pass@localhost/mydb uvx universal-db-mcp
# DuckDB (columnar, in-process analytics)
DUCKDB_PATH=./analytics.duckdb uvx universal-db-mcp
# Multiple databases simultaneously
POSTGRES_URI=... SQLITE_PATH=... uvx universal-db-mcpMCP Tools
Tool | Description |
| Execute SQL — read-only by default, all 8 security layers apply |
| Inspect tables and columns — no config needed |
| Get query execution plan without running the query |
| Check connection status, DB version, and pool metrics |
| Show all configured databases and connection state |
| Inspect the last 100 executed queries |
| Capture current schema for drift detection |
| Compare current schema against the last snapshot |
v1.1.0: dry-run mode (DRYRUN=true), table allowlists (WHITELISTED_TABLES), query
complexity warnings, structured audit logs, and a --check CLI flag for connectivity
validation. See CHANGELOG.md.
Configuration
# ── PostgreSQL ─────────────────────────────────────
POSTGRES_URI=postgresql://user:pass@host:5432/db
POSTGRES_READONLY=true # default: true
# ── SQLite ─────────────────────────────────────────
SQLITE_PATH=/path/to/database.db
SQLITE_READONLY=true # default: true
# ── MySQL ──────────────────────────────────────────
MYSQL_URI=mysql://user:pass@host:3306/db
MYSQL_READONLY=true # default: true
# ── DuckDB ─────────────────────────────────────────
DUCKDB_PATH=/path/to/analytics.duckdb # or :memory:
DUCKDB_READONLY=true # default: true
# ── Security ───────────────────────────────────────
ALLOW_DESTRUCTIVE=false # default: false — blocks INSERT/UPDATE/DELETE/DROP
MAX_RESULT_ROWS=1000 # truncate large results
ENABLE_LOGGING=true # log queries to stderr
QUERY_TIMEOUT=30 # seconds
RATE_LIMIT_RPM=60 # requests per minuteSecure Database Users
Always use a dedicated read-only account. Never give the MCP server credentials that can modify data.
PostgreSQL:
CREATE USER mcp_agent WITH PASSWORD 'strong_random_password';
GRANT CONNECT ON DATABASE mydb TO mcp_agent;
GRANT USAGE ON SCHEMA public TO mcp_agent;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO mcp_agent;MySQL:
CREATE USER 'mcp_agent'@'localhost' IDENTIFIED BY 'strong_random_password';
GRANT SELECT ON mydb.* TO 'mcp_agent'@'localhost';
FLUSH PRIVILEGES;Development
git clone <repo-url>
cd universal-db-mcp
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
# Run tests (67+ passing, no external DB required for SQLite + DuckDB)
pytest
# Security tests only
pytest tests/test_security.py -v
# With coverage
pytest --cov=src/universal_db_mcp --cov-report=term-missingArchitecture
src/universal_db_mcp/
├── server.py # FastMCP server — 5 tools
├── config.py # Env-var config via Pydantic
├── adapters/
│ ├── base.py # Abstract adapter + result dataclasses
│ ├── postgresql.py # asyncpg, connection pool, read-only via init callback
│ ├── sqlite.py # aiosqlite, read-only via file URI mode=ro
│ ├── mysql.py # aiomysql, DictCursor
│ └── duckdb.py # duckdb, thread-pool executor, lock-guarded
└── security/
└── sanitizer.py # SQLSanitizer — 8-layer injection prevention
docs/
└── SECURITY.md # Full security architecture and threat modelvs. Google MCP Toolbox
This project | Google MCP Toolbox | |
Runtime | Python — | Go binary / Docker |
Local DBs | SQLite + DuckDB zero-infra | No SQLite |
Analytics | DuckDB in-process | No columnar adapter |
Auth model | Read-only by default + env vars | IAM / GCP-native |
SQL injection | 8-layer sanitizer + parameterized | Auth-focused |
Extend | Python ecosystem, any | Go plugins |
Vendor | Neutral | Google Cloud funnel |
Different tools for different jobs. Use this when you want Python-native, local-first, security-hardened access without cloud dependencies.
License
MIT — LICENSE
Security Notice: This server provides AI agents with database access. Always
use read-only credentials, review docs/SECURITY.md before
production deployment, and never commit .env files.
Available Tools
8 toolsexplainExplainA
Get query execution plan without running the query.
Inputs: sql (required), params, database. Returns: result
healthHealthA
Check database connection health and get server version info.
Inputs: database. Returns: result
list_databasesList DatabasesA
List all configured databases and their connection status.
Returns: JSON with list of databases including key, type, database name, and connection status.
Inputs: no named parameters. Returns: result
queryQueryA
Execute a SQL query against the database.
Supports parameterized queries for injection safety. In read-only mode, destructive operations (INSERT, UPDATE, DELETE, DROP, etc.) are blocked.
Inputs: sql (required), params, database. Returns: result
query_historyQuery HistoryA
Get recent query execution history (most recent first).
Inputs: limit. Returns: result
schemaSchemaA
Get database schema information: tables, columns, types, and constraints.
Inputs: tables, database. Returns: result
schema_diffSchema DiffA
Compare the current schema against the last snapshot taken with snapshot_schema.
Inputs: database. Returns: result
snapshot_schemaSnapshot SchemaA
Take a snapshot of the current database schema for later drift detection.
Inputs: database. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 8 tools
Each tool targets a distinct operation: schema introspection, query execution, plan explanation, health checking, history, schema snapshot/diff, and database listing. The schema-related trio (schema, snapshot_schema, schema_diff) and health/list_databases have adjacent concerns, but descriptions clarify boundaries.
Tool names mix styles: noun-only (schema, health), verb-only (query, explain), and snake_case compounds (query_history, snapshot_schema, schema_diff, list_databases). All are readable and lowercase, but there is no consistent verb_noun pattern.
Eight tools is well-scoped for a universal database server, covering introspection, execution, planning, health, history, and schema drift. Each tool earns its place without redundancy.
The set covers schema reading, arbitrary SQL execution, query plans, health checks, history, and schema drift detection, which covers most database workflows. Missing dedicated transaction control or database administration tools, though query can handle many of those operations.
Maintenance
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Deterministic safety, correctness & cost gate that vets Postgres SQL before your AI agent runs it.
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Query Postgres, MySQL, SQL Server, Oracle, BigQuery, ClickHouse and Redshift from your AI client.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables AI assistants to query business databases directly via natural language, with enforced read-only access and secure query limits. Supports SQLite and PostgreSQL, and works with any OpenAI-compatible model.0ISC
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to safely explore and query databases across SQLite, PostgreSQL, MySQL, and MSSQL, with schema introspection, natural language queries, and data profiling.MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to query Postgres, BigQuery and DuckDB read-only through policy-checked SQL, with AST-based guards that refuse writes and dangerous functions, column masking on the way out, and an audit log of every query. Also exposes schema browsing and query-planning tools so agents can see allowed tables, columns and costs before running anything.MIT
- AlicenseAqualityBmaintenanceEnables AI agents to inspect database schemas and run strictly read-only SQL queries with guardrails against destructive statements, multi-statement chaining, and unbounded scans. Supports SQLite natively and PostgreSQL optionally.484 PyPIMIT