MySQL MCP Server
Enables Cursor IDE to interact with MySQL databases through schema and data operations, including read and write capabilities with environment-specific safety controls.
README
MySQL MCP Server
A comprehensive MySQL Model Context Protocol (MCP) server that provides database operations for Cursor IDE.
Features
- ✅ Connection Management: Connect to any MySQL database
- ✅ Schema Operations: List databases, tables, describe table structures
- ✅ Data Operations: SELECT, INSERT, UPDATE, DELETE operations
- ✅ Advanced Features: View indexes, foreign keys, execute custom queries
- ✅ Safety: Built-in query limits and error handling
- 🔒 Production Security: Automatic PII protection and audit logging (production environment only)
Prerequisites
Before setting up this MySQL MCP server, ensure you have:
- Node.js (v16 or higher) - Required to run the MCP server
- MySQL Database - Either local or remote MySQL server access
- Cursor IDE - For MCP integration
📁 Repository Note: This repository follows Node.js best practices by excluding
node_modules/anddist/folders. You'll generate these locally after cloning.
Quick Setup
🚀 First Time Setup (After Cloning)
Important: This repository does not include node_modules/ or dist/ folders to keep it lightweight. You'll need to generate them:
-
Clone the repository:
git clone https://github.com/binoy154/mysql-mcp.git cd mysql-mcp⚠️ Important Path Considerations:
- Note the absolute path where you clone this repository (e.g.,
C:/Projects/mysql-mcporE:/mysql-mcp) - You'll need this exact path for Cursor MCP configuration later
- The built files will be at
YOUR_PATH/dist/index.js
- Note the absolute path where you clone this repository (e.g.,
-
Install dependencies:
npm installThis will create the
node_modules/folder with all required packages. -
Build the project:
npm run buildThis will create the
dist/folder with compiled JavaScript files. -
Set up environment variables (optional):
cp .env.example .env # Edit .env with your MySQL credentialsNote: You can also configure credentials directly in Cursor MCP settings.
-
Configure Cursor MCP:
🔧 IMPORTANT: Update the file path below with your actual clone location!
A single MCP server instance can switch between local, staging, preproduction and production environments at runtime. The
localenvironment allows full read/write access, whilestaging,preproduction, andproductionare configured as read-only for safety. Supply their credentials through environment variables:{ "mcpServers": { "mysql": { "command": "node", "args": ["YOUR_ABSOLUTE_PATH/mysql-mcp/dist/index.js"], "env": { "MYSQL_LOCAL_HOST": "localhost", "MYSQL_LOCAL_PORT": "3306", "MYSQL_LOCAL_USER": "root", "MYSQL_LOCAL_PASSWORD": "localPassword", "MYSQL_LOCAL_DATABASE": "localDatabase", "MYSQL_STAGING_HOST": "staging.db.example.com", "MYSQL_STAGING_PORT": "3306", "MYSQL_STAGING_USER": "staging_user", "MYSQL_STAGING_PASSWORD": "staging_pw", "MYSQL_STAGING_DATABASE": "staging_db", "MYSQL_PREPRODUCTION_HOST": "preprod-db.example.com", "MYSQL_PREPRODUCTION_PORT": "3306", "MYSQL_PREPRODUCTION_USER": "preprod_user", "MYSQL_PREPRODUCTION_PASSWORD": "preprod_pw", "MYSQL_PREPRODUCTION_DATABASE": "preprod_db" } } } }📝 Path Examples - Replace
YOUR_ABSOLUTE_PATH/mysql-mcpwith:- Windows:
"C:/Projects/mysql-mcp/dist/index.js" - Windows (E drive):
"E:/mysql-mcp/dist/index.js" - Mac/Linux:
"/home/username/mysql-mcp/dist/index.js"
⚠️ Critical: Use forward slashes (
/) even on Windows, and ensure the path points to where you actually cloned the repository.Database Safety: The
productioncredentials should point to a read-only slave or replica to guarantee safety. Additionally,stagingandpreproductionenvironments are enforced as read-only at the code level to prevent accidental data modifications. - Windows:
Available Tools
Connection Tools
connect_database: Connect with custom credentialslist_databases: Show all available databasesuse_database: Switch to a specific databaseswitch_environment: Switch the active DB environment (local,staging,preproduction,production)
Schema Tools
list_tables: List all tables in current databasedescribe_table: Get detailed table schemaget_table_indexes: View table indexesget_foreign_keys: View foreign key relationships
Data Operations
select_query: Execute SELECT queries with automatic LIMITinsert_data: Insert new recordsupdate_data: Update existing recordsdelete_data: Delete recordsexecute_query: Execute any SQL query (use carefully)
Write operations & permission levels
| Tool | Local | Staging | Pre-production | Production |
|---|---|---|---|---|
insert_data, update_data, delete_data, execute_query |
✅ Immediate | ❌ READ-ONLY | ❌ READ-ONLY | ❌ READ-ONLY |
Note: Only the local environment allows write operations. All other environments (staging, preproduction, production) are configured as read-only for data safety and integrity.
Example (local only):
{
"name": "update_data",
"arguments": {
"table": "users",
"data": { "status": "active" },
"where": "id = 42"
}
}
Usage Examples
Connect to Database
Use the connect_database tool with:
- host: localhost
- port: 3306
- user: myuser
- password: mypassword
- database: myapp_db
Query Data
Use select_query with query: "SELECT * FROM users WHERE active = 1"
Insert Data
Use insert_data with:
- table: "users"
- data: {"name": "John Doe", "email": "john@example.com"}
Security Notes
- Store database credentials securely using environment variables
- SELECT queries automatically include LIMIT 100 unless specified
- The server uses parameterized queries for data operations
- Ensure your MySQL user has appropriate permissions
🔒 Production Security Features
Automatic PII Protection (Production Environment Only):
- Sensitive Data Masking: Columns containing PII (SIN, birth dates, credit cards, etc.) are automatically masked
- Audit Logging: All production database access is logged for compliance
- Zero Impact on Development: Local, staging, and preproduction environments work exactly as before
- Smart Detection: Uses pattern matching to identify sensitive columns (sin, ssn, birth_date, etc.)
Environment Behavior:
- Local/Staging/Preproduction: Full data access (no filtering)
- Production: Automatic sensitive data masking + audit logging
Example Output in Production:
{
"id": 1,
"name": "John Doe",
"email": "jo***@example.com",
"sin": "12*8",
"birth_date": "19**-**-**"
}
Security Status Messages:
- 🔓 DEVELOPMENT MODE: No data filtering (full access)
- 🔒 PRODUCTION MODE: Sensitive data protection active
Deployment to Another Computer
❌ What Won't Work
Simply copying the project folder to another computer will not work without proper setup.
✅ Required Steps for New Installation
-
Install Prerequisites:
- Node.js (v16 or higher)
- Access to a MySQL database
-
Clone or Copy Project Files:
git clone https://github.com/binoy154/mysql-mcp.git cd mysql-mcp- Note the absolute path where you cloned/copied the project
- You'll need this exact path for Cursor MCP configuration
-
Install Dependencies:
npm install -
Build the Project:
npm run build -
Update Cursor Configuration:
- Update the file path in your Cursor MCP settings to match the new location
- Example: Change
"E:/mySqlMcp/dist/index.js"to the correct path on the new computer
-
Configure Database Credentials:
- Update environment variables or Cursor MCP configuration with the correct database connection details for the new environment
📁 What's Included vs. What You Need to Build
✅ Included in this repository:
- Source code (
src/folder) - Configuration files (
package.json,tsconfig.json,README.md) - Documentation files
.gitignore(protects against accidentally committing large folders)
🔨 What you need to build after cloning:
node_modules/folder → Runnpm installdist/folder → Runnpm run build
⚙️ What you need to customize:
- Database credentials (host, port, username, password)
- File paths in Cursor MCP configuration
- Environment-specific settings
💡 Why this approach?
- Keeps repository lightweight (MB instead of GB)
- Avoids platform-specific dependency issues
- Follows Node.js best practices
Troubleshooting
Setup Issues
- "Cannot find module" errors: Run
npm installto install dependencies - "Cannot find dist/index.js": Run
npm run buildto compile TypeScript - Missing
node_modules/folder: This is normal! Runnpm installto create it - Missing
dist/folder: This is normal! Runnpm run buildto create it
Connection Issues
- Verify MySQL server is running
- Check host, port, username, and password
- Ensure user has necessary database permissions
Permission Errors
Grant appropriate MySQL privileges:
GRANT SELECT, INSERT, UPDATE, DELETE ON your_database.* TO 'your_user'@'localhost';
FLUSH PRIVILEGES;
Deployment Issues
- Ensure Node.js is installed on the target computer
- Verify the file path in Cursor MCP configuration is correct
- Check that
npm installandnpm run buildcompleted successfully - Confirm database connectivity from the new computer
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。