A Model Context Protocol (MCP) server that enables secure interaction with MySQL databases
Configuration
View docs{
"mcpServers": {
"designcomputer-mysql_mcp_server": {
"command": "uv",
"args": [
"--directory",
"path/to/mysql_mcp_server",
"run",
"mysql_mcp_server"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_username",
"MYSQL_DATABASE": "your_database",
"MYSQL_PASSWORD": "your_password"
}
}
}
}You can securely interact with MySQL databases through a dedicated MCP server that exposes a controlled interface for AI applications. It lets you list tables, read data, and run SQL queries with proper error handling, all while keeping credentials and access tightly managed via environment variables.
Use a compatible MCP client (for example, Claude Desktop or Visual Studio Code with the MCP extension) to connect to the MySQL MCP Server. The MCP server acts as a bridge between your AI host and the MySQL database, enabling you to explore data sources and perform queries in a structured, auditable way.
Prerequisites: make sure you have Python installed (for the server package) and, if you choose the Smithery route, Node.js is available on your system.
Install the MySQL MCP Server package with Python’s package manager.
pip install mysql-mcp-serverConfigure the following environment variables to enable secure access to your MySQL database:
MYSQL_HOST=localhost # Database host
MYSQL_PORT=3306 # Optional: Database port (defaults to 3306 if not specified)
MYSQL_USER=your_username
MYSQL_PASSWORD=your_password
MYSQL_DATABASE=your_databaseAdd this MCP server configuration to your Claude Desktop setup to run the MySQL MCP Server via a local process.
{
"mcpServers": {
"mysql": {
"command": "uv",
"args": [
"--directory",
"path/to/mysql_mcp_server",
"run",
"mysql_mcp_server"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_username",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database"
}
}
}
}Add a MCP server entry to your VS Code configuration to run the server as a stdio process.
{
"servers": {
"mysql": {
"type": "stdio",
"command": "uvx",
"args": [
"--from",
"mysql-mcp-server",
"mysql_mcp_server"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_username",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database"
}
}
}
}If you need to debug the MCP implementation interactively, you can use the MCP Inspector. Install dependencies and then launch the inspector tooling to test the MCP configuration without running the server directly through Python.
# Install inspector dependencies
pip install -r requirements.txt
# Use the MCP Inspector for debuggingTo contribute or run the project locally, clone the repository, set up a virtual environment, install development dependencies, and run tests.
git clone https://github.com/designcomputer/mysql_mcp_server.git
cd mysql_mcp_server
python -m venv venv
source venv/bin/activate # or `venv\Scripts\activate` on Windows
pip install -r requirements-dev.txt
pytestNever commit environment variables or credentials. Use a database user with minimal permissions and enable logging for auditability. Consider implementing query whitelisting for production use.
Lists available MySQL tables as resources that you can explore or query.
Reads and returns the contents of a selected table.
Executes a SQL query with proper error handling and returns results or errors.
Ensures secure access via environment variables and minimal privilege database users.
Provides comprehensive logging of database operations for audit and debugging.