A production-ready Python implementation of the Model Context Protocol (MCP) server for universal database connectivity. Connect Cursor, Claude Desktop, and other MCP clients to PostgreSQL, MySQL, MariaDB, SQL Server, and SQLite databases.
- ✅ PostgreSQL - Full support with connection pooling
- ✅ MySQL - Full support with connection pooling
- ✅ MariaDB - Full support (MySQL-compatible)
- ✅ SQL Server - Full support with Azure AD auth
- ✅ SQLite - Full support with clone() for multi-source
- ✅ Resources - Database exploration (schemas, tables, indexes, procedures)
- ✅ Tools - SQL execution with multi-statement support
- ✅ Prompts - AI-assisted SQL generation and database explanation
- ✅ Stdio Transport - Direct integration with Cursor/Claude Desktop
- ✅ Read-Only Mode - Restrict to SELECT queries only
- ✅ Row Limiting - Prevent accidental data dumps
- ✅ Password Redaction - Automatic password masking in logs
- ✅ SSH Tunneling - Secure remote database connections
- ✅ SSL/TLS Support - Encrypted database connections
- ✅ TOML Config - Multi-database project configuration
- ✅ CLI Arguments - Quick testing and single database
- ✅ Environment Variables - Docker and CI/CD deployment
- ✅ .env Files - Local development
- ✅ Demo Mode - Built-in sample database
- Python 3.13+
- pip or uv
git clone https://github.com/yourusername/dmcp-db.git
cd dmcp-db
pip install -e .pip install -r requirements.txtTry DMCP-DB with a sample SQLite database:
dmcp-db --demodmcp-db --dsn="postgres://user:password@localhost:5432/mydb"dmcp-db --dsn="mysql://root:password@localhost:3306/mydb"dmcp-db --dsn="sqlite:///path/to/database.db"Create dmcp-db.toml:
[[sources]]
id = "prod_pg"
type = "postgres"
host = "localhost"
port = 5432
user = "postgres"
password = "password"
database = "production"
readonly = true
max_rows = 1000
[[sources]]
id = "staging_mysql"
type = "mysql"
host = "localhost"
port = 3306
user = "root"
password = "secret"
database = "staging"Run:
dmcp-db --config=dmcp-db.tomlcd dmcp-db
pip install -e .Open Cursor Settings → Features → MCP, or edit ~/.cursor/mcp.json (Linux/Mac) or %APPDATA%\Cursor\User\globalStorage\mcp.json (Windows):
{
"mcpServers": {
"dmcp-db": {
"command": "python",
"args": ["-m", "dmcp", "--demo"]
}
}
}PostgreSQL:
{
"mcpServers": {
"postgres-prod": {
"command": "python",
"args": [
"-m", "dmcp",
"--dsn=postgres://user:password@localhost:5432/mydb",
"--readonly"
]
}
}
}MySQL:
{
"mcpServers": {
"mysql-dev": {
"command": "python",
"args": [
"-m", "dmcp",
"--type=mysql",
"--host=localhost",
"--port=3306",
"--user=root",
"--password=secret",
"--database=mydb"
]
}
}
}Multi-Database:
{
"mcpServers": {
"my-databases": {
"command": "python",
"args": [
"-m", "dmcp",
"--config=C:\\path\\to\\dmcp-db.toml"
]
}
}
}- Restart Cursor
- Open Cursor chat
- The MCP server will appear with a green indicator
- Ask questions like:
- "What tables are in the database?"
- "Show me the schema for the users table"
- "SELECT * FROM employees WHERE department = 'Engineering'"
# Database Connection
--dsn="connection-string" # Full DSN
--type=postgres # Database type
--host=localhost # Database host
--port=5432 # Database port
--user=myuser # Database user
--password=mypass # Database password
--database=mydb # Database name
# Configuration File
--config=path/to/config.toml # TOML config file
# Demo Mode
--demo # Use sample database
# Transport
--transport=stdio # stdio (default) or http
--http-port=8080 # HTTP server port
# Security
--readonly # Enable read-only mode
--max-rows=1000 # Limit result rows
# SSH Tunnel
--ssh-host=bastion.example.com # SSH host
--ssh-port=22 # SSH port
--ssh-user=ubuntu # SSH user
--ssh-password=secret # SSH password
--ssh-key=~/.ssh/id_rsa # SSH private key
# Multi-Instance
--id=prod # Instance ID suffix# Database Connection
export DSN="postgres://user:pass@localhost:5432/db"
# Or individual parameters
export DB_TYPE=postgres
export DB_HOST=localhost
export DB_PORT=5432
export DB_USER=myuser
export DB_PASSWORD=mypass
export DB_NAME=mydb
# Security
export READONLY=true
export MAX_ROWS=1000
# SSH Tunnel
export SSH_HOST=bastion.example.com
export SSH_USER=ubuntu
export SSH_KEY=~/.ssh/id_rsaCreate .env:
DSN=postgres://user:password@localhost:5432/mydb
READONLY=true
MAX_ROWS=1000db://schemas
db://schemas/{schema}/tables
db://schemas/{schema}/tables/{table}
db://schemas/{schema}/tables/{table}/indexes
db://schemas/{schema}/procedures
db://schemas/{schema}/procedures/{procedure}
Execute SQL queries with multi-statement support:
{
"sql": "SELECT * FROM users WHERE id = 1",
"source_id": "prod_pg"
}Generate SQL from natural language:
{
"description": "Get all users who registered in the last 30 days"
}Explain database structure:
{
"table_name": "users",
"schema_name": "public"
}Always enable read-only mode for production databases:
dmcp-db --dsn="..." --readonlyPrevent accidental large data dumps:
dmcp-db --dsn="..." --max-rows=1000Use SSH tunnels for remote databases:
dmcp-db --dsn="postgres://user:pass@localhost:5432/db" \
--ssh-host=bastion.example.com \
--ssh-user=ubuntu \
--ssh-key=~/.ssh/id_rsaNever commit passwords. Use:
- Environment variables
- .env files (add to .gitignore)
- SSH key authentication
- Secrets management systems
PostgreSQL:
# Test connection
psql -h localhost -U postgres -d mydb
# Check SSL mode
dmcp-db --dsn="postgres://...?sslmode=disable"MySQL:
# Test connection
mysql -h localhost -u root -p mydb
# Check charset
dmcp-db --dsn="mysql://...?charset=utf8mb4"SQL Server:
# Check ODBC driver
odbcinst -q -d
# Trust server certificate
dmcp-db --dsn="mssql://...?TrustServerCertificate=yes"- Check Cursor logs: Help → Show Logs
- Verify Python path:
which pythonorwhere python - Test server manually:
python -m dmcp --demo - Check JSON syntax in mcp.json
- Restart Cursor completely
# Linux/Mac
chmod +x $(which dmcp-db)
# Or use full Python path
"command": "/usr/bin/python3"cd dmcp-db
python -m dmcp --demopytestblack src/
isort src/DMCP-DB follows a modular architecture:
- Connectors - Database-specific implementations
- Resources - MCP resource handlers
- Tools - MCP tool handlers
- Prompts - MCP prompt handlers
- Config - Configuration system
- Utils - Security and utility functions
See reference/ directory for detailed architecture documentation.
MIT License - see LICENSE file for details.
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new features
- Submit a pull request