Skip to content

devmilad/cursor-mcp-mysql-database

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  1. Clone or download this repository

    git clone <repository-url>
    cd mysql-mcp
  2. Install dependencies

    npm install
  3. 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

Setup with Cursor IDE

  1. 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
  2. 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

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 .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

Troubleshooting

Common Issues

  1. Connection Refused: Make sure your MySQL server is running and accessible
  2. Authentication Failed: Verify your username and password in the .env file
  3. Permission Denied: Ensure your MySQL user has the necessary permissions
  4. MCP Not Working: Check that the path in mcp-config.json is 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.

About

this repo can connect mysql to the cursor via mcp server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published