MySQL MCP Server
Provides tools for interacting with MySQL databases, including CRUD operations, DDL, schema inspection, arbitrary query execution/explain/analyze/validate, administration, optimization, and backup/restore.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
MySQL MCP Server
A comprehensive Model Context Protocol (MCP) server for MySQL databases with Langchain integration. This server provides 40+ tools for database operations, schema management, query optimization, and administration.
Author: Ayush Singh
Features
Comprehensive Tool Set: 40+ tools covering all MySQL operations
Langchain Compatible: Tools can be used with Langchain agents
Security First: Built-in SQL injection prevention and access control
Performance Optimized: Connection pooling, query caching, result streaming
Production Ready: Error handling, logging, monitoring
Easy Integration: Simple configuration for Claude Desktop, Claude Code, Cursor
Extensible: Modular design for easy extension
Related MCP server: MySQL MCP Server
Installation
Prerequisites
Python 3.10 or higher
MySQL 5.7 or higher (MySQL 8.0+ recommended)
MySQL user with appropriate permissions
Option 1: Docker (recommended for production)
Pull the image from Docker Hub and run with your .env:
docker pull ayush1184docker/mysql-mcp-server:latest
docker run --rm -i --env-file /path/to/your/.env ayush1184docker/mysql-mcp-server:latestSee DOCKER.md for build, push, and Cursor integration details.
Option 2: Install from source
pip install -r requirements.txtOr using pip:
pip install mcp aiomysql pymysql sqlalchemy langchain langchain-community pydantic python-dotenvConfiguration
Environment Variables
Create a .env file in the project root or set environment variables:
# MySQL Connection Settings
MYSQL_HOST=127.0.0.1
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=your_password
MYSQL_DATABASE=your_database
# Optional: Path to .env file (for per-project configurations)
# MYSQL_ENV_FILE=/path/to/custom/.env
# Connection Pool Settings
MYSQL_POOL_SIZE=10
MYSQL_MAX_CONNECTIONS=100
MYSQL_QUERY_TIMEOUT=30
# SSL/TLS Settings
MYSQL_SSL_ENABLED=false
MYSQL_SSL_CA=
MYSQL_SSL_CERT=
MYSQL_SSL_KEY=
# Security Settings
MYSQL_READ_ONLY=false
MYSQL_ALLOW_DDL=false
MYSQL_ALLOW_DELETE=false
MYSQL_RATE_LIMIT=100
# Logging Settings
MYSQL_LOG_QUERIES=false
MYSQL_LOG_LEVEL=INFOConfiguration Reference
Variable | Description | Default |
| Path to | (none, loads from CWD) |
| MySQL server host |
|
| MySQL server port |
|
| MySQL username |
|
| MySQL password | (empty) |
| Default database name | (none) |
| Full connection string (alternative) | (none) |
| Connection pool size |
|
| Maximum connections |
|
| Query timeout in seconds |
|
| Enable SSL/TLS |
|
| Read-only mode |
|
| Allow DDL operations |
|
| Allow DELETE operations |
|
| Queries per minute |
|
| Log all queries |
|
| Logging level |
|
Usage
Running the Server
python -m src.serverOr using the entry point:
mysql-mcp-serverClaude Desktop Configuration
Add to your claude_desktop_config.json (usually located at ~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"mysql": {
"command": "python",
"args": ["-m", "src.server"],
"env": {
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database"
}
}
}
}Claude Code Configuration
Add to your Claude Code MCP configuration:
{
"mcpServers": {
"mysql": {
"command": "python",
"args": ["-m", "src.server"],
"env": {
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database"
}
}
}
}Cursor Configuration
Add to your Cursor MCP configuration:
{
"mcpServers": {
"mysql": {
"command": "python",
"args": ["-m", "src.server"],
"env": {
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database"
}
}
}
}Per-Project Database Configuration
For per-project database configurations, use project-scoped .cursor/mcp.json files. See the Quick Start Guide for details.
Available Tools
CRUD Operations
mysql_insert- Insert a single row into a tablemysql_select- Select data from a table with filtering and sortingmysql_update- Update rows in a tablemysql_delete- Delete rows from a tablemysql_upsert- Insert or update a row (upsert operation)
DDL Operations
mysql_create_table- Create a new tablemysql_alter_table- Alter table structuremysql_drop_table- Drop a tablemysql_create_index- Create an indexmysql_drop_index- Drop an indexmysql_create_database- Create a databasemysql_drop_database- Drop a databasemysql_create_view- Create a viewmysql_create_procedure- Create a stored proceduremysql_create_function- Create a stored functionmysql_create_trigger- Create a trigger
Query Tools
mysql_execute_query- Execute an arbitrary SQL querymysql_explain_query- Explain query execution planmysql_analyze_query- Analyze query performancemysql_validate_query- Validate SQL query syntax and permissions
Schema Tools
mysql_list_databases- List all databasesmysql_list_tables- List tables in a databasemysql_describe_table- Get detailed table structuremysql_get_table_schema- Get complete table schemamysql_list_columns- List columns in a tablemysql_list_indexes- List indexes on a tablemysql_list_foreign_keys- List foreign key relationshipsmysql_get_table_stats- Get table statistics
Administration Tools
mysql_show_processes- Show running processes or kill a processmysql_show_variables- Show MySQL server variablesmysql_show_status- Show MySQL server statusmysql_flush_tables- Flush tablesmysql_optimize_table- Optimize a tablemysql_analyze_table- Analyze a tablemysql_repair_table- Repair a corrupted tablemysql_backup_table- Backup table datamysql_restore_table- Restore table data from backup
Optimization Tools
mysql_suggest_indexes- Suggest indexes for queriesmysql_analyze_slow_queries- Analyze slow query logmysql_get_query_stats- Get query statistics
Langchain Integration
Using with Langchain Agents
from langchain.agents import initialize_agent, AgentType
from langchain.llms import OpenAI
from src.langchain.adapters import create_langchain_tools
# Initialize LLM
llm = OpenAI(temperature=0)
# Get MySQL tools from MCP server
mysql_tools = create_langchain_tools()
# Create agent with MySQL tools
agent = initialize_agent(
tools=mysql_tools,
llm=llm,
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
verbose=True,
)
# Use the agent
response = agent.run("List all tables in the database")Using with Langchain SQL Agent
from langchain.llms import OpenAI
from src.langchain.sql_agent import create_mysql_agent
# Initialize LLM
llm = OpenAI(temperature=0)
# Create MySQL SQL agent
agent = create_mysql_agent(
llm=llm,
database="your_database",
verbose=True,
)
# Use the agent
response = agent.run("How many users are in the database?")Security Features
SQL Injection Prevention
All queries use parameterized statements to prevent SQL injection attacks. The server validates queries before execution and checks for dangerous patterns.
Permission System
Read-only mode: Prevents all write operations when enabled
DDL restrictions: Control creation/modification of database structures
DELETE restrictions: Control deletion operations
Rate limiting: Limit queries per minute
Query Validation
Syntax validation
Permission checking
SQL injection detection
Complexity analysis
Examples
See the examples/ directory for:
Claude Desktop configuration
Claude Code configuration
Cursor configuration
Langchain integration examples
Troubleshooting
Connection Issues
Verify MySQL server is running and accessible
Check credentials and permissions
Ensure SSL/TLS configuration is correct if enabled
Try connecting with a MySQL client to confirm access
Permission Errors
Review rate limiting configuration
Check query whitelist/blacklist settings
Verify SSL/TLS settings
Ensure the user has appropriate MySQL permissions
Performance Issues
Adjust connection pool size
Configure query timeout values
Enable query caching if needed
Check query complexity settings
Monitor server resource usage
Publishing to Docker Hub
To build and push the image as Ayush Singh (or your Docker Hub username):
docker build -t ayush1184docker/mysql-mcp-server:1.0.0 .
docker tag ayush1184docker/mysql-mcp-server:1.0.0 ayush1184docker/mysql-mcp-server:latest
docker login
docker push ayush1184docker/mysql-mcp-server:latest
docker push ayush1184docker/mysql-mcp-server:1.0.0See DOCKER.md for full details.
Development
Project Structure
mysql-mcp-server/
├── src/
│ ├── database/ # Database connection and query execution
│ ├── tools/ # MCP tool implementations
│ ├── langchain/ # Langchain integration
│ ├── security/ # Security validators and permissions
│ └── utils/ # Configuration and logging
├── tests/ # Test suite
├── examples/ # Configuration examples
└── README.md # This fileRunning Tests
pytest tests/Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License. See LICENSE for details.
Copyright (c) 2025 Ayush Singh.
Acknowledgments
Built with FastMCP
Inspired by benborla/mcp-server-mysql
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
The agent-native cloud: database, functions, AI, storage, computers. 53 tools. OAuth or API key.
PostgreSQL, MySQL, OpenAPI/Swagger, and shared Agent Memory with scoped access.
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Related MCP Servers
- AlicenseBqualityDmaintenanceEnables AI models to perform MySQL database operations through a standardized interface, supporting secure connections, query execution, and comprehensive schema management.779 npm33MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to securely connect to and manage MySQL databases with support for multiple database connections, complete CRUD operations, schema inspection, and dynamic connection management through natural language.15 npm81MIT
- AlicenseNot gradedqualityNot gradedmaintenanceEnables AI assistants to securely interact with MySQL databases through tools for query execution, schema inspection, and transaction management. It features built-in safety controls like row limits and query validation to ensure safe and standardized database access.546 npm-
- AlicenseNot gradedqualityDmaintenanceEnables secure, runtime-authenticated MySQL database querying and mutation through dynamic tools, allowing AI assistants to list databases/tables, describe schemas, and perform CRUD operations.2MIT