MySQL MCP Server is an implementation of the Model Context Protocol for working with MySQL databases. It provides a standardized way to execute queries, retrieve table structures, and access data from MySQL databases through the MCP protocol.
To get started with the MySQL MCP Server, follow these steps:
Clone the repository and install dependencies:
git clone https://github.com/vitalyDV/mysql-mcp.git
cd mysql-mcp
npm install
The MySQL MCP Server requires configuration in the mcp.json
file to define connection parameters and server settings.
Add the following to your mcp.json
file:
{
"mcpServers": {
"mysql_mcp_readonly": {
"command": "node",
"args": [
"./mysql-mcp/index.js"
],
"env": {
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASS": "",
"MYSQL_DB": "db"
}
}
}
}
Configure your MySQL connection using these environment variables:
MYSQL_HOST
- MySQL server hostMYSQL_PORT
- MySQL server portMYSQL_USER
- MySQL usernameMYSQL_PASS
- MySQL passwordMYSQL_DB
- MySQL database nameThe MySQL MCP Server provides several tools for interacting with your database.
Execute SQL queries (limited to SELECT, SHOW, EXPLAIN, DESCRIBE):
query
This tool allows you to run read-only SQL operations against your database.
Retrieve the structure of a specific table:
table-schema
Get a list of all tables in the connected database:
list-tables
Access data from specific tables using the resource format:
table://{name}
This resource returns up to 100 rows from the specified table.
To list all tables in your database:
list-tables
To get the schema of a table named "users":
table-schema users
To execute a custom query:
query SELECT * FROM users LIMIT 10
To access data directly from a table:
table://users
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "mysql_mcp_readonly" '{"command":"node","args":["./mysql-mcp/index.js"],"env":{"MYSQL_HOST":"127.0.0.1","MYSQL_PORT":"3306","MYSQL_USER":"root","MYSQL_PASS":"","MYSQL_DB":"db"}}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"mysql_mcp_readonly": {
"command": "node",
"args": [
"./mysql-mcp/index.js"
],
"env": {
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASS": "",
"MYSQL_DB": "db"
}
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"mysql_mcp_readonly": {
"command": "node",
"args": [
"./mysql-mcp/index.js"
],
"env": {
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASS": "",
"MYSQL_DB": "db"
}
}
}
}
3. Restart Claude Desktop for the changes to take effect