Skip to main content

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.

Metadata

Release files for mcp-mysql-connect 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-mysql-connect 1.0.4
File Size Uploaded Provenance
mcp_mysql_connect-1.0.4.tar.gz 5.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mcp-mysql-connect 1.0.4
File Interpreter ABI Platform
mcp_mysql_connect-1.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 11.1 kB

Release files / mcp_mysql_connect-1.0.4.tar.gz

Download URL mcp_mysql_connect-1.0.4.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0a0a35c403e572de98bf4c3bb59d4ce39d119ac18d4f1aae432c8c7dbb5ea500
BLAKE2b-256 checksum
How to use checksums
2c8e0d69c91ab857986b8526f185ec9afbeadba5c61d3d1da8bb2b1eaecb80bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / mcp_mysql_connect-1.0.4-py3-none-any.whl

Download URL mcp_mysql_connect-1.0.4-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a410133918f6ef997a25eea6ee46a595f8653261d21996f5f7027ebbe97ba856
BLAKE2b-256 checksum
How to use checksums
c596eb77c41799568c85ce2ddd01aa64aa84f41951bd7afa7346efc72e2e1e12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Security for mcp-mysql-connect 1.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page