Provides comprehensive MySQL database operations including cross-database queries, schema discovery, performance monitoring, health analysis, lock detection, and AI-assisted database management with role-based access control.
MySQL MCP Server
A comprehensive Model Context Protocol (MCP) server for MySQL database operations with advanced features for database analysis, health monitoring, and AI-assisted database management.
🚀 Features
MySQL MCP Server goes beyond basic CRUD operations, providing powerful database analysis capabilities and an extensible framework for custom tools.
🔌 Transport Modes
- STDIO Mode: Direct integration with MCP clients like Cursor, Cline
- SSE Mode: HTTP-based Server-Sent Events for web applications
🗄️ Database Operations
- Cross-Database Access: Connect once, access all databases without switching connections
- Multi-Statement Execution: Execute multiple SQL statements separated by ";"
- Smart Table Discovery: Find tables by comments and descriptions
- SQL Execution Plan Analysis: Performance optimization insights
🛡️ Security & Permissions
- Role-Based Access Control: Three permission levels (readonly, writer, admin)
- SQL Comment Support: Handles SQL statements with
--
and/* */
comments
🔍 Advanced Analysis
- Health Monitoring: Connection, transaction, and lock status analysis
- Performance Insights: Index usage analysis and optimization recommendations
- Lock Detection: Row-level and table-level lock monitoring
- Chinese Text Processing: Pinyin conversion for Chinese field names
🤖 AI Integration
- Prompt Templates: Pre-built AI prompts for database analysis and querying
- Context-Aware Assistance: Intelligent database operation guidance
📋 Permission Levels
Role | Permissions | Use Case |
---|---|---|
readonly | SELECT , SHOW , DESCRIBE , EXPLAIN , USE | Read-only access for reporting and analysis |
writer | readonly + INSERT , UPDATE , DELETE | Application development and data manipulation |
admin | Full database administration | Complete database management including DDL, user management, backup/recovery |
🛠️ Available Tools
Database Operations
Tool | Description |
---|---|
execute_sql | Execute SQL statements with role-based permission control |
get_databases | List all available databases (excluding system databases) |
Schema Discovery
Tool | Description |
---|---|
get_table_desc | Get table structures across databases (supports database.table format) |
get_table_index | Retrieve table indexes with cross-database support |
get_table_name | Find tables by comments and descriptions |
Performance & Health
Tool | Description |
---|---|
get_db_health_running | Analyze MySQL health (connections, transactions, locks) |
get_db_health_index_usage | Index usage analysis with performance recommendations |
get_table_lock | Detect row-level and table-level locks |
Utilities
Tool | Description |
---|---|
get_chinese_initials | Convert Chinese field names to pinyin initials |
🤖 AI Prompt Templates
Prompt Template | Purpose |
---|---|
analyzing-mysql-prompt | Comprehensive MySQL issue analysis and troubleshooting |
query-table-data-prompt | Intelligent table data querying with AI assistance |
🚀 Quick Start
Prerequisites
- Python 3.10+
- UV package manager
- MySQL server
Installation
📦 Installing UV Package Manager
Windows:
Linux/macOS:
🔽 Project Setup
- Clone and install dependencies:Windows (PowerShell):Linux/macOS:
- Configure database connection:Create a
.env
file in the project root directory:Windows (PowerShell):Or manually create.env
file with content:For remote MySQL server (example):
Running the Server
SSE Mode (Web-based)
Windows (PowerShell):
Linux/macOS:
MCP Client Configuration (SSE):
STDIO Mode (Direct integration)
Windows (PowerShell):
Linux/macOS:
MCP Client Configuration (STDIO):
Windows:
Linux/macOS:
🛠️ Windows-Specific Configuration Notes
Common Issues and Solutions
PowerShell Execution Policy: If you encounter execution policy errors, run:
Path Separators:
- Use double backslashes
\\
or forward slashes/
in JSON configuration - Example:
"C:\\Users\\YourName\\mcp_mysql"
or"C:/Users/YourName/mcp_mysql"
Environment Variables in Windows:
Windows Firewall: Ensure MySQL port (default 3306) is allowed through Windows Firewall if connecting to remote MySQL server.
🔧 Extending with Custom Tools
- Create a new tool class:
- Register the tool:
💡 Usage Examples
Cross-Database Operations
List all databases:
Cross-database queries:
Table structure analysis:
AI-Assisted Operations
Performance Analysis:
Health Monitoring:
Smart Table Discovery:
Deadlock Analysis:
📖 Documentation
- Development Guide - For developers working with this codebase
- API Reference - Detailed tool and prompt documentation
🤝 Contributing
- Fork the repository
- Create a feature branch
- Add your custom tools or improvements
- Submit a pull request
📄 License
This project is open source. Please check the license file for details.
Star this repository if you find it helpful! ⭐
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Enables comprehensive MySQL database operations including cross-database queries, performance analysis, health monitoring, and AI-assisted database management with role-based access control.