mineru98_mysql_mcp_server

mineru98_mysql_mcp_server

by Mineru98
A server application built on MCP to enable AI models to interact with MySQL databases.

MySQL Database Integration for MCP Server

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.

Tools

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

Configuration

Running with Docker

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

Running with Docker Compose

docker-compose up -d

Running directly with Python

pip install -r requirements.txt
python mysql_mcp_server/main.py run

Usage

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.

Cursor Setting

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.

Development Roadmap

  • Parameter Options:
  • Enable/Disable Switch for Each Tool
  • Query Security Level Setting
  • Features:
  • Data Analysis Report Generation
  • Extended Text2SQL Support
  • SSH Connection Support
  • File Extraction Function (CSV, JSON, Excel)

System Configuration

Key Components

  • MCP Server: A FastMCP server that communicates with AI models
  • MySQL Database: Manages and stores data
  • Tools: Executors that perform database operations

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

Deployment Environment

  • Containerized deployment via Docker and Docker Compose
  • Ports: 8081 (MCP Server), 3306 (MySQL)

Directory Structure

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

Architecture Design

Layered Structure

  1. Interface Layer: MCP Server (FastMCP)
  2. Business Logic Layer: Handlers and Executors
  3. Data Access Layer: Database connection and query execution

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

Communication Flow

  1. AI model requests a list of available tools from the MCP server.
  2. The server returns the available tools list.
  3. The AI model requests the execution of a specific tool.
  4. The server calls the corresponding executor to perform the database operation.
  5. The execution results are returned to the AI model.

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.

Deployment and Execution

Local Execution

# 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

Docker Deployment

# 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

Security Considerations

  • Manage database credentials via environment variables.
  • Use strong passwords in production environments.
  • Consider implementing SSL/TLS encryption for database connections when necessary.

About

A server application designed on top of MCP to interact with Cursor and MySQL.

Topics

mysql
mcp

Resources

Readme

License

MIT license

Stars

20 stars

Watchers

1 watching

Forks

4 forks

Releases

Version 1.2.0 Latest

Languages

  • Python 52.8%
  • HTML 47.0%
  • Dockerfile 0.2%

Features & Capabilities

Categories
mcp_server model_context_protocol python mysql docker api_integration database_management

Implementation Details

Stats

0 Views
20 GitHub Stars

Repository Info

Mineru98 Organization

Similar MCP Servers

continuedev_continue by continuedev
25049
21423
9300
SunMonTueWedThuFriSat
303112345678910111213141516171819202122232425262728293012345678910
:
PM
SunMonTueWedThuFriSat
303112345678910111213141516171819202122232425262728293012345678910
:
PM