my

mysql_mcp_server

MySQL database integration with configurable access controls, schema inspection, and comprehensive security guidelines

Publishermysql_mcp_server
Submitted date4/13/2025

๐Ÿš€ Unleashing AI-Powered Database Interactions: The MySQL MCP Server

The MySQL MCP Server is a powerful tool designed to bridge the gap between Large Language Model (LLM) applications and MySQL databases, enabling secure and structured data exploration and analysis. Built upon the Model Context Protocol (MCP), this server acts as a crucial intermediary, facilitating communication between AI clients and your database.

โœจ Key Features

  • Resource Discovery: Effortlessly list available MySQL tables as accessible resources for your AI applications.
  • Data Retrieval: Securely read table contents, providing your AI with the context it needs.
  • Controlled Query Execution: Execute SQL queries with robust error handling, ensuring data integrity and stability.
  • Secure Access: Leverage environment variables for secure database credential management, preventing hardcoding and enhancing security.
  • Comprehensive Logging: Gain insights into database interactions with detailed logging, aiding in debugging and security monitoring.

๐Ÿ› ๏ธ Installation

Manual Installation

Install the server using pip:

pip install mysql-mcp-server

Smithery Integration

For seamless integration with Claude Desktop, use Smithery:

npx -y @smithery/cli install mysql-mcp-server --client claude

โš™๏ธ Configuration

Configure the server by setting the following environment variables:

MYSQL_HOST=localhost MYSQL_PORT=3306 # Optional: Defaults to 3306 MYSQL_USER=your_username MYSQL_PASSWORD=your_password MYSQL_DATABASE=your_database

๐Ÿš€ Usage Examples

Claude Desktop Integration

Add the following configuration to your claude_desktop_config.json:

{ "mcpServers": { "mysql": { "command": "uv", "args": [ "--directory", "path/to/mysql_mcp_server", "run", "mysql_mcp_server" ], "env": { "MYSQL_HOST": "localhost", "MYSQL_PORT": "3306", "MYSQL_USER": "your_username", "MYSQL_PASSWORD": "your_password", "MYSQL_DATABASE": "your_database" } } } }

Visual Studio Code Integration

Configure the server in your mcp.json file:

{ "servers": { "mysql": { "type": "stdio", "command": "uvx", "args": [ "--from", "mysql-mcp-server", "mysql_mcp_server" ], "env": { "MYSQL_HOST": "localhost", "MYSQL_PORT": "3306", "MYSQL_USER": "your_username", "MYSQL_PASSWORD": "your_password", "MYSQL_DATABASE": "your_database" } } }

Note: Ensure you have uv installed for this to work.

Debugging with MCP Inspector

While the MySQL MCP Server is designed for integration with AI applications, you can use the MCP Inspector for debugging purposes:

# Install dependencies pip install -r requirements.txt # Use the MCP Inspector for debugging (do not run directly with Python)

๐Ÿ’ป Development

Contribute to the project by following these steps:

# Clone the repository git clone https://github.com/yourusername/mysql_mcp_server.git cd mysql_mcp_server # Create virtual environment python -m venv venv source venv/bin/activate # or `venv\Scripts\activate` on Windows # Install development dependencies pip install -r requirements-dev.txt # Run tests pytest

๐Ÿ›ก๏ธ Security Considerations

  • Credential Management: Never commit credentials or environment variables to your repository.
  • Principle of Least Privilege: Use a dedicated database user with minimal required permissions.
  • Query Whitelisting: Implement query whitelisting for production environments to prevent SQL injection attacks.
  • Monitoring and Logging: Monitor and log all database operations for auditing and security analysis.

๐Ÿ”’ Security Best Practices

  1. Dedicated User: Create a dedicated MySQL user with minimal permissions.
  2. Avoid Root: Never use root credentials or administrative accounts.
  3. Restrict Access: Limit database access to only necessary operations.
  4. Enable Logging: Enable logging for audit purposes.
  5. Regular Reviews: Conduct regular security reviews of database access.

Refer to the MySQL Security Configuration Guide for detailed instructions on securing your MySQL database.

โš ๏ธ Important: Always adhere to the principle of least privilege when configuring database access.

๐Ÿค Contributing

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/amazing-feature).
  3. Commit your changes (git commit -m 'Add some amazing feature').
  4. Push to the branch (git push origin feature/amazing-feature).
  5. Open a Pull Request.

Visit More

View All