mcp-sql
MCP server that lets LLMs query PostgreSQL, SQLite, and MySQL databases. Single binary, read-only by default, multi-database.
Install
cargo install mcp-sql
Usage
# Demo mode — try it instantly with sample data
mcp-sql --demo
# Single database
mcp-sql --url postgres://user:pass@localhost/mydb
# SQLite
mcp-sql --url sqlite:path/to/db.sqlite
# Multiple databases
mcp-sql --url postgres://localhost/app --url sqlite:analytics.db
# Enable write operations
mcp-sql --url sqlite:local.db --allow-write
# Custom row limit
mcp-sql --url mysql://user:pass@localhost/shop --row-limit 500
# Read URL from environment variable
mcp-sql --url-env DATABASE_URL
# Mix --url and --url-env
mcp-sql --url sqlite:local.db --url-env PROD_DB_URL
# Custom query timeout (default: 30s)
mcp-sql --url sqlite:local.db --query-timeout 60
Configuration
Claude Code
claude mcp add sql -- mcp-sql --url sqlite:path/to/your.db
Or edit ~/.claude.json directly:
{
"mcpServers": {
"sql": {
"type": "stdio",
"command": "mcp-sql",
"args": ["--url", "sqlite:path/to/your.db"]
}
}
}
Claude Desktop
Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"sql": {
"command": "mcp-sql",
"args": [
"--url", "postgres://user:pass@localhost/mydb",
"--url", "sqlite:analytics.db"
]
}
}
}
Cursor / VS Code
Add to your MCP config (.cursor/mcp.json or equivalent):
{
"mcpServers": {
"sql": {
"command": "mcp-sql",
"args": ["--url", "sqlite:path/to/your.db"]
}
}
}
Tools
All tools accept an optional database parameter when multiple databases are connected. If only one database is connected, it's used automatically.
CLI Options
At least one --url or --url-env is required (unless using --demo).
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
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.