sqlx-mcp
A Rust-based MCP (Model Context Protocol) server providing secure multi-database operations for MCP clients.
Features
- 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
Installation
Or build from source:
Quick Start
1. Configure Databases and Agent
# Interactive setup
# Or configure specific agent
2. Check Status
3. Restart Your MCP Client
Restart 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
Configuration
Database Configuration (.databases.json)
Create a .databases.json file in your project directory or ~/.config/sqlx-mcp/:
See .databases.json.example for a complete configuration example.
Available MCP Tools
| 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 |
Usage Examples
Natural Language Examples
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 |
List Connections
Query Data
Query with Default Connection
Insert Data
Update Data
Delete Data
List Tables
Describe Table
Manual Configuration
Claude Desktop
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Linux: ~/.config/claude/claude_desktop_config.json
Claude Code
Path: ~/.claude.json
Note: Project-level config can also be placed in
.mcp.jsonin the project root.
Cursor
Path: ~/.cursor/mcp.json
Security
Built-in Protections
- 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
Best Practices
-- Good: Use parameterized queries
SELECT * FROM users WHERE id = ?
-- Bad: Never concatenate values (blocked by design)
SELECT * FROM users WHERE id = 1; users;
Troubleshooting
Connection Failed
# Check database is running
# Verify configuration
Agent Not Detecting MCP Server
- 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
License
Apache-2.0 License - see LICENSE for details.
Support
If you find this project useful, consider supporting: