Provides read-only access to MySQL databases with query validation, enabling AI assistants to execute SELECT queries securely while blocking dangerous SQL operations
Supports SSL/TLS connections to PlanetScale cloud databases, enabling secure read-only access to MySQL-compatible databases
MySQL MCP Server
A Model Context Protocol (MCP) server that provides AI assistants with read-only access to MySQL databases. The server validates all queries to ensure only SELECT statements are executed.
Features
Read-only access - Only SELECT queries are allowed
Query validation - Blocks dangerous SQL operations (INSERT, UPDATE, DELETE, DROP, etc.)
SSL/TLS support - Works with cloud databases like PlanetScale
Secure credentials - Database credentials stay on the server, never exposed to AI clients
Prerequisites
Bun runtime
MySQL database with a read-only user
Installation
Configuration
Create a .env file in the project root:
Creating a Read-Only MySQL User
For security, create a dedicated read-only user for the AI:
Usage
With Claude Desktop
Add to your claude_desktop_config.json (located at ~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
With Cursor
Add to your MCP server settings:
Manual Testing
Available Tools
execute_sql
Executes a SELECT-only SQL query on the MySQL database.
Input:
Output:
Security
The server implements multiple layers of protection:
Query validation - Must start with
SELECTKeyword blocking - Blocks:
INSERT,UPDATE,DELETE,DROP,CREATE,ALTER,TRUNCATE,REPLACE,GRANT,REVOKE,COMMIT,ROLLBACK,LOCK,CALL,EXECUTE,PREPARE,LOAD,INTO OUTFILE,INTO DUMPFILEInjection prevention - Blocks semicolons (
;) and SQL comments (--,/*)Database-level enforcement - Use a MySQL user with only SELECT privileges
License
MIT