Lakshya-Saini/mysql-mcp-server-copilot
If you are the rightful owner of mysql-mcp-server-copilot and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A secure and configurable MySQL MCP server that enables AI agents to interact with MySQL databases safely and efficiently.
MySQL MCP Server
A secure and configurable MySQL MCP (Model Context Protocol) server that enables AI agents to interact with MySQL databases safely and efficiently.
Features
- 🔒 Secure by Default: Only fetch operations are enabled by default
- ⚙️ Configurable Operations: Enable create, update, delete operations through configuration
- 📝 Comprehensive Logging: Detailed logging for debugging and monitoring
- 📦 NPM Package: Ready to use with VS Code GitHub Copilot and other MCP clients
- 🛡️ Security Standards: Input validation, SQL injection prevention, connection security
- 📊 Agent-Friendly Responses: Structured responses optimized for tabular data display
- 🔌 Connection Pooling: Efficient database connection management
- ✅ TypeScript: Full TypeScript support with strict type checking
Installation & Setup
1. VS Code with GitHub Copilot
The easiest way to use this MySQL MCP server is with VS Code and GitHub Copilot:
-
Install VS Code and the GitHub Copilot extension
-
Install the package globally:
npm install -g @lakshya-mcp/mysql-mcp-server-copilot
-
Configure MCP settings by creating/editing your
mcp-config.json
:{ "mcpServers": { "mysql": { "command": "npx", "args": ["@lakshya-mcp/mysql-mcp-server-copilot"], "env": { "DB_HOST": "localhost", "DB_PORT": "3306", "DB_USER": "your_username", "DB_PASSWORD": "your_password", "DB_NAME": "your_database", "DB_SSL": "true", "ENABLE_CREATE": "false", "LOG_LEVEL": "info" } } } }
-
Restart VS Code and start asking Copilot about your database!
2. Claude Desktop
For Claude Desktop users:
-
Install the package:
npm install -g @lakshya-mcp/mysql-mcp-server-copilot
-
Add to Claude Desktop config (
claude_desktop_config.json
):{ "mcpServers": { "mysql": { "command": "npx", "args": ["@lakshya-mcp/mysql-mcp-server-copilot"], "env": { "DB_HOST": "localhost", "DB_PORT": "3306", "DB_USER": "your_username", "DB_PASSWORD": "your_password", "DB_NAME": "your_database" } } } }
-
Restart Claude Desktop to load the MCP server
3. Manual/Any MCP Client
For any MCP-compatible client:
-
Install globally or locally:
# Global installation npm install -g @lakshya-mcp/mysql-mcp-server-copilot # Local installation npm install @lakshya-mcp/mysql-mcp-server-copilot
-
Run directly:
npx @lakshya-mcp/mysql-mcp-server-copilot
-
Configure your MCP client to connect to the server using stdio transport
4. Programmatic Usage (NPM)
For programmatic integration in your Node.js applications:
npm install @lakshya-mcp/mysql-mcp-server-copilot
import { MySQLMCPServer } from "@lakshya-mcp/mysql-mcp-server-copilot";
const server = new MySQLMCPServer({
host: "localhost",
port: 3306,
user: "username",
password: "password",
database: "mydb",
features: {
create: false,
update: false,
delete: false,
schema: false,
},
});
await server.start();
5. Local Development
To run from the local repository:
-
Clone the repository:
git clone https://github.com/your-username/mysql-mcp-server-copilot.git cd mysql-mcp-server-copilot
-
Install dependencies:
npm install
-
Build the project:
npm run build
-
Set up environment:
cp .env.example .env # Edit .env with your database credentials
-
Run locally:
npm start
-
For development with auto-rebuild:
npm run dev
Configuration
Create a .env
file or set environment variables:
# Database Configuration (Required)
DB_HOST=localhost
DB_PORT=3306
DB_USER=your_username
DB_PASSWORD=your_password
DB_NAME=your_database
# Security Configuration
DB_SSL=true
DB_CONNECTION_LIMIT=10
DB_TIMEOUT=30000
# Feature Configuration (Optional - defaults to false except fetch)
ENABLE_CREATE=false
ENABLE_UPDATE=false
ENABLE_DELETE=false
ENABLE_SCHEMA_OPERATIONS=false
# Logging Configuration
LOG_LEVEL=info
LOG_FILE=./logs/mysql-mcp-server.log
VS Code GitHub Copilot Integration
Add to your MCP settings (mcp-config.json
):
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["@lakshya-mcp/mysql-mcp-server-copilot"],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "3306",
"DB_USER": "your_username",
"DB_PASSWORD": "your_password",
"DB_NAME": "your_database",
"ENABLE_CREATE": "false",
"LOG_LEVEL": "info"
}
}
}
}
Usage Examples
Ask GitHub Copilot natural language questions:
- Basic Queries: "Show me all users from the database", "What's the structure of the users table?"
- Data Analysis: "Show me the top 10 customers by order value", "What's the average age of our users?"
- Schema Exploration: "Describe the structure of the orders table", "What are all the tables in this database?"
Security Best Practices
-
Use Read-Only by Default:
ENABLE_CREATE=false ENABLE_UPDATE=false ENABLE_DELETE=false ENABLE_SCHEMA_OPERATIONS=false
-
Create Dedicated Database User:
-- Read-only user CREATE USER 'copilot_readonly'@'%' IDENTIFIED BY 'secure_password'; GRANT SELECT ON your_database.* TO 'copilot_readonly'@'%'; FLUSH PRIVILEGES;
-
Enable SSL/TLS:
DB_SSL=true DB_CONNECTION_LIMIT=5
Programmatically:
import { MySQLMCPServer } from "@lakshya-mcp/mysql-mcp-server-copilot";
const server = new MySQLMCPServer({
host: "localhost",
port: 3306,
user: "username",
password: "password",
database: "mydb",
features: {
create: false,
update: false,
delete: false,
schema: false,
},
});
await server.start();
Available Tools
Always Available:
mysql_query
- Execute SELECT queries safelymysql_describe_table
- Get table structuremysql_list_tables
- List all tables in databasemysql_show_databases
- List available databases
Configurable Tools:
mysql_insert
- Insert data (requires ENABLE_CREATE=true)mysql_update
- Update data (requires ENABLE_UPDATE=true)mysql_delete
- Delete data (requires ENABLE_DELETE=true)mysql_create_table
- Create tables (requires ENABLE_SCHEMA_OPERATIONS=true)mysql_drop_table
- Drop tables (requires ENABLE_SCHEMA_OPERATIONS=true)
Security Features
- SQL injection prevention through parameterized queries
- Input validation using Joi schemas
- Connection pooling with limits
- SSL/TLS support
- Query timeout protection
- Feature-based access control
Troubleshooting
Connection Issues
-
Check MySQL Server Status:
# Windows Get-Service MySQL* # Linux systemctl status mysql # macOS brew services list mysql
-
Verify Credentials:
mysql -h localhost -u your_username -p your_database
-
Check Firewall: Ensure port 3306 is accessible
Permission Issues
-
Check User Permissions:
SHOW GRANTS FOR 'your_username'@'%';
-
Verify Database Access:
USE your_database; SHOW TABLES;
Debug Mode
Enable detailed logging:
LOG_LEVEL=debug
Check logs:
tail -f logs/mysql-mcp-server.log
Advanced Configuration
Multiple Database Connections
Configure separate instances for different databases:
{
"mcpServers": {
"mysql-production": {
"command": "npx",
"args": ["@lakshya-mcp/mysql-mcp-server-copilot"],
"env": {
"DB_HOST": "prod-server",
"DB_NAME": "production_db",
"ENABLE_CREATE": "false"
}
},
"mysql-development": {
"command": "npx",
"args": ["@lakshya-mcp/mysql-mcp-server-copilot"],
"env": {
"DB_HOST": "localhost",
"DB_NAME": "dev_db",
"ENABLE_CREATE": "true"
}
}
}
}
Environment-Specific Settings
Development:
DB_SSL=false
ENABLE_CREATE=true
ENABLE_UPDATE=true
ENABLE_DELETE=true
ENABLE_SCHEMA_OPERATIONS=true
LOG_LEVEL=debug
Production:
DB_SSL=true
ENABLE_CREATE=false
ENABLE_UPDATE=false
ENABLE_DELETE=false
ENABLE_SCHEMA_OPERATIONS=false
LOG_LEVEL=info
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
MIT License - see LICENSE file for details.