Skip to main content
Glama
DB Health MCP
by ekss1121

db-health-mcp

One call. One health report for your database. An MCP server that lets Claude, Cursor, or any MCP client run a real checkup on your MySQL database — slow queries, missing indexes, fragmentation, dead-weight indexes — and returns a single scored report with a concrete fix for every finding. PostgreSQL is supported too.

Ask your agent: "What's wrong with my database?" — and watch it run health_report instead of guessing.

The headline: health_report

Most database MCP servers hand the agent a bag of small tools and let it improvise. health_report runs every check at once and folds the results into one report:

  • Score 0–100 with a letter grade (transparent heuristic: severity deductions, capped per category — see src/db_health_mcp/report.py)

  • Findings sorted by severity, each with the numbers behind it

  • A suggested fix per finding, as SQL text — e.g. the exact CREATE INDEX / OPTIMIZE TABLE / DROP INDEX statement. The server is read-only: it proposes fixes, it never executes them.

Sample output (abridged, from a real run against MySQL 8.0.46):

# Database health report (mysql)

**Score: 44/100 (grade D)**

- Server: 8.0.46-0ubuntu0.24.04.5
- Database size: 5.2 MB
- Active connections: 2
- Largest table: healthdemo.logs (2.5 MB)

Findings: 14 (1 high, 3 warning, 10 info)

## [HIGH] Table bloat / fragmentation: healthdemo.logs

80% of the table's allocated space is free (10.0 MB of 12.5 MB), left
behind by deletes/updates.

Suggested fix: `OPTIMIZE TABLE `healthdemo`.`logs`;`

## [WARNING] Missing indexes: healthdemo.orders

Full table scans have read 600,000 rows from this ~19,922-row table
(30 full passes).

Suggested fix: `CREATE INDEX idx_orders_<column> ON `healthdemo`.`orders` (<column>); ...`

## [INFO] Unused indexes: healthdemo.users

Index has never been used since the server started, but still costs write
overhead on every insert/update.

Suggested fix: `DROP INDEX `idx_nickname_unused` ON `healthdemo`.`users`;`

Verified end to end against live MySQL 8.0.46 and PostgreSQL 16.15 (all six tools, both engines), plus 30 unit tests with mocked rows.

Related MCP server: pgtriage

Individual check tools

For follow-up questions, each check is also a tool of its own:

Tool

MySQL source

PostgreSQL source

db_overview

version, size, connections, largest tables

same

slow_queries

performance_schema statement digests

pg_stat_statements

missing_indexes

sys.schema_tables_with_full_table_scans

sequential-scan stats

table_bloat

InnoDB fragmentation (information_schema.data_free)

dead-tuple ratio

index_usage

sys.schema_unused_indexes

pg_stat_user_indexes

