Supports containerized deployment of the MCP server through Docker, allowing configuration of database connection parameters and port mappings.
Provides environment variable management for configuring database credentials and server settings through .env files.
Includes Mermaid diagram support for visualizing the server architecture and data flow between components.
Enables AI models to interact with MySQL databases by providing tools for executing SQL queries, creating tables, describing table schemas, getting query execution plans, and listing available tables.
Integrates with pandas for processing and analyzing database query results before returning them to AI models.
Built with Python, allowing direct execution of the server outside of Docker containers and easy extension through Python-based tools.
mysql-mcp-server
0. Execution
Running with Docker
Change the database connection information as needed.
Running with Docker Compose
This will proceed with a pre-configured setup.
Running directly with Python
Cursor Configuration
MCP functionality is available from Cursor version 0.46 and above.
Additionally, the MCP feature is only accessible to Cursor Pro account users.
Tool Addition Tips
Adding a Tool
execute
functions implement the actual logic execution (Service Layer).The
@tool
decorator helps register the tool with MCP (Controller Layer).
Explanation
Each file under
mysql_mcp_server/executors
represents a single tool.If a new tool is added, it must be imported in
mysql_mcp_server/executors/__init__.py
and included in the__all__
array.This ensures the module is automatically registered in the
TOOLS_DEFINITION
variable.
🚧 Development Roadmap 🚧
⚙️ Parameter Options
🔧 Enable/Disable Switch for Each Tool: Provide a function to reduce Input Context costs 💰
🔒 Query Security Level Setting: Offer optional control over functions that could damage asset value, such as DROP, DELETE, UPDATE 🚫
✨ Features
📊 Data Analysis Report Generation: Provide a report generation function optimized for the model to appropriately select various charts based on user requests 📈
📝 Reporting capabilities for prescribed forms
🖌️ Diversify report templates
🗄️ Extended Text2SQL Support
🌐 SSH Connection Support: Enable secure remote access via SSH for advanced operations 🔑
📥 File Extraction Function
📄 CSV
📑 JSON
📉 Excel
1. Overview
MCP MySQL Server is a server application for MySQL database operations based on MCP (Model Context Protocol). This server provides tools that allow AI models to interact with the MySQL database.
2. System Configuration
2.1 Key Components
MCP Server: A FastMCP server that communicates with AI models
MySQL Database: Manages and stores data
Tools: Executors that perform database operations
2.2 Tech Stack
Language: Python
Database: MySQL 8.0
Key Libraries:
mcp: Implements Model Context Protocol for AI communication
PyMySQL: Connects to MySQL and executes queries
pandas: Processes and analyzes data
python-dotenv: Manages environment variables
fire: Implements command-line interfaces
2.3 Deployment Environment
Containerized deployment via Docker and Docker Compose
Ports: 8081 (MCP Server), 3306 (MySQL)
3. Directory Structure
4. Architecture Design
4.1 Layered Structure
Interface Layer: MCP Server (FastMCP)
Business Logic Layer: Handlers and Executors
Data Access Layer: Database connection and query execution
4.2 Key Classes and Modules
MySQLMCPServer: Main server class that initializes and runs the MCP server
DatabaseManager: Singleton pattern-based database connection manager
Executors: Collection of tools for database operations
execute_create_table: Creates tables
execute_desc_table: Checks table schema
execute_explain: Provides query execution plans
execute_insert_query: Executes INSETR queries
execute_select_query: Executes SELECT queries
execute_show_tables: Retrieves table lists
4.3 Communication Flow
AI model requests a list of available tools from the MCP server.
The server returns the available tools list.
The AI model requests the execution of a specific tool.
The server calls the corresponding executor to perform the database operation.
The execution results are returned to the AI model.
5. Scalability and Maintenance
Adding Tools: Implement new tools in the
executors
directory and register them in__init__.py
.Environment Configuration: Manage environment variables via the
.env
file.Logging: Ensure consistent logging using
logger_helper
.
6. Deployment and Execution
6.1 Local Execution
6.2 Docker Deployment
7. Security Considerations
Manage database credentials via environment variables.
Use strong passwords in production environments.
Consider implementing SSL/TLS encryption for database connections when necessary.
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
A server that enables AI models to interact with MySQL databases through a Model Control Protocol, providing tools for table creation, schema inspection, query execution, and data retrieval.
- 0. Execution
- 🚧 Development Roadmap 🚧
- 1. Overview
- 2. System Configuration
- 3. Directory Structure
- 4. Architecture Design
- 5. Scalability and Maintenance
- 6. Deployment and Execution
- 7. Security Considerations
Related Resources
Related MCP Servers
- AsecurityAlicenseAqualityThis server enables AI models to interact with MySQL databases through a standardized interface.Last updated -283114MIT License
- AsecurityAlicenseAqualityA Model Context Protocol server that enables AI models to interact with MySQL databases, providing tools for querying, executing statements, listing tables, and describing table structures.Last updated -5283MIT License
- AsecurityFlicenseAqualityA Model Context Protocol server that enables AI models to interact with MySQL databases through a standardized interface, providing tools for querying, executing commands, and managing database schemas.Last updated -7
- -securityFlicense-qualityA Model Context Protocol server that enables AI models to interact with MySQL databases through natural language, supporting SQL queries, table creation, and schema exploration.Last updated -3