Supports deployment as a Docker container, making it easy to run the MCP server in containerized environments with proper isolation and dependency management.
Enables configuration through environment variables stored in .env files, allowing users to securely store database connection details and other configuration options.
Provides database interaction capabilities through MySQL, enabling SQL query execution, table creation, and database schema exploration with tools for reading data, writing data, creating tables, listing tables, and describing table schemas.
Leverages SQLAlchemy as the database abstraction layer for connecting to and interacting with MySQL databases, handling database connections and query execution.
MySQL MCP Server
Overview
A Model Context Protocol (MCP) server implementation that provides database interaction capabilities through MySQL. This server enables running SQL queries, creating tables, and exploring database schema information.
Components
Tools
The server offers five core tools:
Query Tools
read_query
Execute SELECT queries to read data from the database
Input:
*query
(string): The SELECT SQL query to executeReturns: Query results as array of objects
write_query
Execute INSERT, UPDATE, or DELETE queries
Input:
*query
(string): The SQL modification queryReturns:
{ affected_rows: number }
create_table
Create new tables in the database
Input:
*query
(string): CREATE TABLE SQL statementReturns: Confirmation of table creation
Schema Tools
list_tables
Get a list of all tables in the database
No input required
Returns: Array of table names
describe_table
View schema information for a specific table
Input:
*table_name
(string): Name of table to describeReturns: Array of column definitions with names and types
Installation
Prerequisites
Python 3.10+
MySQL database
Required Python packages:
mcp
(Model Context Protocol)sqlalchemy
pymysql
(or another MySQL driver)python-dotenv
uvicorn
(for HTTP transport)
Setup with Conda
First, create and activate a conda environment:
Then, install the required dependencies:
Configuration
You can configure the server using:
Environment Variables File (.env)
Copy the
.env.template
file and rename it to.env
:
Edit the
.env
file with your configuration:
Command Line Arguments
You can also override configuration with command line arguments:
Usage
Starting the Server
Testing with MCP Inspector
You can test the server using the MCP Inspector tool:
This will start the server and allow you to interactively test the available tools.
Example Workflow
Start the server with your MySQL database connection
Connect an AI model to the server using the MCP client
Use the
list_tables
tool to see available tablesCreate tables with
create_table
if neededInsert data with
write_query
Query data with
read_query
Usage with Claude Desktop
uv
Add the server to your claude_desktop_config.json
:
Docker
Add the server to your claude_desktop_config.json
:
Package Installation
You can also install the package using pip:
In Cursor IDE
Cursor is an AI-assisted IDE. You can integrate this MCP server with Cursor to query MySQL databases directly during coding.
Setup in Cursor
Start the MCP server
Configure MCP in Cursor settings
Add your MCP server URL:
Use Cursor commands to access MCP
In the Cursor editor, use:
For parameterized queries:
API Reference
Input Format
Output Format
Security Considerations
This server should be run in a trusted environment as it allows arbitrary SQL queries
In production, implement proper access control and input validation
Consider limiting the types of SQL commands that can be executed
Important: Do not commit
.env
files containing sensitive information to version control
Development
Project Structure
src/mysql/server.py
: Main server implementationpyproject.toml
: Package configurationREADME.md
: This documentation
Adding New Features
To extend the server with new capabilities:
Add new tools using the
@mcp.tool()
decoratorImplement the tool logic using the
MySQLDatabase
classUpdate the documentation to reflect the new capabilities
License
This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License.
This server cannot be installed
A Model Context Protocol server that enables AI models to interact with MySQL databases through natural language, supporting SQL queries, table creation, and schema exploration.
Related MCP Servers
- 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 -5310MIT 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
- AsecurityAlicenseAqualityA Model Context Protocol server that enables AI models to interact with both MySQL and MongoDB databases through a standardized interface, supporting comprehensive database operations including queries, schema management, and CRUD operations.Last updated -146MIT License
- AsecurityFlicenseAqualityA Model Context Protocol server that allows AI agents to execute SQL queries against a MySQL database, supporting operations like reading data, creating tables, inserting, updating, and deleting records.Last updated -62797