mcp-sql
MCP server that lets LLMs query PostgreSQL, SQLite, and MySQL databases. Single binary, read-only by default, multi-database.
Install
Usage
# Single database
# SQLite
# Multiple databases
# Enable write operations
# Custom row limit
# Read URL from environment variable
# Mix --url and --url-env
# Custom query timeout (default: 30s)
Configuration
Claude Code
Or edit ~/.claude.json directly:
Claude Desktop
Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
Cursor / VS Code
Add to your MCP config (.cursor/mcp.json or equivalent):
Tools
| Tool | Description |
|---|---|
list_databases |
Show all connected databases with name and type |
list_tables |
List tables with approximate row counts |
describe_table |
Column details: name, type, nullable, default, primary key, foreign key |
sample_data |
Return sample rows from a table as JSON (no SQL needed) |
query |
Execute SQL and return results as JSON |
explain |
Show query execution plan |
All tools accept an optional database parameter when multiple databases are connected. If only one database is connected, it's used automatically.
CLI Options
| Flag | Default | Description |
|---|---|---|
--url |
— | Database connection URL (repeatable) |
--url-env |
— | Read database URL from an environment variable (repeatable) |
--allow-write |
false |
Enable write operations (INSERT, UPDATE, DELETE, CREATE, DROP) |
--row-limit |
100 |
Maximum rows returned per query |
--query-timeout |
30 |
Query timeout in seconds |
At least one --url or --url-env is required.
Safety
- Read-only by default — only
SELECT,WITH,SHOW,PRAGMA, andEXPLAINqueries are allowed - Row limit enforced —
LIMITis injected if not present (default: 100) - Query timeout — queries are killed after the configured timeout (default: 30s)
- Credentials redacted — passwords are masked in
list_databasesoutput - PostgreSQL/MySQL — additionally uses
SET TRANSACTION READ ONLYfor database-level enforcement
Pass --allow-write to enable INSERT, UPDATE, DELETE, CREATE, and DROP operations.
Supported Databases
| Database | URL Scheme | Notes |
|---|---|---|
| PostgreSQL | postgres:// or postgresql:// |
Full support |
| SQLite | sqlite:path or sqlite::memory: |
Full support |
| MySQL | mysql:// or mariadb:// |
Full support |
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.