A secure, feature-rich MySQL Model Context Protocol server
MySQL MCP Server
A secure, feature-rich MySQL Model Context Protocol (MCP) server designed for integration with AI assistants like Claude and VS Code GitHub Copilot.
Features
- Security First: Built with security best practices, input validation, and configurable access controls
- Configurable Operations: Enable/disable CRUD operations and table creation based on your needs (read operations enabled by default)
- Tabular Data Display: Properly formatted responses for easy data visualization
- Comprehensive Logging: Detailed logging for debugging and monitoring
- Environment-Based Configuration: Easy setup using environment variables or configuration objects
- NPM Package: Ready to use as a dependency in your projects
Usage
With Visual Studio Code
Add this to your .vscode/mcp.json:
{
"servers": {
"mysql": {
"command": "npx",
"args": ["@lakshya-mcp/mysql-mcp-server-claude"],
"env": {
"MYSQL_HOST": "{your_host}",
"MYSQL_PORT": "{your_port}",
"MYSQL_USER": "{your_username}",
"MYSQL_PASSWORD": "{your_password}",
"MYSQL_DATABASE": "{your_database}",
"MYSQL_ALLOW_CREATE": "false",
"MYSQL_ALLOW_UPDATE": "false",
"MYSQL_ALLOW_DELETE": "false",
"MYSQL_ALLOW_CREATE_TABLE": "false",
"MYSQL_READ_ONLY": "true" // Set to "true" for read-only mode; "false" allows writes.
}
}
}
}
With Claude Desktop
Add this to your claude_desktop_config.json.
Follow these instructions to locate file.
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["@lakshya-mcp/mysql-mcp-server-claude"],
"env": {
"MYSQL_HOST": "{your_host}",
"MYSQL_PORT": "{your_port}",
"MYSQL_USER": "{your_username}",
"MYSQL_PASSWORD": "{your_password}",
"MYSQL_DATABASE": "{your_database}",
"MYSQL_ALLOW_CREATE": "false",
"MYSQL_ALLOW_UPDATE": "false",
"MYSQL_ALLOW_DELETE": "false",
"MYSQL_ALLOW_CREATE_TABLE": "false",
"MYSQL_READ_ONLY": "true" // Set to "true" for read-only mode; "false" allows writes.
}
}
}
}
Save file and restart claude desktop. It should be visible under tools (check icon next to +).
With Claude Code
Open terminal and run this command:
For windows (without wsl):
claude mcp add mysql -e MYSQL_HOST=localhost -e MYSQL_PORT=3306 -e MYSQL_USER=root -e MYSQL_PASSWORD={your_password} -e MYSQL_DATABASE={your_database} -e MYSQL_ALLOW_CREATE=false -e MYSQL_ALLOW_UPDATE=false -e MYSQL_ALLOW_DELETE=false -e MYSQL_ALLOW_CREATE_TABLE=false -e MYSQL_READ_ONLY=true -- cmd /c npx @lakshya-mcp/mysql-mcp-server-claude
For mac / windows (with wsl):
claude mcp add mysql -e MYSQL_HOST=localhost -e MYSQL_PORT=3306 -e MYSQL_USER=root -e MYSQL_PASSWORD={your_password} -e MYSQL_DATABASE={your_database} -e MYSQL_ALLOW_CREATE=false -e MYSQL_ALLOW_UPDATE=false -e MYSQL_ALLOW_DELETE=false -e MYSQL_ALLOW_CREATE_TABLE=false -e MYSQL_READ_ONLY=true -- npx -y @lakshya-mcp/mysql-mcp-server-claude
Then type: claude and run /mcp. It should show:
❯ 1. mysql ✔ connected · Enter to view details
With Gemini CLI
Navigate to your home directory and look for a folder named .gemini.
Inside that folder, you will find the settings.json file.
Add this in your .gemini/settings.json file:
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["@lakshya-mcp/mysql-mcp-server-claude"],
"env": {
"MYSQL_HOST": "{your_host}",
"MYSQL_PORT": "{your_port}",
"MYSQL_USER": "{your_username}",
"MYSQL_PASSWORD": "{your_password}",
"MYSQL_DATABASE": "{your_database}",
"MYSQL_ALLOW_CREATE": "false",
"MYSQL_ALLOW_UPDATE": "false",
"MYSQL_ALLOW_DELETE": "false",
"MYSQL_ALLOW_CREATE_TABLE": "false",
"MYSQL_READ_ONLY": "true" // Set to "true" for read-only mode; "false" allows writes.
}
}
}
}
Then restart gemini cli. You should be able to see mysql mcp server.
You can verify by running /mcp.
Within your project
Tools (3)
list_tablesLists all tables in the connected MySQL databasedescribe_tableRetrieves the schema structure of a specific tablequeryExecutes a SQL query against the databaseEnvironment Variables
MYSQL_HOSTrequiredThe hostname of the MySQL serverMYSQL_PORTrequiredThe port number of the MySQL serverMYSQL_USERrequiredThe username for database authenticationMYSQL_PASSWORDrequiredThe password for database authenticationMYSQL_DATABASErequiredThe name of the database to connect toMYSQL_READ_ONLYSet to true to restrict operations to read-only modeConfiguration
{"mcpServers": {"mysql": {"command": "npx", "args": ["@lakshya-mcp/mysql-mcp-server-claude"], "env": {"MYSQL_HOST": "{your_host}", "MYSQL_PORT": "{your_port}", "MYSQL_USER": "{your_username}", "MYSQL_PASSWORD": "{your_password}", "MYSQL_DATABASE": "{your_database}", "MYSQL_READ_ONLY": "true"}}}}