The MySQL MCP Server is a service built on the Model Context Protocol that enables interaction with MySQL databases through Cursor. It allows you to create tables, perform CRUD operations, and execute custom SQL queries directly from the Cursor interface.
Clone or download the repository and install dependencies:
npm install
Create a .env
file based on the example template:
.env.example
file to .env
.env
file with your MySQL database connection information:# Database configuration
DB_HOST=localhost
DB_PORT=3306
DB_USER=your_database_username
DB_PASSWORD=your_database_password
DB_NAME=your_database_name
# Server configuration
PORT=3001
npm start
The server will start at http://localhost:3001 (or the port you specified in the .env
file).
Add the MCP service in Cursor using one of these methods:
/connect-mcp http://localhost:3001/sse
Once connected, you can interact with your MySQL database through resources and tools.
Access database information through these resource paths:
mysql://tables
mysql://schema/table_name
mysql://data/table_name
Execute database operations with these commands:
Create table:
create-table tableName="table_name" schema="id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255)"
Drop table:
drop-table tableName="table_name"
Insert data:
insert-data tableName="table_name" data="{\"name\": \"John\", \"age\": 30}"
Update data:
update-data tableName="table_name" data="{\"name\": \"Jane\"}" condition="{\"id\": 1}"
Delete data:
delete-data tableName="table_name" condition="{\"id\": 1}"
Query data:
query-data tableName="table_name" fields="[\"id\",\"name\"]" condition="{\"age\": 30}"
Execute custom SQL:
execute-sql sql="SELECT * FROM users WHERE age > 18" params="[]"
Get assistance with database operations:
create-table-guide tableName="table_name"
insert-data-guide tableName="table_name"
database-operations
Create a users table:
create-table tableName="users" schema="id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255) NOT NULL, email VARCHAR(255) UNIQUE, age INT"
Insert user data:
insert-data tableName="users" data="{\"name\": \"John\", \"email\": \"[email protected]\", \"age\": 30}"
Query user data:
mysql://data/users
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "mcp-mysql" '{"command":"npm","args":["start"],"url":"http://localhost:3001/sse"}'
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": {
"mcp-mysql": {
"command": "npm",
"args": [
"start"
],
"url": "http://localhost:3001/sse"
}
}
}
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": {
"mcp-mysql": {
"command": "npm",
"args": [
"start"
],
"url": "http://localhost:3001/sse"
}
}
}
3. Restart Claude Desktop for the changes to take effect