Beyond Portal Copilots: Database MCP Agents That Open Verified Index PRs

Portal chat copilots summarize slow queries in a browser tab and leave the risky migration work to you. Pairing archived ADX plans, SqlCommenter file:line tags, and culprit lint-sql lets coding agents open lock-safe PRs without touching production.

Every database vendor now pitches an “AI Database Agent” inside their cloud portal. In Microsoft Database Hub, Copilot sits next to your fleet metrics, consumes Fabric Capacity Units per prompt, and summarizes which query ID used the most CPU.

Having used both portal chat boxes and repo-level coding agents (as I shared in my post-Azure Data Studio setup), portal copilots have two structural blind spots:

  1. They cannot see your application code. Knowing query_id = 4192 scanned shop.orders does not tell a portal chatbot which TypeScript repository, Prisma call, or migration directory owns that table.
  2. LLMs are dangerous when guessing SQL migrations. Left unchecked, an LLM will happily suggest CREATE INDEX ix_orders_status ON shop.orders(status) without CONCURRENTLY on PostgreSQL (locking writes on a 40M-row table) or create a fourth overlapping index on a column that already has 85% write overhead.

Fixing slow queries safely requires deterministic Rust analysis on both ends - parsing the archived execution plan before the LLM thinks, and linting the proposed SQL migration against real table/index metadata before a PR opens.

Three warehouse MCP tools built for 64 KiB context budgets

Raw .sqlplan XML files routinely exceed 2 MB. Dumping raw XML into an agent’s context window blows token budgets and causes hallucinations on nested <RelOp> nodes.

When you start culprit mcp in EvidenceOnly mode delegated to your read-only ADX or ClickHouse archive, the agent gets three high-signal warehouse tools alongside resources, window, and incident:

MCP ToolWhat Rust executes before returning JSON (<= 64 KiB)
fleet_attentionCalls WarehouseFleetReader to rank up to 25 databases needing attention (active incidents, new regressions, high findings, collector gaps) in one tool call.
warehouse_plan_insightsFetches the exact .sqlplan or EXPLAIN (FORMAT JSON) blob from Azure Storage / S3, verifies its SHA-256 digest, runs culprit_plans::parse_plan + 32 plan-insight rules, and returns the compact operator tree + ranked fixes.
warehouse_plan_compareFetches two archived plan artifacts (e.g. baseline plan vs regressed plan), runs culprit_plans::compare, and returns operator diffs, row-estimate skew, and compiled parameter mismatches.

From archived Seq Scan to verified CONCURRENTLY index

Here is what that workflow looks like on a real PostgreSQL audit-log slowdown. fleet_attention flags audit-pg-prod with a high-impact finding (seq-scan accounting for 38% of database time). The captured SqlCommenter tag (/* controller='audit#recent',file='src/audit/repo.ts:84' */) points straight to the repository file.

Calling warehouse_plan_insights parses the archived EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON) artifact and shows public.audit_events scanning 2.4M rows (41,200 shared buffers, 246 ms) to filter one tenant’s key-rotation events. Once CREATE INDEX CONCURRENTLY audit_events_org_action_created_idx ON public.audit_events (org_id, action, created_at DESC) is verified via HypoPG and culprit lint-sql, execution drops to a 6-buffer backward Index Scan (1.4 ms):

Live EXPLAIN JSON diffClick any operator or switch Diagram / Tree
Open in Culprit Explain ↗
A Seq Scan (2.4M rows)vsB CONCURRENTLY index

178× fasterCONCURRENTLY index took 178× less time because it seeks audit_events_org_action_created_idx where Seq Scan (2.4M rows) scans audit_events (99% of Seq Scan (2.4M rows)'s cost).

  • CONCURRENTLY index has no Sort (Seq Scan (2.4M rows) has).
48K
cost · Seq Scan (2.4M rows)
4.880
cost · CONCURRENTLY index
246 ms
time · Seq Scan (2.4M rows)
1.4 ms
time · CONCURRENTLY index
3 → 2
operators
1
identical regions
ASeq Scan (2.4M rows)PostgreSQL · actual
Actual plan3 operators · cost 48K80%
Measured run246 ms41Kreads · 8.8K from disk50rows
Where the 246 ms went
result
BCONCURRENTLY indexPostgreSQL · actual
Actual plan2 operators · cost 4.8880%
Measured run1.4 ms6reads50rows
Where the 1.4 ms went
result
Live @culpritsql/plan-viewer PostgreSQL EXPLAIN diff: scanning 2.4M rows of public.audit_events with top-N heapsort (246 ms, 41,200 shared buffers) drops to a backward Index Scan on audit_events_org_action_created_idx (1.4 ms, 6 shared buffers) after a lint-sql verified CREATE INDEX CONCURRENTLY migration.

The mandatory gate: culprit lint-sql in CI

Giving an agent production evidence is step one. Refusing to trust its generated DDL blindly is step two.

Before opening a pull request (and again on every PR in GitHub Actions), culprit agent triage-warehouse and culprit lint-sql check the proposed migration file offline against a saved schema/size snapshot:

# 1. Generate a redacted Markdown triage brief + validate proposed migration
culprit agent triage-warehouse \
  --warehouse-evidence evidence-readonly.json \
  --resource "shop-prod" \
  --window 24h \
  --report shop-schema-snapshot.json \
  --proposed-sql migrations/20261126_cover_orders_status.sql \
  --fail-on high \
  --format markdown > pr-brief.md

# 2. Emit GitHub Code Scanning SARIF for inline PR annotations
culprit lint-sql shop-schema-snapshot.json \
  --file migrations/20261126_cover_orders_status.sql \
  --fail-on high \
  --format sarif > culprit-lint.sarif
0 live queries Both warehouse triage and lint-sql run 100% offline against archived metadata
SARIF output Blocks offline index builds, NOT NULL table rewrites, and FK type mismatches
Redacted PRs Generated briefs include exact culprit verify commands without leaking SQL literals

We also ship a composite GitHub Action (.github/actions/culprit-warehouse-triage) you can trigger on a schedule or from a culprit-notify webhook:

- uses: culpritsql/culprit-sql-studio/.github/actions/culprit-warehouse-triage@main
  with:
    warehouse-config: ./ops/evidence-readonly.json
    resource: shop-prod
    window: 24h
    snapshot-report: ./ops/shop-schema.json
    proposed-sql: ./migrations/20261126_cover_orders_status.sql
    fail-on: high

If the agent forgets WITH (ONLINE = ON) on SQL Server Enterprise or CREATE INDEX CONCURRENTLY on PostgreSQL, lint-sql exits non-zero and the bad migration never reaches a human reviewer’s inbox. And because Culprit enforces strict selectivity and read-replica evidence rules, it will not suggest dropping an index that a read replica still relies on.