devmilad/cursor-mcp-mysql-database
If you are the rightful owner of cursor-mcp-mysql-database and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
This is a Model Context Protocol (MCP) server designed for integration with Cursor IDE to facilitate interaction with MySQL databases.
MySQL MCP Server for Cursor IDE
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.
Features
- 🔌 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
Prerequisites
- Node.js (version 18 or higher)
- MySQL server running and accessible
- Cursor IDE
Installation
-
Clone or download this repository
git clone <repository-url> cd mysql-mcp -
Install dependencies
npm install -
Configure database connection
cp env.example .envEdit the
.envfile with your MySQL database credentials:DB_HOST=localhost DB_USER=your_username DB_PASSWORD=your_password DB_NAME=your_database DB_PORT=3306
Setup with Cursor IDE
-
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.jsonfile
-
Alternative: Use the MCP configuration directly:
- Copy the contents of
mcp-config.jsonto your Cursor MCP settings - Make sure the path to
src/server.jsis correct
- Copy the contents of
Available Tools
The MCP server provides the following tools that Cursor can use:
1. connect
Connect to a MySQL database.
- Parameters:
host,user,password,database,port(optional, default: 3306)
2. disconnect
Disconnect from the current database connection.
3. execute_query
Execute a SQL query and return results.
- Parameters:
query(SQL query string)
4. get_tables
List all tables in the current database.
5. get_table_schema
Get the schema information for a specific table.
- Parameters:
table_name
6. get_databases
List all available databases on the server.
7. switch_database
Switch to a different database.
- Parameters:
database
Usage Examples
Once configured, you can use these tools in Cursor IDE:
Connect to Database
Use the connect tool with:
- host: localhost
- user: myuser
- password: mypassword
- database: mydatabase
Execute a Query
Use the execute_query tool with:
- query: SELECT * FROM users LIMIT 10
Get Table Schema
Use the get_table_schema tool with:
- table_name: users
Development
Running the Server
# Production mode
npm start
# Development mode with auto-restart
npm run dev
Testing
You can test the server independently by running:
node src/server.js
Security Considerations
- Never commit your
.envfile 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
Troubleshooting
Common Issues
- Connection Refused: Make sure your MySQL server is running and accessible
- Authentication Failed: Verify your username and password in the
.envfile - Permission Denied: Ensure your MySQL user has the necessary permissions
- MCP Not Working: Check that the path in
mcp-config.jsonis correct
Debug Mode
To enable debug logging, set the environment variable:
DEBUG=mysql-mcp:*
Contributing
Feel free to submit issues and enhancement requests!
License
MIT License - see LICENSE file for details.