MySQL MCP Server
Enables GitHub Copilot to interact with MySQL databases through the MCP server, allowing developers to perform database operations via natural language prompts in VS Code.
Provides tools for interacting with MySQL databases, including executing SQL queries, listing databases and tables, describing table structures, and performing administrative tasks like killing queries and optimizing tables.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MySQL MCP Serverlist all tables in the database"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MySQL MCP Server
A secure and professional MySQL Model Context Protocol (MCP) server with clean architecture, designed for seamless integration with GitHub Copilot, Cline, and other AI coding assistants in VS Code.
Features
Clean Architecture: Follows Single Responsibility Principle for maintainability and scalability
Security First: Built-in permission system, audit logging, and query validation
Connection Pooling: Efficient MySQL connection management with connection pooling
Schema Inspection: Tools for exploring database structure
Query Execution: Secure SQL query execution with timeout controls
Audit Logging: Comprehensive logging of all database operations
Quick Start
Installation
npm installConfiguration
Copy the example configuration and update credentials:
cp .env.example .envThen edit .env in the project root:
# MySQL Connection
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=your_username
MYSQL_PASSWORD=your_password
MYSQL_DATABASE=your_database
# Security Settings
SECURITY_ENABLED=true
ALLOWED_OPERATIONS=SELECT,SHOW,DESCRIBE,EXPLAIN
MAX_QUERY_EXECUTION_TIME=30000
# Audit Settings
AUDIT_ENABLED=true
AUDIT_LOG_LEVEL=infoBuild
npm run buildRun
npm startIntegration with VS Code
GitHub Copilot
Recommended for this repository: use the workspace MCP file at .vscode/mcp.json.
It is already included in this project and should look like:
{
"servers": {
"mysql-local": {
"type": "stdio",
"command": "node",
"args": ["${workspaceFolder}/dist/index.js"],
"env": {
"MYSQL_HOST": "${env:MYSQL_HOST}",
"MYSQL_PORT": "${env:MYSQL_PORT}",
"MYSQL_USER": "${env:MYSQL_USER}",
"MYSQL_PASSWORD": "${env:MYSQL_PASSWORD}",
"MYSQL_DATABASE": "${env:MYSQL_DATABASE}"
}
}
}
}Alternative: add to VS Code user settings (settings.json):
{
"mcpServers": {
"mysql": {
"command": "node",
"args": ["/path/to/mysql-mcp/dist/index.js"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_username",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database"
}
}
}
}Cline
Configure in Cline settings:
{
"mcpServers": {
"mysql": {
"command": "node",
"args": ["/path/to/mysql-mcp/dist/index.js"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_USER": "your_username",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database"
}
}
}
}Available Tools
Query Tools
execute_query
Execute SQL queries against the database.
Parameters:
sql(required): SQL query to executedatabase(optional): Database nameuserId(optional): User ID for permission checkingtimeout(optional): Query timeout in milliseconds
Schema Tools
list_databases
List all available databases.
Parameters:
userId(optional): User ID for permission checking
list_tables
List all tables in a database.
Parameters:
database(optional): Database nameuserId(optional): User ID for permission checking
describe_table
Get the structure of a table.
Parameters:
table(required): Table namedatabase(optional): Database nameuserId(optional): User ID for permission checking
Admin Tools
get_server_status
Get MySQL server status variables.
Parameters:
userId(optional): User ID for permission checking
get_process_list
Get list of running MySQL processes.
Parameters:
userId(optional): User ID for permission checking
kill_query
Kill a running MySQL process.
Parameters:
processId(required): Process ID to killuserId(optional): User ID for permission checking
get_table_indexes
Get index information for a table.
Parameters:
table(required): Table namedatabase(optional): Database nameuserId(optional): User ID for permission checking
get_table_constraints
Get constraint information for a table.
Parameters:
table(required): Table namedatabase(optional): Database nameuserId(optional): User ID for permission checking
analyze_table
Analyze table statistics.
Parameters:
table(required): Table namedatabase(optional): Database nameuserId(optional): User ID for permission checking
optimize_table
Optimize a table.
Parameters:
table(required): Table namedatabase(optional): Database nameuserId(optional): User ID for permission checking
RBAC Tools
All RBAC tools require authentication and API key permission rbac_admin.
Role and Permission Management
create_role(name, desc)delete_role(id)list_roles()create_permission(name, desc)list_permissions()assign_permission_to_role(roleId, permId)revoke_permission_from_role(roleId, permId)
User Role Assignment
assign_role_to_user(userId, roleId)revoke_role_from_user(userId, roleId)list_user_roles(userId)
Authorization Checks
check_user_permission(userId, permissionName)current_user_permissions()can_access(userId, resource, action, attributes?)
RBAC Audit
audit_log(event, actor, target, details)query_audit_logs(filter)
RBAC Database Operations
db_migrate_rbac()db_seed_rbac_defaults()db_check_integrity()
Available Resources
mysql://status
Current database connection status and pool information.
mysql://config
Server configuration (sanitized, no sensitive data).
mysql://audit/statistics
Statistics about database operations.
mysql://audit/logs
Recent database operation logs.
Architecture
src/
├── config/ # Configuration management
├── mysql/ # MySQL connection management
├── security/ # Permission and audit logging
├── tools/ # MCP tools implementation
├── resources/ # MCP resources
├── types/ # TypeScript type definitions
└── index.ts # Main entry pointKey Components
ConfigManager: Handles configuration loading and validation
MySQLConnectionManager: Manages connection pooling and query execution
PermissionManager: Handles permission checking and access control
AuditLogger: Logs all database operations for security
QueryTool: Executes SQL queries with security validation
SchemaTool: Inspects database schema
DatabaseResource: Provides MCP resources
Security
Permission-based access control
Query timeout enforcement
Operation whitelisting/blacklisting
Audit logging of all operations
Rate limiting support
See docs/security.md for detailed security documentation.
Documentation
Development
# Install dependencies
npm install
# Run in development mode
npm run dev
# Build
npm run build
# Lint
npm run lint
# Format
npm run formatRequirements
Node.js >= 18.0.0
MySQL 5.7+ or MariaDB 10.3+
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please read our contributing guidelines before submitting pull requests.
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/az-coder-123/mysql-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server