mysql mcp server
Allows AI assistants to list tables, read data, and execute SQL queries through a controlled interface, making database exploration and analysis safer and more structured.
Allows AI assistants to list tables, read data, and execute SQL queries through a controlled interface, making database exploration and analysis safer and more structured.
A Model Context Protocol (MCP) server that enables secure interaction with MySQL databases. This server allows AI assistants to list tables, read data, and execute SQL queries through a controlled interface, making database exploration and analysis safer and more structured.
pip install mysql-mcp-server
To install MySQL Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install mysql-mcp-server --client claude
Set the following environment variables:
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_database
Add this to your claude_desktop_config.json
:
{
"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"
}
}
}
}
# Install dependencies
pip install -r requirements.txt
# Run the server
python -m mysql_mcp_server
# Clone the repository
git clone https://github.com/yourusername/mysql_mcp_server.git
cd mysql_mcp_server
# Create virtual environment
python -m venv venv
source venv/bin/activate # or `venvScriptsactivate` on Windows
# Install development dependencies
pip install -r requirements-dev.txt
# Run tests
pytest
This MCP server requires database access to function. For security:
See MySQL Security Configuration Guide for detailed instructions on: - Creating a restricted MySQL user - Setting appropriate permissions - Monitoring database access - Security best practices
⚠️ IMPORTANT: Always follow the principle of least privilege when configuring database access.
MIT License - see LICENSE file for details.
git checkout -b feature/amazing-feature
)git commit -m 'Add some amazing feature'
)git push origin feature/amazing-feature
)[
{
"description": "Execute an SQL query on the MySQL server",
"inputSchema": {
"properties": {
"query": {
"description": "The SQL query to execute",
"type": "string"
}
},
"required": [
"query"
],
"type": "object"
},
"name": "execute_sql"
}
]