Manages configuration through environment variables for database credentials, security settings, and optional integrations
Offers optional OAuth authentication integration for securing access to the MCP server
Enables secure database access with comprehensive operations including queries, table management, data modification, and transaction handling
Provides optional error tracking and monitoring capabilities for production deployments
MySQL MCP Server Documentation
Overview
This is a production-ready MySQL MCP (Model Context Protocol) server that provides secure database access through MCP tools. The server includes authentication, monitoring, and comprehensive database operations.
Quick Start
Prerequisites
- Python 3.8+
- MySQL database server
- Claude Desktop application
- Git
Installation
- Clone and navigate to the project:
- Install dependencies:
- Set up environment variables (create
.env
file):
Running the Server
Primary method:
Alternative methods:
Claude Desktop Integration
MCP Configuration for Claude Desktop
Add this configuration to your Claude Desktop MCP settings file. The configuration file is typically located at:
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Linux: ~/.config/Claude/claude_desktop_config.json
Setup Steps for Claude Desktop
- Install the MCP server (follow installation steps above)
- Locate your Claude Desktop config file using the paths above
- Add the MCP configuration to the config file
- Update the
cwd
path to match your actual installation directory - Set up environment variables in a
.env
file in your project directory - Restart Claude Desktop to load the new MCP server
- Verify connection by asking Claude to list database tables
Configuration Notes
- Replace
your_username
,your_password
, etc. with your actual database credentials - Update the
cwd
path to match your actual installation directory - Ensure Python is available in your system PATH
- The server will be available as "mysql-mcp" in Claude Desktop
Testing Claude Integration
Once configured, you can test the integration by asking Claude:
- "List all tables in my database"
- "Show me the structure of the users table"
- "Query the first 5 rows from my products table"
Project Structure
Available MCP Tools
Basic Operations
mysql-mcp:query_database
- Execute SELECT queriesmysql-mcp:list_tables
- List all database tablesmysql-mcp:describe_table
- Get table schema information
Write Operations
mysql-mcp:execute_sql
- Execute INSERT, UPDATE, DELETE operationsmysql-mcp:create_table
- Create new tables
Advanced Features
- Transaction management
- Query optimization
- Performance monitoring
- Security validation
Configuration
Environment Variables
Variable | Description | Required | Default |
---|---|---|---|
MYSQL_HOST | MySQL server host | Yes | localhost |
MYSQL_PORT | MySQL server port | No | 3306 |
MYSQL_USER | Database username | Yes | - |
MYSQL_PASSWORD | Database password | Yes | - |
MYSQL_DATABASE | Database name | Yes | - |
SECRET_KEY | Security secret key | Yes | - |
ALLOWED_OPERATIONS | Permitted SQL operations | No | SELECT,INSERT,UPDATE,DELETE |
MAX_CONNECTIONS | Connection pool size | No | 10 |
QUERY_TIMEOUT | Query timeout (seconds) | No | 30 |
Security Features
- SQL injection prevention
- Query validation and sanitization
- Operation restrictions
- Connection pooling with limits
- Session-based authentication
- Optional GitHub OAuth integration
Usage Examples
Basic Query
Table Operations
Data Modification
Testing
Run the test suite:
Docker Deployment
Use the provided Docker setup:
Monitoring and Debugging
Logging
The server includes structured logging with different levels:
- INFO: General operations
- WARNING: Potential issues
- ERROR: Operation failures
- DEBUG: Detailed debugging info
Sentry Integration
Configure Sentry for error tracking:
Debug Mode
Enable debug mode in debug_settings.py
:
Troubleshooting
Common Issues
- Connection Errors
- Verify MySQL server is running
- Check credentials in
.env
file - Ensure network connectivity
- Permission Errors
- Verify database user permissions
- Check
ALLOWED_OPERATIONS
configuration
- Performance Issues
- Monitor connection pool usage
- Check query execution times
- Review database indexes
Debug Commands
Development
Code Style
The project uses:
- Black for code formatting
- Ruff for linting
- MyPy for type checking
Adding New Tools
- Create tool function in appropriate module
- Register in
src/tools/register_tools.py
- Add tests in
tests/
- Update documentation
Production Deployment
See DEPLOYMENT.md
for detailed production deployment instructions including:
- Environment setup
- Security hardening
- Performance optimization
- Monitoring configuration
Security Considerations
- Always use parameterized queries
- Implement proper authentication
- Regularly update dependencies
- Monitor for suspicious activity
- Use SSL/TLS for connections
- Implement rate limiting
Support
For issues and questions:
- Check the troubleshooting section
- Review logs for error details
- Consult the existing README.md and DEPLOYMENT.md files
- Check the test files for usage examples
This server cannot be installed
A comprehensive Model Context Protocol server that enables AI assistants to interact with MySQL databases through secure, role-based database operations.
Related MCP Servers
- -securityAlicense-qualityA 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 -963MIT License
- 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
- -securityFlicense-qualityA Model Context Protocol server that enables AI models to interact with MySQL databases through natural language, supporting SQL queries, table creation, and schema exploration.Last updated -3Python
- AsecurityFlicenseAqualityA Model Context Protocol server that allows AI agents to execute SQL queries against a MySQL database, supporting operations like reading data, creating tables, inserting, updating, and deleting records.Last updated -67792JavaScript