Skip to main content

MCP server for querying MySQL databases — let AI agents explore schemas, run queries, and manage data via Model Context Protocol.

Project description

MCP MySQL Server

A Model Context Protocol (MCP) server that connects AI agents (Cursor, Claude Desktop, etc.) to MySQL databases, enabling schema exploration, data querying, and SQL execution through natural language.

Chinese docs: README.zh.md

Features

Tool Description
list_tables List all tables in the database
describe_table View table schema with column types and comments
query Execute read-only queries (SELECT / SHOW / DESCRIBE / EXPLAIN)
execute_sql Execute write operations (INSERT / UPDATE / DELETE / DDL), disabled in read-only mode
get_table_indexes Show all indexes of a table
get_create_table Get the CREATE TABLE statement
get_database_info Get database overview (version, size, table count)

Installation

pip install mcp-mysql-explorer

Usage in Cursor

Open Cursor Settings -> MCP, add a new server. Three ways to configure the database connection:

Option 1: Command-line arguments (recommended)

{
  "mcpServers": {
    "mysql": {
      "command": "mcp-mysql-explorer",
      "args": [
        "--host", "your-mysql-host",
        "--port", "3306",
        "--user", "your-user",
        "--password", "your-password",
        "--database", "your-database"
      ]
    }
  }
}

Enable write mode explicitly:

{
  "mcpServers": {
    "mysql": {
      "command": "mcp-mysql-explorer",
      "args": [
        "--host", "your-mysql-host",
        "--database", "your-database",
        "--allow-write"
      ]
    }
  }
}

Option 2: Environment variables

{
  "mcpServers": {
    "mysql": {
      "command": "mcp-mysql-explorer",
      "env": {
        "MYSQL_HOST": "your-mysql-host",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "your-user",
        "MYSQL_PASSWORD": "your-password",
        "MYSQL_DATABASE": "your-database",
        "MYSQL_READ_ONLY": "true"
      }
    }
  }
}

Option 3: .env file

Create a .env file in the working directory:

MYSQL_HOST=your-mysql-host
MYSQL_PORT=3306
MYSQL_USER=your-user
MYSQL_PASSWORD=your-password
MYSQL_DATABASE=your-database
MYSQL_READ_ONLY=true

Then simply:

{
  "mcpServers": {
    "mysql": {
      "command": "mcp-mysql-explorer"
    }
  }
}

Priority: command-line args > environment variables > .env file

Usage in Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "mysql": {
      "command": "mcp-mysql-explorer",
      "args": [
        "--host", "your-mysql-host",
        "--user", "your-user",
        "--password", "your-password",
        "--database", "your-database"
      ]
    }
  }
}

Run Manually

# With command-line arguments
mcp-mysql-explorer --host localhost --user root --password secret --database mydb

# Explicitly allow write operations
mcp-mysql-explorer --host localhost --user root --password secret --database mydb --allow-write

# With .env file
mcp-mysql-explorer

# As a Python module
python -m mcp_mysql_explorer --host localhost --database mydb

Testing

# Run unit tests (no real database needed)
python scripts/run_tests.py
# Optional manual smoke check (reads credentials from env only)
# Required env: MYSQL_HOST, MYSQL_PORT, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE
python scripts/manual_smoke_check.py --mode both

Security Notes

  • The query tool only allows SELECT / SHOW / DESCRIBE / EXPLAIN statements.
  • Read-only mode is enabled by default (MYSQL_READ_ONLY=true).
  • To enable writes, set MYSQL_READ_ONLY=false or pass --allow-write.
  • The execute_sql tool can run write operations only when read-only mode is disabled.
  • Query results are capped at 1000 rows by default.
  • Table/column identifiers are backtick-wrapped to prevent SQL injection.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_mysql_explorer-0.1.3.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_mysql_explorer-0.1.3-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file mcp_mysql_explorer-0.1.3.tar.gz.

File metadata

  • Download URL: mcp_mysql_explorer-0.1.3.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for mcp_mysql_explorer-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b9fd780a81feda30111557f01085a0263a256cb0e1dd697378ccb8df7fccc681
MD5 918ee535d1d7bffb5a36f1ef349b98cf
BLAKE2b-256 e9a890ed5dc5cd22adc6bcce0bbbdd6ff39150485fe2f8d7ad5b8b18b60513f5

See more details on using hashes here.

File details

Details for the file mcp_mysql_explorer-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_mysql_explorer-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6a6419c3aa8dc0c8e8f3d23dcc55268d827107e8695099d4e8098fedb1cc1c52
MD5 e7b28e6de76c9d3dd797b111e430c3dd
BLAKE2b-256 42036ed8c549ccf5c282347e7fcbbe3b5a773edbab1658c5836488179a396923

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page