MCP server for MySQL — connect to any MySQL host from Cursor, Claude Code, or any MCP client.
Project description
mysql-mcp-server-ms
PyPI package for this MCP server. The GitHub repo is still mysql-mcp-server; the PyPI project is mysql-mcp-server-ms because mysql-mcp-server was already taken on PyPI.
MCP server for MySQL over stdio. Tools: connect_mysql, disconnect, list_databases, list_tables, describe_table, run_query (read-only SQL only).
Use without cloning (recommended for teams)
After the package is on PyPI (or your private index)
Install uv, then run the server with uvx (no repo checkout):
uvx mysql-mcp-server-ms
Pin a version for reproducible MCP configs:
uvx mysql-mcp-server-ms==0.1.0
Cursor — .cursor/mcp.json:
"mysql": {
"command": "uvx",
"args": ["mysql-mcp-server-ms"]
}
Claude Code — project .mcp.json or:
claude mcp add --transport stdio mysql -- uvx mysql-mcp-server-ms
Private index (example):
UV_INDEX_URL=https://your-artifact-server/simple uvx mysql-mcp-server-ms
Or set UV_INDEX / PIP_INDEX_URL per uv docs for your org.
Before PyPI: install from Git (no full monorepo clone)
uvx can install the package from a Git URL pointing at this subdirectory (replace ORG, REPO, and branch/tag):
uvx --from "git+https://github.com/ORG/REPO.git#subdirectory=mysql_server&branch=main" mysql-mcp-server-ms
Use a tag or commit SHA instead of branch=main for stable installs.
Install from this repo (developers)
cd mysql_server
uv sync
uv run mysql-mcp-server-ms
Publishing (maintainers)
So others can run uvx mysql-mcp-server-ms from the default index, the package must be on PyPI (or a private index your team configures).
Option A — GitHub Actions (recommended, no long-lived PyPI token on laptops)
- One-time on pypi.org: add a pending trusted publisher for project
mysql-mcp-server-ms(must matchnameinpyproject.tomlexactly) → Settings → Publishing → workflowpublish-mysql-mcp-server.ymlon this repo (see comments in.github/workflows/publish-mysql-mcp-server.yml). - Bump
versioninpyproject.tomland merge to the default branch. - Trigger the workflow:
- GitHub → Actions → Publish mysql-mcp-server-ms to PyPI → Run workflow, or
- Push tag
mysql-mcp-server-ms-v0.1.0(prefixmysql-mcp-server-ms-v+ semver frompyproject.toml, e.g. version0.1.0→ tagmysql-mcp-server-ms-v0.1.0).
- Confirm on PyPI.
If your pending publisher used a different spelling (e.g. mysql_mcp_server_ms), remove it on PyPI and create a new one whose project name matches the name field in pyproject.toml (mysql-mcp-server-ms).
Option B — From your machine
-
Bump
versioninpyproject.toml. -
Remove stray
*.egg-infoundersrc/if present (rm -rf src/*.egg-info). -
Build and upload:
cd mysql_server uv build uv publish
Configure credentials via uv publish (
UV_PUBLISH_TOKEN, orkeyring/~/.pypirc).
Prerequisites
- Python 3.10+
- uv on
PATH(foruvx/uv sync) - Network access to MySQL (VPN if internal)
Installing uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# or: brew install uv
uv --version
Cursor (monorepo / editable install)
If you develop inside the repo (clone path may be mysql-mcp-server):
"mysql": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/mysql-mcp-server/mysql_server",
"run",
"mysql-mcp-server-ms"
]
}
Legacy: .venv/bin/python3 + server.py shim is supported after uv sync.
Claude Code (monorepo + REPO_ROOT)
If your monorepo uses a root env var, point it at this package directory, for example:
export REPO_ROOT="/absolute/path/to/mysql-mcp-server"
claude mcp add --transport stdio mysql -- \
uv --directory "$REPO_ROOT/mysql_server" run mysql-mcp-server-ms
Security
- Prefer read-only MySQL users.
- Use VPN for internal DB hosts.
- Never commit passwords; use
connect_mysqlin-session or your secret manager.
Optional: Index-aware query enforcement (reject full scans + non-indexed predicates)
This MCP server can enforce a stricter performance policy for SELECT queries (including WITH ... SELECT):
- It parses
WHEREandJOIN ... ONpredicates. - For each predicate column, it checks
INFORMATION_SCHEMA.STATISTICSto see whether that column belongs to any index on the referenced table. - It also runs
EXPLAINand rejects the query if MySQL reports a full table scan (type = ALL).
Enable it by setting an env var when starting the MCP server:
"mysql": {
"command": "uvx",
"args": ["mysql-mcp-server-ms"],
"env": {
"MCP_MYSQL_ENFORCE_INDEXED_COLUMNS": "1"
}
}
If a query is rejected, you’ll get a message listing the non-indexed predicate columns (best-effort) and suggestions like “add an index” or “rewrite WHERE/JOIN to use an indexed column”.
Note: the mapping from SQL column references to tables is best-effort. For complex queries (subqueries/CTEs with ambiguous column qualifiers), the server may fall back to an EXPLAIN-only check and allow the query if no full scan is detected.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mysql_mcp_server_ms-0.1.1.tar.gz.
File metadata
- Download URL: mysql_mcp_server_ms-0.1.1.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77bf752c929553937a25e41d26eb291b1172f88d6ac86c7e8e5addd25e655d49
|
|
| MD5 |
d74e9fac920f5b804a39ade9a3926cc8
|
|
| BLAKE2b-256 |
1a38ab1f4ed4898768a41f59e5f4c92e0317ab476865a273e375cc1d32578164
|
File details
Details for the file mysql_mcp_server_ms-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mysql_mcp_server_ms-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0cf9606a6f57da53353d298f7fe063416e8b28959fe1423548e453d23c24aad
|
|
| MD5 |
50ba783c98776c28db8d899a7372569d
|
|
| BLAKE2b-256 |
2d8e122232f7c47b6aa6838186d011553db824c68872dfac5dd80a8ca9830be9
|