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.
The server includes the following 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 INSERT queries
- execute_select_query: Executes SELECT queries
- execute_show_tables: Retrieves table lists
docker run -d --name mcp-mysql \
-e MYSQL_HOST=localhost \
-e MYSQL_PORT=3306 \
-e MYSQL_USER=root \
-e MYSQL_PASSWORD=mcpTest1234!!! \
-e MYSQL_DATABASE=mcp_test \
-e MCP_PORT=8081 \
-p 3306:3306 mineru/mcp-mysql:1.0.0
docker-compose up -d
pip install -r requirements.txt
python mysql_mcp_server/main.py run
MCP functionality is available from Cursor version 0.46 and above. Additionally, the MCP feature is only accessible to Cursor Pro account users.
execute
functions implement the actual logic execution (Service Layer). The @tool
decorator helps register the tool with MCP (Controller Layer).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.MCPBoilerPlate/
├── mysql_mcp_server/ # Main application directory
│ ├── executors/ # Database operation executors
│ │ ├── create_table.py # Tool for creating tables
│ │ ├── desc_table.py # Tool for viewing table schema
│ │ ├── explain.py # Tool for query execution plans
│ │ ├── insert_query.py # Tool for INSERT query execution
│ │ ├── insight_starter.py # Schema verification tools for write reports
│ │ ├── invoke_viz_pro.py # Tool for Visualization chart recommendation
│ │ ├── select_query.py # Tool for SELECT query execution
│ │ └── show_tables.py # Tool for retrieving table lists
│ ├── helper/ # Utility modules
│ │ ├── db_conn_helper.py # Manages database connections
│ │ ├── logger_helper.py # Logging utilities
│ │ └── tool_decorator.py # Tool decorator
│ └── main.py # Application entry point
├── docker-compose.yml # Docker Compose configuration
├── Dockerfile # Docker image build settings
├── requirements.txt # Dependency package list
└── .env.example # Example environment variables file
executors
directory and register them in __init__.py
..env
file.logger_helper
.# Setup environment
cp .env.example .env
# Modify .env file as needed
# Install dependencies
pip install -r requirements.txt
# Run the server
python mysql_mcp_server/main.py run
# Start database using Docker Compose
docker-compose up -d db
# Build and run mysql-mcp-server with Docker Compose (including rebuilds)
docker-compose up -d --build mysql-mcp-server
A server application designed on top of MCP to interact with Cursor and MySQL.