MySQL MCP server

Connects to MySQL databases to enable querying, analyzing, and manipulating data directly within conversation interfaces through a containerized Python server.
Back to servers
Setup instructions
Provider
iamiks
Release date
Mar 18, 2025
Language
Python
Stats
27 stars

This MySQL Model Context Protocol (MCP) server provides a robust interface between AI models and MySQL databases, enabling various database operations through a standardized protocol.

Installation Options

Using Docker

Run the MCP server with a single Docker command:

docker run -d --name mcp-mysql \
  -e MYSQL_HOST=localhost \
  -e MYSQL_PORT=3306 \
  -e MYSQL_USER=root \
  -e MYSQL_PASSWORD=mcpTest1234!!! \
  -e MYSQL_DATABASE=mcp_test \
  -e MCP_PORT=8081 \
  -p 3306:3306 mineru/mcp-mysql:1.0.0

Make sure to adjust the database connection information according to your environment.

Using Docker Compose

For a pre-configured setup, simply use Docker Compose:

docker-compose up -d

Using Python Directly

If you prefer to run without Docker:

pip install -r requirements.txt
python mysql_mcp_server/main.py run

Configuration

Cursor Setup

MCP functionality requires:

  • Cursor version 0.46 or above
  • Cursor Pro account

To configure Cursor, navigate to settings and enable the MCP feature as shown in the documentation.

Available Tools

The MCP server provides several tools for interacting with MySQL:

  • Create Table: Create new tables in the database
  • Describe Table: View table schema information
  • Explain Query: Analyze query execution plans
  • Insert Data: Execute INSERT queries
  • Generate Reports: Check schema for building data reports
  • Visualization Recommendations: Get chart visualization suggestions
  • Run Queries: Execute SELECT queries
  • Show Tables: List all tables in the database

Usage Flow

The typical interaction flow works as follows:

  1. AI model requests available tools from the MCP server
  2. MCP server returns the tool list
  3. AI model requests execution of a specific tool
  4. Server calls the corresponding executor
  5. Database operation is performed
  6. Results are returned to the AI model

Environment Variables

Set these environment variables to configure the server:

  • MYSQL_HOST: MySQL server hostname
  • MYSQL_PORT: MySQL server port (default: 3306)
  • MYSQL_USER: MySQL username
  • MYSQL_PASSWORD: MySQL password
  • MYSQL_DATABASE: Database name
  • MCP_PORT: Port for the MCP server (default: 8081)

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "mysql-mcp-server" '{"command":"python","args":["mysql_mcp_server/main.py","run"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "mysql-mcp-server": {
            "command": "python",
            "args": [
                "mysql_mcp_server/main.py",
                "run"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "mysql-mcp-server": {
            "command": "python",
            "args": [
                "mysql_mcp_server/main.py",
                "run"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later