apaezespinosa/mcp-server-mysql
If you are the rightful owner of mcp-server-mysql 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.
A Model Context Protocol (MCP) server that provides seamless connectivity and operations for MySQL databases, allowing AI assistants to interact with MySQL databases through a standardized protocol.
MCP Server for MySQL
A Model Context Protocol (MCP) server that provides seamless connectivity and operations for MySQL databases. This server allows AI assistants to interact with MySQL databases through a standardized protocol.
🎯 Quick Setup
| IDE | Setup Time | Configuration File |
|---|---|---|
| Cursor | 2 minutes | cursor-mcp-config.json |
| VS Code | 3 minutes | .vscode/settings.json |
| IntelliJ | 5 minutes | External Tools |
| Others | 5 minutes | Generic MCP config |
Need help? Jump to IDE Integration for detailed instructions.
Table of Contents
- Features
- Installation
- Quick Start
- Usage
- IDE Integration
- Configuration
- Development
- Troubleshooting
- Contributing
Features
- Database Connection Management: Secure connection handling with configurable parameters
- SQL Query Execution: Execute SELECT, INSERT, UPDATE, DELETE, and other SQL operations
- Schema Exploration: Discover database structure, tables, columns, indexes, and constraints
- Table Information: Get detailed information about table schemas and relationships
- Database Listing: List available databases and tables
- Error Handling: Comprehensive error handling with detailed error messages
- Connection Pooling: Efficient connection management for better performance
- SSL Support: Secure connections with SSL/TLS encryption
Installation
Prerequisites
- Node.js 18+
- MySQL server 5.7+ or MySQL 8.0+
- npm or yarn package manager
Setup
Option 1: Quick Install (Recommended)
git clone <repository-url>
cd mcp-server-mysql
./install.sh
Option 2: Manual Setup
-
Clone or download this repository
git clone <repository-url> cd mcp-server-mysql -
Install dependencies
npm install -
Configure environment variables
cp .env.example .envEdit
.envfile with your MySQL connection details:MYSQL_HOST=localhost MYSQL_PORT=3306 MYSQL_USER=your_username MYSQL_PASSWORD=your_password MYSQL_DATABASE=your_database MYSQL_SSL=false -
Build the project
npm run build
Quick Start
For Cursor Users
- Clone this repository
- Run
npm install && npm run build - Copy
cursor-mcp-config.jsonto your Cursor config directory - Update the MySQL connection details in the config
- Restart Cursor and start chatting with your database!
For VS Code Users
- Clone this repository
- Run
npm install && npm run build - Install the MCP extension from VS Code marketplace
- Update
.vscode/settings.jsonwith your MySQL credentials - Press F5 to debug or use the provided tasks
For Other IDEs
- Follow the installation steps below
- Use the generic MCP client configuration
- Configure your IDE according to the specific instructions
🚀 IDE Integration
Important: This MCP server works with multiple IDEs! See the detailed IDE Integration section below for step-by-step instructions for your preferred editor.
Supported IDEs:
- ✅ Cursor (Built-in MCP support)
- ✅ Visual Studio Code (with MCP extension)
- ✅ IntelliJ IDEA / WebStorm
- ✅ Sublime Text
- ✅ Vim/Neovim
- ✅ Any MCP-compatible client
Usage
Running the Server
Development mode:
npm run dev
Production mode:
npm start
Watch mode (auto-restart on changes):
npm run watch
Available Tools
The MCP server provides the following tools for MySQL operations:
1. mysql_query
Execute SQL queries on the MySQL database.
Parameters:
query(string): The SQL query to executedatabase(string, optional): Specific database to query (overrides default)
Example:
{
"name": "mysql_query",
"arguments": {
"query": "SELECT * FROM users WHERE age > 25",
"database": "myapp"
}
}
2. mysql_list_databases
List all available databases on the MySQL server.
Example:
{
"name": "mysql_list_databases",
"arguments": {}
}
3. mysql_list_tables
List all tables in a specific database.
Parameters:
database(string, optional): Database name (uses default if not specified)
Example:
{
"name": "mysql_list_tables",
"arguments": {
"database": "myapp"
}
}
4. mysql_describe_table
Get detailed information about a table's structure.
Parameters:
table(string): Table namedatabase(string, optional): Database name (uses default if not specified)
Example:
{
"name": "mysql_describe_table",
"arguments": {
"table": "users",
"database": "myapp"
}
}
5. mysql_get_schema
Get comprehensive schema information for a database.
Parameters:
database(string, optional): Database name (uses default if not specified)
Example:
{
"name": "mysql_get_schema",
"arguments": {
"database": "myapp"
}
}
IDE Integration
Cursor IDE
Cursor has built-in MCP support. Follow these steps to integrate the MySQL MCP server:
-
Install the project dependencies:
npm install npm run build -
Configure Cursor MCP settings:
- Open Cursor settings (Cmd/Ctrl + ,)
- Search for "MCP" or navigate to Extensions → MCP
- Add the following configuration to your MCP settings:
{ "mcpServers": { "mysql": { "command": "node", "args": ["/absolute/path/to/mcp-server-mysql/dist/index.js"], "env": { "MYSQL_HOST": "localhost", "MYSQL_PORT": "3306", "MYSQL_USER": "your_username", "MYSQL_PASSWORD": "your_password", "MYSQL_DATABASE": "your_database" } } } } -
Alternative: Use the provided config file:
- Copy
cursor-mcp-config.jsonto your Cursor configuration directory - Update the paths and environment variables as needed
- Restart Cursor
- Copy
-
Test the connection:
- Open a new chat in Cursor
- Try asking: "List all databases in my MySQL server"
- The MCP server should respond with database information
Visual Studio Code
VS Code requires the MCP extension to work with MCP servers:
-
Install the MCP extension:
- Open VS Code Extensions (Cmd/Ctrl + Shift + X)
- Search for "MCP" or "Model Context Protocol"
- Install the official MCP extension
-
Configure MCP settings:
- Open VS Code settings (Cmd/Ctrl + ,)
- Search for "MCP"
- Add the server configuration:
{ "mcp.servers": { "mysql": { "command": "node", "args": ["${workspaceFolder}/dist/index.js"], "env": { "MYSQL_HOST": "localhost", "MYSQL_PORT": "3306", "MYSQL_USER": "your_username", "MYSQL_PASSWORD": "your_password", "MYSQL_DATABASE": "your_database" } } } } -
Use the provided VS Code configuration:
- The project includes
.vscode/settings.jsonwith pre-configured MCP settings - Update the environment variables in the settings file
- Reload VS Code window (Cmd/Ctrl + Shift + P → "Developer: Reload Window")
- The project includes
-
Debug the MCP server:
- Use the provided launch configurations in
.vscode/launch.json - Set breakpoints in your code
- Press F5 to start debugging
- Use the provided launch configurations in
Other IDEs
IntelliJ IDEA / WebStorm
-
Install Node.js plugin (if not already installed)
-
Configure MCP server as external tool:
- Go to File → Settings → Tools → External Tools
- Add new tool with:
- Name:
MCP MySQL Server - Program:
node - Arguments:
dist/index.js - Working directory:
$ProjectFileDir$ - Environment variables: Add your MySQL connection details
- Name:
-
Create run configuration:
- Go to Run → Edit Configurations
- Add new Node.js configuration
- Set JavaScript file to
dist/index.js - Add environment variables for MySQL connection
Sublime Text
-
Install LSP-MCP package:
- Install Package Control if not already installed
- Install "LSP-MCP" package
-
Configure LSP settings:
- Open Preferences → Package Settings → LSP → Settings
- Add MCP server configuration:
{ "clients": { "mcp-mysql": { "command": ["node", "/path/to/mcp-server-mysql/dist/index.js"], "env": { "MYSQL_HOST": "localhost", "MYSQL_PORT": "3306", "MYSQL_USER": "your_username", "MYSQL_PASSWORD": "your_password", "MYSQL_DATABASE": "your_database" } } } }
Vim/Neovim
-
Install MCP plugin:
" Using vim-plug Plug 'modelcontextprotocol/mcp-vim' -
Configure in your vimrc:
let g:mcp_servers = { \ 'mysql': { \ 'command': 'node', \ 'args': ['/path/to/mcp-server-mysql/dist/index.js'], \ 'env': { \ 'MYSQL_HOST': 'localhost', \ 'MYSQL_PORT': '3306', \ 'MYSQL_USER': 'your_username', \ 'MYSQL_PASSWORD': 'your_password', \ 'MYSQL_DATABASE': 'your_database' \ } \ } \ }
Generic MCP Client Configuration
For any MCP-compatible client, use this configuration:
{
"mcpServers": {
"mysql": {
"command": "node",
"args": ["/absolute/path/to/mcp-server-mysql/dist/index.js"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_username",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database"
}
}
}
}
Configuration
Environment Variables
| Variable | Description | Default |
|---|---|---|
MYSQL_HOST | MySQL server hostname | localhost |
MYSQL_PORT | MySQL server port | 3306 |
MYSQL_USER | MySQL username | root |
MYSQL_PASSWORD | MySQL password | (empty) |
MYSQL_DATABASE | Default database name | (none) |
MYSQL_SSL | Enable SSL connection | false |
MCP_SERVER_NAME | MCP server name | mysql-server |
MCP_SERVER_VERSION | MCP server version | 1.0.0 |
Security Considerations
- Never commit
.envfiles to version control - Use strong passwords for MySQL users
- Enable SSL in production environments
- Consider using connection pooling for high-traffic applications
- Implement proper user permissions in MySQL
Development
Project Structure
mcp-server-mysql/
├── src/
│ ├── index.ts # Main server entry point
│ ├── config.ts # Configuration management
│ ├── types.ts # TypeScript type definitions
│ ├── connection.ts # MySQL connection management
│ └── tools/ # MCP tool implementations
│ ├── query.ts # SQL query execution
│ ├── schema.ts # Schema exploration
│ └── database.ts # Database operations
├── dist/ # Compiled JavaScript output
├── package.json # Project dependencies and scripts
├── tsconfig.json # TypeScript configuration
├── .env.example # Environment variables template
└── README.md # This file
Building from Source
# Install dependencies
npm install
# Build TypeScript to JavaScript
npm run build
# Run in development mode
npm run dev
Testing
To test the server, you can use any MCP-compatible client or test the tools directly:
# Test database connection
npm run dev
Troubleshooting
IDE-Specific Issues
Cursor IDE:
- MCP Server Not Found: Ensure the path to
dist/index.jsis absolute - Connection Timeout: Check if the server is running and accessible
- Permission Denied: Verify Node.js permissions and file access rights
VS Code:
- Extension Not Working: Ensure MCP extension is properly installed and enabled
- Debug Not Starting: Check launch.json configuration and Node.js path
- Tasks Not Running: Verify tasks.json syntax and npm script availability
IntelliJ IDEA:
- External Tool Fails: Check Node.js installation and PATH configuration
- Run Configuration Error: Verify JavaScript file path and environment variables
- Plugin Conflicts: Disable conflicting database plugins if issues occur
Common Issues
-
Connection Refused
- Verify MySQL server is running
- Check host and port configuration
- Ensure firewall allows connections
-
Authentication Failed
- Verify username and password
- Check MySQL user permissions
- Ensure user can connect from the specified host
-
Database Not Found
- Verify database name in configuration
- Ensure database exists on MySQL server
- Check user has access to the database
-
SSL Connection Issues
- Verify SSL configuration
- Check certificate validity
- Ensure MySQL server supports SSL
-
IDE Integration Issues
- Path Problems: Use absolute paths in IDE configurations
- Environment Variables: Ensure all required env vars are set
- Node.js Version: Verify Node.js 18+ is installed and accessible
- Build Issues: Run
npm run buildbefore starting the server
Logs and Debugging
Enable debug logging by setting environment variables:
DEBUG=mcp:* npm run dev
IDE-Specific Debugging:
VS Code:
- Use the provided launch configurations
- Set breakpoints in TypeScript source files
- View debug console for detailed output
Cursor:
- Check Cursor's developer console (Help → Toggle Developer Tools)
- Monitor network requests in the Network tab
- Use browser dev tools for debugging
IntelliJ IDEA:
- Use the built-in debugger with Node.js run configurations
- Set breakpoints and inspect variables
- View console output in the Run tool window
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
MIT License - see LICENSE file for details.
Support
For issues and questions:
- Create an issue in the repository
- Check the troubleshooting section
- Review MySQL documentation for database-specific issues