The engine is picked automatically from the connection-string scheme (mysql:// vs postgresql://), and every tool accepts an optional database_url argument, so one server instance can check several databases.

Read-only by design. Sessions are opened read-only (SET SESSION TRANSACTION READ ONLY / default_transaction_read_only=on) with a statement timeout, and every query is a SELECT against catalog/statistics views. The server cannot modify your database.

Quick start

pip install db-health-mcp   # or: pip install -e . from a clone

Claude Code

claude mcp add db-health \
  -e DATABASE_URL=mysql://user:pass@localhost:3306/mydb \
  -- db-health-mcp

Cursor / other MCP clients

{
  "mcpServers": {
    "db-health": {
      "command": "db-health-mcp",
      "env": {
        "DATABASE_URL": "mysql://user:pass@localhost:3306/mydb"
      }
    }
  }
}

PostgreSQL works the same way with a postgresql:// URL.

Then just ask:

  • "What's wrong with my database?"

  • "Give my database a health check and list the fixes in priority order."

  • "Which tables are missing indexes?"

  • "Are there any indexes I can safely drop?"

Notes

  • MySQL checks need MySQL 8 with performance_schema and the sys schema enabled (both are defaults). If statement digests are unavailable, slow_queries tells you how to enable them instead of failing; the other checks still run.

  • PostgreSQL slow_queries needs the pg_stat_statements extension; same deal — you get enable instructions, not an error.

  • Statistics accumulate over time (MySQL: since server start; PostgreSQL: since the last stats reset) — on a freshly restarted database the scan/index findings need some real traffic before they mean much.

  • Use a least-privilege, read-only database user for extra safety.

Development

python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest                      # unit tests (mocked rows, no live DB needed)
python scripts/selftest.py  # MCP handshake + tool list + error paths

Roadmap

  • MariaDB compatibility pass (the sys schema and max_execution_time differ slightly)

  • SQLite quick-check for local dev databases

  • explain_query tool: run EXPLAIN on a query and interpret the plan

  • Lock contention and long-running transaction checks

  • Replication lag check

  • A sibling project: cloud capacity/quota checks for AWS/GCP

License

MIT

Available Tools

6 tools
db_overviewB

Get a quick snapshot: server version, database size, active connection count, and the largest tables by total size.

Inputs: database_url.

health_reportA

Run every health check in one call and return a single report: an overall score (0-100), findings sorted by severity, and a concrete suggested fix for each finding (SQL text, never executed). Works for MySQL and PostgreSQL; the engine is picked from the URL scheme.

Inputs: database_url.

index_usageB

Find indexes that have never been used for a scan — they still cost write overhead and disk. Primary-key and unique indexes are excluded.

Inputs: database_url.

missing_indexesC

Find tables that are read mostly by full/sequential scans — the classic symptom of a missing index.

Inputs: database_url.

slow_queriesA

List the slowest queries by mean execution time (MySQL: performance_schema statement digests; PostgreSQL: pg_stat_statements). If the statistics source is unavailable, returns instructions for enabling it instead of failing.

Inputs: limit, database_url.

table_bloatB

Find bloated tables (PostgreSQL: dead-tuple ratio; MySQL: InnoDB fragmentation via data_free).

Inputs: database_url.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.6/5.0

    Scored across 6 tools

    Disambiguation5/5

    Each tool targets a single, distinct diagnostic concern: missing indexes, table bloat, unused indexes, slow queries, and a snapshot overview. The one potential overlap (health_report vs. individual checks) is clearly framed as an aggregate that runs all checks in one call, so there's no confusion about when to use which.

    Naming Consistency4/5

    All names are snake_case noun phrases describing the returned data (missing_indexes, table_bloat, index_usage, health_report, db_overview, slow_queries) — internally consistent rather than verb_noun. Minor singular/plural mixing (missing_indexes vs. table_bloat) keeps it just short of perfect.

    Tool Count5/5

    Six tools is well-scoped for a DB health diagnostic server: five focused checks plus one aggregate report. Each tool earns its place with no redundancy beyond the intentional roll-up.

    Completeness4/5

    Covers the core health signals — index gaps, bloat, unused indexes, slow queries, and a version/size/connection snapshot — with an aggregate report. Gaps exist for lock/wait analysis, cache hit ratios, and replication lag, but these are workaround-able omissions rather than blocking holes.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      Read-only PostgreSQL performance auditing via MCP. Collects metrics from PostgreSQL system views, applies deterministic checks for index, query, vacuum, configuration, and connection issues, and returns structured findings for MCP clients.
      6
      MIT
    • A
      license
      B
      quality
      C
      maintenance
      Enables AI coding agents to perform deterministic database architecture audits and performance engineering for PostgreSQL and MySQL, covering migration analysis with schema health scoring, ESR-based composite index recommendations, N+1 query detection, EXPLAIN plan diagnosis, transaction and deadlock analysis, partitioning and archival design, and capacity or configuration tuning. It also generates phased Expand & Contract runbooks that turn blocking DDL into zero-downtime production migrations.
      8
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Read-only MCP server for SQL Server and PostgreSQL health checks. It runs the codeDB Lens diagnosis (A–F grade with rule coverage, findings with evidence, impact and next actions), reads 24-hour performance recordings, lists databases and tables, describes table schemas, and runs one guarded SELECT at a time within per-profile row and time limits. It uses the user's saved connection profiles; pass
      14
      8
      Apache 2.0