This is a Model Context Protocol (MCP) server that allows Cursor IDE to interact with MySQL databases. It provides tools for connecting to databases, executing queries, exploring schemas, and managing database operations.
- 🔌 Database Connection Management: Connect to and disconnect from MySQL databases
- 🔍 Query Execution: Execute SQL queries and get results
- 📋 Schema Exploration: List tables and view table schemas
- 🗄️ Database Management: List available databases and switch between them
- 🛡️ Error Handling: Comprehensive error handling and validation
- 🔧 Environment Configuration: Secure credential management via environment variables
- Node.js (version 18 or higher)
- MySQL server running and accessible
- Cursor IDE
-
Clone or download this repository
git clone <repository-url> cd mysql-mcp
-
Install dependencies
npm install
-
Configure database connection
cp env.example .env
Edit the
.env
file with your MySQL database credentials:DB_HOST=localhost DB_USER=your_username DB_PASSWORD=your_password DB_NAME=your_database DB_PORT=3306
-
Configure MCP in Cursor:
- Open Cursor IDE
- Go to Settings (Ctrl/Cmd + ,)
- Search for "MCP" or "Model Context Protocol"
- Add the path to your
mcp-config.json
file
-
Alternative: Use the MCP configuration directly:
- Copy the contents of
mcp-config.json
to your Cursor MCP settings - Make sure the path to
src/server.js
is correct
- Copy the contents of
The MCP server provides the following tools that Cursor can use:
Connect to a MySQL database.
- Parameters:
host
,user
,password
,database
,port
(optional, default: 3306)
Disconnect from the current database connection.
Execute a SQL query and return results.
- Parameters:
query
(SQL query string)
List all tables in the current database.
Get the schema information for a specific table.
- Parameters:
table_name
List all available databases on the server.
Switch to a different database.
- Parameters:
database
Once configured, you can use these tools in Cursor IDE:
Use the connect tool with:
- host: localhost
- user: myuser
- password: mypassword
- database: mydatabase
Use the execute_query tool with:
- query: SELECT * FROM users LIMIT 10
Use the get_table_schema tool with:
- table_name: users
# Production mode
npm start
# Development mode with auto-restart
npm run dev
You can test the server independently by running:
node src/server.js
- Never commit your
.env
file to version control - Use strong passwords for your MySQL database
- Consider using connection pooling for production use
- Implement proper access controls on your MySQL server
- Connection Refused: Make sure your MySQL server is running and accessible
- Authentication Failed: Verify your username and password in the
.env
file - Permission Denied: Ensure your MySQL user has the necessary permissions
- MCP Not Working: Check that the path in
mcp-config.json
is correct
To enable debug logging, set the environment variable:
DEBUG=mysql-mcp:*
Feel free to submit issues and enhancement requests!
MIT License - see LICENSE file for details.