A Rust-based MCP (Model Context Protocol) server providing secure multi-database operations for MCP clients.
- Multi-Engine Support - MySQL, PostgreSQL, SQLite
- Multiple Connections - Named database connections via
.databases.json - CRUD Operations - Query, Insert, Update, Delete via MCP tools
- Security First - Parameterized queries, SQL injection prevention, dangerous operation blocking
- Easy Setup - Interactive
--initwizard for agent configuration - Multi-Agent Support - Claude Desktop, Claude Code, Cursor
- High Performance - Async Rust with connection pooling
cargo install sqlx-mcpOr build from source:
git clone https://github.com/epicsagas/sqlx-mcp.git
cd sqlx-mcp
cargo build --release
cp target/release/sqlx-mcp ~/.local/bin/# Interactive setup
sqlx-mcp --init
# Or configure specific agent
sqlx-mcp --init cursor
sqlx-mcp --init claude-code
sqlx-mcp --init claude-desktopsqlx-mcp --statusRestart Claude Desktop, Claude Code, or Cursor to load the MCP server.
Note: For Claude Code, a skill is automatically installed at
~/.claude/skills/sqlx/SKILL.md
Create a .databases.json file in your project directory or ~/.config/sqlx-mcp/:
{
"version": "1.0",
"databases": [
{
"name": "mysql_main",
"engine": "mysql",
"host": "localhost",
"port": 3306,
"username": "root",
"password": "secret",
"database": "myapp"
},
{
"name": "postgres_analytics",
"engine": "postgres",
"host": "localhost",
"port": 5432,
"username": "postgres",
"password": "secret",
"database": "analytics"
},
{
"name": "sqlite_cache",
"engine": "sqlite",
"path": "/var/data/cache.db"
}
],
"default_connection": "mysql_main"
}See .databases.json.example for a complete configuration example.
| Tool | Description |
|---|---|
db_list_connections |
List all configured database connections |
db_query |
Execute SELECT queries, returns JSON array |
db_insert |
Execute INSERT, returns last_insert_id |
db_update |
Execute UPDATE, returns rows_affected |
db_delete |
Execute DELETE, returns rows_affected |
db_list_tables |
List all tables in database |
db_describe_table |
Get table structure |
db_health_check |
Check database connectivity |
The Claude Code skill allows you to use natural language to query databases:
| Request | Description |
|---|---|
| "Get active users from mysql_main" | Query active users from mysql_main |
| "Show recent 10 orders from postgres" | Get recent 10 orders from postgres |
| "List tables in sqlite_cache" | List all tables in sqlite_cache |
| "Describe users table structure in mydb" | Get users table schema |
| "Add new user John to mysql_main" | Insert new user John into mysql_main |
| "Delete record with id 5 from postgres" | Delete record with id 5 from postgres |
{}{
"query": "SELECT * FROM users WHERE status = ?",
"params": ["active"],
"connection": "mysql_main"
}{
"query": "SELECT * FROM orders WHERE user_id = ?",
"params": [123]
}{
"query": "INSERT INTO users (name, email) VALUES (?, ?)",
"params": ["John", "[email protected]"],
"connection": "postgres_analytics"
}{
"query": "UPDATE users SET status = ? WHERE id = ?",
"params": ["inactive", 5]
}{
"query": "DELETE FROM users WHERE id = ?",
"params": [10]
}{
"connection": "sqlite_cache"
}{
"table": "users",
"connection": "mysql_main"
}macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Linux: ~/.config/claude/claude_desktop_config.json
{
"mcpServers": {
"sqlx": {
"command": "sqlx-mcp",
"env": {
"SQLX_MCP_CONFIG": "/path/to/.databases.json",
"RUST_LOG": "info"
}
}
}
}Path: ~/.claude.json
{
"mcpServers": {
"sqlx": {
"command": "sqlx-mcp",
"env": {
"SQLX_MCP_CONFIG": "/path/to/.databases.json",
"RUST_LOG": "info"
}
}
}
}Note: Project-level config can also be placed in
.mcp.jsonin the project root.
Path: ~/.cursor/mcp.json
{
"mcpServers": {
"sqlx": {
"command": "sqlx-mcp",
"env": {
"SQLX_MCP_CONFIG": "/path/to/.databases.json",
"RUST_LOG": "info"
}
}
}
}- Parameterized Queries - All queries use
?placeholders (auto-converted to$1,$2,...for PostgreSQL) - Query Type Validation - SELECT for query, INSERT for insert, etc.
- Dangerous Operations Blocked - DROP, TRUNCATE, ALTER, CREATE, GRANT, REVOKE
- Multi-statement Prevention - Semicolon-separated queries blocked
- Hidden Config File -
.databases.jsonis hidden by default for security
-- Good: Use parameterized queries
SELECT * FROM users WHERE id = ?
-- Bad: Never concatenate values (blocked by design)
SELECT * FROM users WHERE id = 1; DROP TABLE users;# Check database is running
mysql -u your_user -p -h localhost your_database
psql -U your_user -h localhost your_database
# Verify configuration
sqlx-mcp --status- Restart the agent after configuration
- Check config file path and JSON syntax
- Verify binary is in PATH:
which sqlx-mcp - Check
.databases.jsonfile exists and is valid
Apache-2.0 License - see LICENSE for details.
If you find this project useful, consider supporting: