A Model Context Protocol (MCP) server for executing SQL queries on MySQL and PostgreSQL databases. This allows Claude and other MCP-compatible AI assistants to connect to and interact with your local databases.
- Dynamic Database Connections: Connect to any MySQL or PostgreSQL database
- READ-ONLY Security: Only SELECT, SHOW, DESCRIBE, and EXPLAIN queries are allowed
- Multi-Statement Protection: Prevents SQL injection
- Database Exploration: List tables and describe table structures
- No Configuration Files: Database credentials are provided at runtime
- Clone the repository
- Create and activate a virtual environment
- Install dependencies:
pip install -r requirements.txt
./start_server.shOr:
python3 mcp_server.py- connect_database: Connect to a MySQL or PostgreSQL database
- execute_query: Execute READ-ONLY SQL queries
- list_tables: List all tables in a database
- describe_table: Get the structure of a table
To connect, provide the following details:
db_type:mysqlorpostgresqlhost:127.0.0.1port: (e.g., 3306 for MySQL, 5432 for PostgreSQL)user: your_userpassword: your_passworddatabase: your_dbconnection_name: a unique name for the connection
- Read-Only: Only
SELECT,SHOW,DESCRIBE,EXPLAINare allowed. - Destructive commands are blocked:
UPDATE,DELETE,INSERT, etc. - Multi-statement queries are blocked.
- Parameterized queries are supported.
- Basic tests:
python3 test_mcp.py - Security tests:
python3 test_readonly.py