Uses .ENV files for configuration management, enabling users to define database connections, security levels, and server settings with support for hot reloading configuration changes.
Supports Git for installation and version control of the server, with the README providing Git clone instructions as part of the setup process.
Provides secure, multi-database MySQL access with configurable security levels, allowing users to execute SQL queries, describe table structures, and browse schemas through VS Code's resource explorer.
Integrates with npm for package management and script execution, with installation and startup procedures using standard npm commands.
MySQL MCP Server
A sophisticated Model Context Protocol (MCP) server that provides secure, multi-database MySQL access with configurable security levels, lazy loading, and hot reload capabilities.
🚀 Features
- 🗄️ Multi-Database Support: Configure and access multiple MySQL databases simultaneously
- 🔒 Configurable Security: Four security levels from read-only to full access
- ⚡ Lazy Loading: Connection pools created only when needed for optimal resource usage
- 🔄 Hot Reload: Database configuration updates without server restart
- 📊 Complete Schema Information: Full table definitions with indexes, foreign keys, and constraints
- 🛡️ Explicit Database Selection: Required database parameter prevents accidental operations
- 🎯 MCP Protocol Integration: Native VS Code integration with resource browsing
🔧 Installation
- Clone and Install
- Configure Multi-Database SetupCopy the example configuration file and customize it:Edit
.env
with your database configurations: - Add to VS Code MCP ConfigurationAdd to your VS Code
settings.json
under MCP servers:
🔒 Security Levels
Configure MYSQL_ALLOWED_COMMANDS
in your .env
file:
Default (Recommended)
Allowed Commands: SELECT
, SHOW
, DESCRIBE
, DESC
, EXPLAIN
, ANALYZE
Use Case: Safe read-only access for data analysis and exploration
Extended
Allowed Commands: All default commands plus CREATE TABLE
, ALTER TABLE
, DROP TABLE
, INSERT
, UPDATE
, DELETE
, TRUNCATE
, etc.
Use Case: Development environments where schema and data modifications are needed
All (⚠️ Use with Extreme Caution)
Allowed Commands: No restrictions - all SQL commands permitted
Use Case: Trusted environments requiring full database administration capabilities
Custom
Allowed Commands: User-defined comma-separated list
Use Case: Specific operational requirements with tailored permissions
🛠️ Available Tools
All tools require explicit database selection for security.
query_database
Execute SQL queries with security validation and explicit database selection.
- Parameters:
sql
(string, required) - The SQL query to executedatabase
(string, required) - Database name to target (security requirement)
- Security: Commands validated against current security level
- Returns: Query results with execution metadata
describe_table
Get complete table structure using SHOW CREATE TABLE
for comprehensive schema information.
- Parameters:
table_name
(string, required) - Name of the table to describedatabase
(string, required) - Database containing the table (security requirement)
- Returns: Full table definition including columns, indexes, foreign keys, and engine details
list_databases
Display all configured databases and their connection status.
- Parameters: None required
- Returns: Database configurations with connection pool status and default database indicator
📚 Available Resources
Tables from the default database are exposed as MCP resources with URIs like:
Browse table schemas directly through VS Code's resource explorer.
💡 Usage Examples
Basic Database Query
Database: primary_db
Multi-Database Operations
Database: analytics_db
Table Schema Exploration
Use describe_table
tool:
- Table:
users
- Database:
primary_db
Returns complete table definition with foreign keys, indexes, and constraints.
Database Discovery
Use list_databases
tool to see all configured databases and their connection status:
🔄 Hot Reload Feature
Update database configurations in .env
file - they'll be automatically reloaded:
- ✅ Credential updates: New passwords/users applied immediately
- ✅ New databases: Added to available list (restart VS Code to update tool schemas)
- ✅ Configuration changes: Host/port updates applied on next connection
- 🔄 Existing connections: Remain active until naturally recycled
⚡ Lazy Loading
Connection pools are created only when needed:
- 📊 Resource efficient: No unnecessary database connections
- 🚀 Fast startup: Server starts immediately regardless of database availability
- 🔍 Status visibility:
list_databases
shows which pools are active - 🛡️ Failure isolation: One database issue doesn't affect others
🏗️ Architecture
Key design principles:
- Multi-Database: Each database has independent configuration and connection pool
- Security: Command validation before execution, explicit database selection required
- Performance: Lazy loading + connection pooling for optimal resource usage
- Reliability: Hot reload + error isolation for production stability
🚀 Development
Running the Server
Testing Configuration
Environment Variables
MYSQL_DATABASES
: JSON array of database configurationsMYSQL_ALLOWED_COMMANDS
: Security level (default/extended/all/custom)MYSQL_CONNECTION_LIMIT
: Max connections per pool (default: 4)MYSQL_WAIT_FOR_CONNECTIONS
: Wait for available connections (default: true)
📄 License
MIT License - see LICENSE file for details.
Built with ❤️ for the Model Context Protocol ecosystem
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
A Model Context Protocol server that provides secure, multi-database MySQL access with configurable security levels, enabling SQL queries across multiple databases directly from VS Code.
Related MCP Servers
- -securityFlicense-qualityA Model Context Protocol server that enables SQL query execution, database management, and business intelligence capabilities through MySQL connections.Last updated -JavaScript
- AsecurityAlicenseAqualityA Model Context Protocol server that enables AI models to interact with MySQL databases, providing tools for querying, executing statements, listing tables, and describing table structures.Last updated -5745MIT License
- -securityFlicense-qualityA Model Context Protocol server that provides tools for connecting to and interacting with various database systems (SQLite, PostgreSQL, MySQL/MariaDB, SQL Server) through a unified interface.Last updated -3Python
- AsecurityFlicenseAqualityA Model Context Protocol server that enables AI models to interact with MySQL databases through a standardized interface, providing tools for querying, executing commands, and managing database schemas.Last updated -7JavaScript