MCP Server to connect the MySQL database
Project description
MySQL MCP Server
A Model Context Protocol (MCP) server that provides an interface for AI models to interact with MySQL databases through natural language queries.
Overview
This package creates an MCP server that connects to a MySQL database and exposes a tool to execute SQL queries. It allows AI models like Claude to interact with your MySQL database without direct database access.
Prerequisites
- Python 3.11 or above
- MySQL database
Installation
You can install the MCP MySQL server using pip:
pip install mcp_mysql_connect
Or using UV:
uv pip install mcp_mysql_connect
Configuration
The server requires the following environment variables:
DB_HOST- MySQL server hostDB_USER- MySQL usernameDB_PASSWORD- MySQL passwordDB_NAME- MySQL database name
You can set these using a .env file or directly in your environment.
Usage Options
1. Using with Cursor
Add the following to your ~/.cursor/mcp.json configuration:
"mysql-mcp-server": {
"command": "uvx",
"args": [
"--from",
"mcp_mysql_connect",
"mcp_mysql_connect"
],
"env": {
"DB_HOST": "your-mysql-host",
"DB_USER": "your-username",
"DB_PASSWORD": "your-password",
"DB_NAME": "your-database"
}
}
Alternative configuration:
"mysql-mcp-server": {
"command": "uv",
"args": [
"run",
"--with",
"mcp_mysql_connect",
"-m",
"mcp_mysql_connect"
],
"env": {
"DB_HOST": "your-mysql-host",
"DB_USER": "your-username",
"DB_PASSWORD": "your-password",
"DB_NAME": "your-database"
}
}
2. Using with Python Code
from mcp.client import Client
from mcp.tools import Tools
# Connect to the MySQL MCP server
tools = Tools()
tools.add_server("mysql", "mcp_mysql_connect")
# Create a client with the tools
client = Client(tools=tools)
# Example query
response = client.complete(
messages=[
{"role": "user", "content": "Query all users from the database"}
]
)
print(response.content)
3. Running Manually
Start the server manually:
# Set environment variables first
export DB_HOST=your-mysql-host
export DB_USER=your-username
export DB_PASSWORD=your-password
export DB_NAME=your-database
# Then run the server
python -m mcp_mysql_connect
Available Tools
The server provides a SQL execution tool that can be used to query your MySQL database:
read_query(query: str, params: List[str] = None)- Execute a SQL SELECT query against the database
Example Queries
When using with Claude or other AI models, you can ask natural language questions like:
- "Show me all users who registered in the last week"
- "What are the top 5 selling products?"
- "Count how many orders each customer has placed"
The AI model will translate these into SQL queries and use the MCP server to execute them.
License
MIT License
Contributing
Contributions welcome! Please feel free to submit a Pull Request.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_mysql_connect-1.0.3.tar.gz.
File metadata
- Download URL: mcp_mysql_connect-1.0.3.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bad2769188774e8f628d6832642c9887f49fc8a7c7d0ae93714f58eee2705bf5
|
|
| MD5 |
e1bcfcef53660825b9ea7072cb70883f
|
|
| BLAKE2b-256 |
99bd9dcaa54bed4804225db014f963d11af4b5e8d84cbf1950b0fa57a243e793
|
File details
Details for the file mcp_mysql_connect-1.0.3-py3-none-any.whl.
File metadata
- Download URL: mcp_mysql_connect-1.0.3-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4931228f39123b87a861d7684aa6362f195f9d24f9f899516c660941c0dd60af
|
|
| MD5 |
4c8f02c6b888e0c7a8d7ac3b7e03d2c3
|
|
| BLAKE2b-256 |
1b722faa6a6c383e4b525c04275e4a0ce16bd3cf379406e4d77691ee63e13d6a
|