MySQL MCP Server
Enables AI assistants to interact with MySQL databases by executing SQL queries, describing table schemas, and listing tables. It provides seamless database integration for tools like Cursor through the Model Context Protocol.
README
MySQL MCP Server
A Model Context Protocol (MCP) server that provides MySQL database access tools for AI assistants like Cursor.
Overview
This MCP server enables AI assistants to interact with MySQL databases by providing three essential tools:
- Execute SQL queries
- Describe table structures
- List all database tables
Features
- Query Execution: Run any SQL query against your MySQL database
- Table Description: Get detailed schema information for any table
- Table Listing: View all tables in your database
- Error Handling: Comprehensive error handling for database operations
- MCP Protocol Compliance: Fully compatible with MCP 2024-11-05 specification
Prerequisites
- Node.js (v14 or higher)
- MySQL database (local or remote)
- Cursor IDE (for MCP integration)
Installation
- Clone or download this repository
- Install dependencies:
npm install
Configuration
The server uses environment variables for database configuration:
MYSQL_HOST: MySQL server hostnameMYSQL_USER: Database usernameMYSQL_PASSWORD: Database passwordMYSQL_DATABASE: Database nameMYSQL_PORT: MySQL port (default: 3306)
Cursor Integration
To use this MCP server with Cursor, add the following configuration to your Cursor MCP settings file (~/.cursor/mcp.json):
{
"mcpServers": {
"mysql-mcp": {
"label": "MySQL MCP",
"command": "node",
"args": ["/path/to/your/mysql-mcp-server.js"],
"env": {
"MYSQL_HOST": "your-mysql-host",
"MYSQL_USER": "your-username",
"MYSQL_PASSWORD": "your-password",
"MYSQL_DATABASE": "your-database",
"MYSQL_PORT": "3306"
}
}
}
}
Replace /path/to/your/mysql-mcp-server.js with the actual path to your server file and update the environment variables with your database credentials.
Available Tools
1. mysql_query
Execute any SQL query against the database.
Parameters:
query(string): The SQL query to execute
Example:
SELECT * FROM users WHERE role = 'admin'
2. mysql_describe_table
Get the structure and schema information for a specific table.
Parameters:
table_name(string): Name of the table to describe
Example:
mysql_describe_table("users")
3. mysql_list_tables
List all tables in the database.
Parameters: None required.
Usage Examples
Once configured in Cursor, you can use natural language to interact with your database:
- "Show me all tables in the database"
- "Describe the structure of the users table"
- "Get all admin users from the user table"
- "Show me recent appointments"
Security Considerations
- Database Credentials: Store sensitive credentials securely and never commit them to version control
- Query Permissions: The server executes queries with the provided database user's permissions
- Network Access: Ensure your database is properly secured and accessible only from authorized sources
- Input Validation: While the server handles errors, always validate and sanitize inputs in production
Troubleshooting
Server Shows as Red in Cursor
- Check that all environment variables are correctly set
- Verify database connectivity
- Ensure Node.js and mysql2 package are properly installed
- Check Cursor's developer console for error messages
Connection Errors
- Verify database host, port, and credentials
- Check network connectivity to the database
- Ensure the database allows connections from your IP
- Verify the database name exists
"0 tools enabled" Error
- Restart Cursor after making configuration changes
- Check the MCP server file path in the configuration
- Ensure the server implements the MCP protocol correctly
Development
File Structure
mcp/
├── mysql-mcp-server.js # Main MCP server implementation
├── package.json # Node.js dependencies
└── README.md # This file
Dependencies
mysql2: MySQL client for Node.js with promise support
Contributing
Feel free to submit issues, feature requests, or pull requests to improve this MCP server.
License
This project is open source and available under the MIT License.
Changelog
v1.0.0
- Initial release
- Basic MCP protocol implementation
- Three core database tools (query, describe, list)
- Error handling and logging
- Cursor integration support
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
E2B
Using MCP to run code via e2b.