mcpField
M
MySQL MCP Server

MySQL MCP Server

Local
github.com/gopikapeenikkalDatabases0Updated 78w ago

About MySQL MCP Server

MySQL MCP Server connects AI models to a MySQL database and exposes a tool for running read-only SQL queries. It is intended for AI applications that need to retrieve database information through natural-language requests.

Key features

  1. 01Runs SQL SELECT queries
  2. 02Accepts query parameters
  3. 03Connects using environment variables

Use cases

  1. 01Retrieve recently registered users
  2. 02Find top-selling products
  3. 03Count orders by customer

MCP support

It exposes a `read_query` tool to MCP clients for executing SQL SELECT queries against a configured MySQL database.

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

No install method listed yet

We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.

Repository

Tools

No tool list yet

Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.

Details

From the project README

MySQL MCP Server

A Model Context Protocol (MCP) server that provides an interface for AI models to interact with MySQL databases through natural language queries.

Overview

This package creates an MCP server that connects to a MySQL database and exposes a tool to execute SQL queries. It allows AI models like Claude to interact with your MySQL database without direct database access.

Prerequisites

  • Python 3.11 or above
  • MySQL database

Installation

You can install the MCP MySQL server using pip:

pip install mcp_mysql_connect

Or using UV:

uv pip install mcp_mysql_connect

Configuration

The server requires the following environment variables:

  • DB_HOST - MySQL server host
  • DB_USER - MySQL username
  • DB_PASSWORD - MySQL password
  • DB_NAME - MySQL database name

You can set these using a .env file or directly in your environment.

Usage Options

1. Using with Cursor

Add the following to your ~/.cursor/mcp.json configuration:

"mysql-mcp-server": {
  "command": "uvx",
  "args": [
    "--from",
    "mcp_mysql_connect",
    "mcp_mysql_connect"
  ],
  "env": {
    "DB_HOST": "your-mysql-host",
    "DB_USER": "your-username",
    "DB_PASSWORD": "your-password",
    "DB_NAME": "your-database"
  }
}

Alternative configuration:

"mysql-mcp-server": {
  "command": "uv",
  "args": [
    "run",
    "--with",
    "mcp_mysql_connect",
    "-m",
    "mcp_mysql_connect"
  ],
  "env": {
    "DB_HOST": "your-mysql-host",
    "DB_USER": "your-username",
    "DB_PASSWORD": "your-password",
    "DB_NAME": "your-database"
  }
}
2. Using with Python Code
from mcp.client import Client
from mcp.tools import Tools

# Connect to the MySQL MCP server
tools = Tools()
tools.add_server("mysql", "mcp_mysql_connect")

# Create a client with the tools
client = Client(tools=tools)

# Example query
response = client.complete(
    messages=[
        {"role": "user", "content": "Query all users from the database"}
    ]
)
print(response.content)
3. Running Manually

Start the server manually:

# Set environment variables first
export DB_HOST=your-mysql-host
export DB_USER=your-username
export DB_PASSWORD=your-password
export DB_NAME=your-database

# Then run the server
python -m mcp_mysql_connect

Available Tools

The server provides a SQL execution tool that can be used to query your MySQL database:

  • read_query(query: str, params: List[str] = None) - Execute a SQL SELECT query against the database

Example Queries

When using with Claude or other AI models, you can ask natural language questions like:

  • "Show me all users who registered in the last week"
  • "What are the top 5 selling products?"
  • "Count how many orders each customer has placed"

The AI model will translate these into SQL queries and use the MCP server to execute them.

License

MIT License

Contributing

Contributions welcome! Please feel free to submit a Pull Request.

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.