hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Integrations
Enables configuration through environment variables stored in .env files, allowing users to securely store database connection details and other configuration options.
Supports deployment as a Docker container, making it easy to run the MCP server in containerized environments with proper isolation and dependency management.
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.
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 execute - Returns: Query results as array of objects
write_query
- Execute INSERT, UPDATE, or DELETE queries
- Input:
*query
(string): The SQL modification query - Returns:
{ affected_rows: number }
create_table
- Create new tables in the database
- Input:
*query
(string): CREATE TABLE SQL statement - Returns: 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 describe - Returns: 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 tables - Create tables with
create_table
if needed - Insert 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 serverCopy
- Configure MCP in Cursor settingsAdd your MCP server URL:Copy
- Use Cursor commands to access MCPIn the Cursor editor, use:For parameterized queries:CopyCopy
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()
decorator - Implement the tool logic using the
MySQLDatabase
class - Update 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.