mysql-diag-mcp
Provides diagnostic-only tools for troubleshooting MySQL performance, including processlist, active queries, InnoDB status, lock waits, statement digests, replication status, and curated status/variable snapshots.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mysql-diag-mcp check for long-running queries in the processlist"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mysql-diag-mcp
A read-only MCP server that gives an AI agent (or any MCP client) a curated set of diagnostic-only tools for troubleshooting MySQL performance problems — the kind of thing a DBA or ops engineer reaches for during a slowdown: processlist, blocking chains, InnoDB status, statement digests, replication lag, and curated status/variable snapshots.
Supports MySQL 5.7 through 8.4+. The server detects the target server's version once per run and automatically selects the right query variant where MySQL's schema changed between major versions (e.g. lock-wait diagnostics, replication status).
There is no generic SQL tool and this MCP never reads application row
data — every tool is backed by a fixed query against
information_schema/performance_schema/SHOW ... metadata. The one
exception, mysql_explain, only runs EXPLAIN on a single SELECT/SHOW
statement you provide; it never executes DML/DDL.
Connection modes
Pick whichever fits your environment via MYSQL_CONN_MODE:
MYSQL_CONN_MODE=ssh (default)
MCP client → mysql-diag (stdio) → ssh [-J bastion] dbhost → mysql CLI (socket or TCP)
MYSQL_CONN_MODE=direct
MCP client → mysql-diag (stdio) → PyMySQL → MySQL (TCP or unix socket)ssh— hops over SSH (optionally through a bastion) and runs the remote host'smysqlCLI binary. Good when MySQL is only reachable from inside a network you access via SSH, and you'd rather not open a DB port to the machine running this MCP.direct— connects straight to MySQL over TCP or a local unix socket using a bundled Python driver (PyMySQL). No SSH, no remote CLI dependency. Use this if you already have network access to the DB (directly, via VPN, or via your own port-forward/tunnel). ConfigureMYSQL_SSL_MODE(disabledby default, orrequired/verify_ca/verify_identitywithMYSQL_SSL_CA/MYSQL_SSL_CERT/MYSQL_SSL_KEY) if you're connecting over an untrusted network.
Related MCP server: mysql-mcp
Setup
Install uv if needed, then from this repo:
uv syncCopy the env template and fill it in (never commit
.env):cp .env.example .envSee
.env.examplefor every setting; the essentials:Variable
Required
Meaning
MYSQL_CONN_MODEno
ssh(default) ordirectSSH_HOSTyes, if
sshmodeuser@dbhost— or the bastion if MySQL runs thereSSH_JUMPno
user@bastion(ssh -J). Leave empty when the bastion is the DB hostSSH_KEYno
Private key path; otherwise ssh-agent /
~/.ssh/configMYSQL_USERyes
Dedicated
mcp_diaguser (not app root)MYSQL_PASSWORDno
Omit if the remote user uses socket peer-auth /
.my.cnfMYSQL_SOCKETpreferred for
sshmodeSocket as seen on the DB host
MYSQL_HOST/MYSQL_PORTfallback / required for
directUsed when
MYSQL_SOCKETis unsetMYSQL_SSL_MODEno,
directmode onlydisabled(default) /required/verify_ca/verify_identityMYSQL_TIMEOUT_SECno
Default
8MYSQL_MAX_ROWSno
Default
200In
sshmode, confirm the hop by hand (same identity the MCP will use):ssh -o BatchMode=yes -J "$SSH_JUMP" "$SSH_HOST" \ mysql --socket="$MYSQL_SOCKET" -u "$MYSQL_USER" -e 'SELECT 1'Register the server with your MCP client, pointing it at this directory and your
.envfile, e.g.:{ "mcpServers": { "mysql-diag": { "command": "uv", "args": ["run", "--directory", "/path/to/mysql-diag-mcp", "python", "-m", "mysql_diag_mcp"], "envFile": "/path/to/mysql-diag-mcp/.env" } } }
Password is sent as a remote --defaults-extra-file (base64 over SSH
stdin), not on ps argv, in ssh mode.
Running as a shared network server
By default this runs over stdio: one client spawns it as a local
subprocess. It can instead run as a persistent HTTP service that many
different users/agents, using any MCP-compatible client, connect to over
the network, instead of everyone needing their own local checkout and DB
credentials.
Where you run this, and how it reaches your MySQL server(s), is entirely
up to you/ops — it doesn't need to sit next to the database. Both
connection modes above work the same regardless of placement: ssh if this
host has SSH access to a bastion/DB host, direct if it has plain network
(or VPN/tunnel) access to MySQL itself.
Set the network env vars (add to
.envor pass directly):Variable
Meaning
MCP_TRANSPORTstdio(default) /streamable-http(recommended) /sse(legacy clients)MCP_HOSTBind address, e.g.
0.0.0.0to listen on all interfacesMCP_PORTDefault
8000MCP_AUTH_TOKENStoken1:alice,token2:bob— required for any non-stdiotransportMCP_ALLOW_NO_AUTHtrueto explicitly run without token auth (see below)MCP_ALLOWED_HOSTS/MCP_ALLOWED_ORIGINSComma-separated; required once
MCP_HOSTis anything other than localhost (see below)Auth is required by default. Starting a
streamable-http/sseserver withoutMCP_AUTH_TOKENSrefuses to start with a clear error, rather than silently exposing an unauthenticated diagnostics endpoint. Every request needs anAuthorization: Bearer <token>header matching one of the configured tokens; unmatched/missing tokens get a401. Each request is logged with the token's label, method, path, status, and duration — the audit trail for a shared credential now serving multiple people. If you're deliberately relying on network-level access control instead (firewall, VPN, an authenticating reverse proxy), setMCP_ALLOW_NO_AUTH=trueto opt out explicitly.This app serves plain HTTP — it does not terminate TLS. Put a reverse proxy (nginx, Caddy, your load balancer) in front for HTTPS; forward
Authorizationheaders through unchanged.DNS-rebinding protection: once
MCP_HOSTis not127.0.0.1/localhost, setMCP_ALLOWED_HOSTS/MCP_ALLOWED_ORIGINSto the hostname(s)/origin(s) clients will actually use to reach this server — otherwise the SDK's rebinding protection will reject requests with421 Invalid Host header.Run it directly:
MCP_TRANSPORT=streamable-http MCP_HOST=0.0.0.0 MCP_AUTH_TOKENS=devtoken:alice \ uv run python -m mysql_diag_mcpOr with Docker:
docker build -t mysql-diag-mcp . docker run -p 8000:8000 --env-file .env \ -e MCP_AUTH_TOKENS=devtoken:alice \ mysql-diag-mcpFor
MYSQL_CONN_MODE=sshinside the container, mount an SSH key read-only and pointSSH_KEYat it, e.g.-v $HOME/.ssh/id_ed25519:/root/.ssh/id_ed25519:ro -e SSH_KEY=/root/.ssh/id_ed25519.Or with Docker Compose (
compose.yml, customize as needed — e.g. uncomment the SSH key volume mount, or add anenvironment:block to override individual.envvalues):docker compose up -d --buildThis is also the easiest path if you manage the container from Docker Desktop's GUI rather than the CLI — Desktop's own "Run" dialog only lets you add environment variables one at a time, with no equivalent of
--env-file; Compose'senv_file:directive loads the whole file at once, and Desktop's Containers view manages a Compose-started container the same way it manages any other.MCP_TRANSPORTmust bestreamable-http(orsse) in.envbefore running detached like this. Left at the defaultstdio, the server starts, immediately hits EOF on stdin (nothing is attached to it in a detached container), exits, and — because ofrestart: unless-stopped— restart-loops forever with no error in the logs, just repeated clean startups.docker compose psshowingRestartingis the symptom.Point your MCP client at
http://<host>:<port>/mcp(or/ssefor the legacy transport) with anAuthorization: Bearer <token>header. The exact way to add a remote HTTP MCP server varies by client and version — check your client's own docs for the current syntax.
All callers share the same MySQL privileges as the one configured DB user — no new risk versus the single-user model, just now serving more people; the per-request identity logging above is how you attribute usage.
MySQL grants
Run as an admin on the target server. No application-schema grants — these work unchanged on 5.7 and 8.0/8.4:
CREATE USER 'mcp_diag'@'localhost' IDENTIFIED BY 'choose-a-strong-password';
GRANT PROCESS, REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO 'mcp_diag'@'localhost';
GRANT SELECT ON performance_schema.* TO 'mcp_diag'@'localhost';
GRANT SELECT ON information_schema.* TO 'mcp_diag'@'localhost';
FLUSH PRIVILEGES;Use 'mcp_diag'@'%' (or a specific client CIDR) as well if you connect via
MYSQL_CONN_MODE=direct from a different host than the DB server.
Tools
Tool | Purpose |
| Reachability, version, hostname |
|
|
| Non- |
| Curated status counters (+ whether query cache exists on this version) |
| Two samples → per-second rates |
| Curated variables (buffer pool, query cache if present, slow log) |
| Parsed InnoDB status + history list length |
| Open transactions |
| Blocking chains — |
| Top statement digests by wait time |
| Wait event summary (often empty if instruments are off) |
| Hottest tables by IO wait |
| Connections grouped by user/host — spot monitoring-agent storms |
| Replica lag/thread health — |
| Connected replicas — |
|
|
Resource runbook://spike is the suggested call order for a user-facing
slowdown.
Safety
Allowlisted SQL only.
mysql_explainmust start withSELECTorSHOW, contain no;, and no DML/DDL keywords.Timeouts kill the SSH/mysql process (or the direct connection).
Info/ InnoDB dumps and replication error fields are truncated.In
sshmode:BatchMode,ControlMasterconnection reuse, optionalProxyJump.This MCP cannot
INSERT/UPDATE/DELETE, dump application row data, or change server configuration.
Development
uv sync
uv run python -m unittest discover -s tests -v
uv run python -m mysql_diag_mcp # stdio MCP serverLogs go to stderr only (stdout is the MCP protocol).
License
MIT — see LICENSE.
Available Tools
16 toolsmysql_active_queriesA
Non-Sleep threads from information_schema.PROCESSLIST, longest first.
Inputs: no named parameters. Returns: object
mysql_digest_topA
Top statement digests by wait time from performance_schema (no application table reads).
Inputs: no named parameters. Returns: object
mysql_explainA
EXPLAIN a single SELECT or SHOW. Stacked queries and DML are rejected.
Inputs: statement (required). Returns: object
mysql_global_statusB
Curated SHOW GLOBAL STATUS keys (threads, tmp tables, InnoDB locks, QPS counters).
Inputs: no named parameters. Returns: object
mysql_innodb_statusA
Parsed SHOW ENGINE INNODB STATUS: history list, deadlocks, semaphores, buffer pool.
Inputs: no named parameters. Returns: object
mysql_innodb_trxA
Open InnoDB transactions (age, thread, query). Long trx_age_sec pins locks/history.
Inputs: no named parameters. Returns: object
mysql_lock_waitsB
Blocking chains: performance_schema.data_locks (8.0+) or innodb_locks (<8.0.18). Empty if nobody is waiting.
Inputs: no named parameters. Returns: object
mysql_monitor_clientsA
Processlist grouped by user/host/command. Use to spot monitoring-agent connection storms.
Inputs: no named parameters. Returns: object
mysql_pingA
Check SSH + MySQL reachability; return version, hostname, and server time.
Inputs: no named parameters. Returns: object
mysql_processlistA
SHOW FULL PROCESSLIST. Truncates Info. Use during a user-facing slowdown.
Inputs: no named parameters. Returns: object
mysql_replica_statusA
Replica lag, IO/SQL thread state, last IO/SQL error.
SHOW REPLICA STATUS (8.0.22+) or SHOW SLAVE STATUS (older). Replication
channel metadata only, never binlog row contents. is_replica: false
with empty rows is the normal result on a standalone/primary server.
Inputs: no named parameters. Returns: object
mysql_replica_topologyA
Replicas connected to this server: SHOW REPLICAS (8.0.22+) or SHOW SLAVE HOSTS (older).
Inputs: no named parameters. Returns: object
mysql_status_deltaC
Two GLOBAL STATUS samples; counters as per-second rates, gauges as t0/t1.
Inputs: sample_seconds. Returns: object
mysql_table_ioA
Hottest application tables by IO wait (excludes mysql/performance_schema/sys).
Inputs: no named parameters. Returns: object
mysql_variablesA
Curated SHOW GLOBAL VARIABLES (buffer pool, connections, slow log, query cache if present).
Inputs: no named parameters. Returns: object
mysql_wait_eventsA
Top wait events. Often empty if wait instruments are disabled.
Inputs: no named parameters. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 16 tools
Most tools target clearly distinct diagnostic areas: connectivity, processlist, status, variables, InnoDB internals, replication, and explain. The only notable overlap is among mysql_processlist, mysql_active_queries, and mysql_monitor_clients, all of which read the processlist but with different filtering/grouping purposes.
All tools share the mysql_ prefix and use snake_case with descriptive resource names, making the set predictable. A minor deviation is that mysql_ping and mysql_explain use action-style names while the rest are noun-phrase resources, but this does not create real confusion.
16 tools is slightly above the typical 3-15 range, but the count is justified by the breadth of MySQL diagnostic concerns: processlist, status, InnoDB transactions, locks, wait events, table IO, and replication. Each tool covers a distinct diagnostic probe rather than duplicating existing functionality.
The toolkit provides strong coverage for diagnosing MySQL health, performance, locks, transactions, and replication with no obvious dead ends. Minor gaps exist, such as no ability to kill a query or inspect slow query logs, but these are operational actions rather than core diagnostic surface.
Maintenance
Related MCP Connectors
Hosted MCP server for PostgreSQL diagnostics: slow queries, missing indexes, connection pressure.
Read-only MCP server for AIStatusDashboard status, incidents, metrics, and fallback recommendations.
2,000+ MCP servers read at source level. Know what one does before you connect. Free, no key.
Reddit Ads MCP server: 9 tools for subreddit reports, targeting, diagnosis. Read-only by default.
Related MCP Servers
- AlicenseAqualityBmaintenanceAn MCP server that provides read-only access to MySQL databases.4716 npm75MIT
- AlicenseNot gradedqualityDmaintenanceA lightweight MCP server providing safe, read-only access to MySQL databases. It enables users to query multiple MySQL instances securely while preventing write operations.MIT
- AlicenseNot gradedqualityDmaintenanceA production-ready MCP server for MySQL database operations, providing secure HTTP endpoints for read-only queries, performance analysis, and server monitoring.22MIT
- FlicenseAqualityCmaintenanceSecurity-hardened, read-only MySQL MCP server that enables safe, read-only access to MySQL databases for running SELECT queries, exploring schemas, and sampling data via MCP clients.9-