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:
- They cannot see your application code. Knowing
query_id = 4192scannedshop.ordersdoes not tell a portal chatbot which TypeScript repository, Prisma call, or migration directory owns that table. - LLMs are dangerous when guessing SQL migrations. Left unchecked, an LLM will happily suggest
CREATE INDEX ix_orders_status ON shop.orders(status)withoutCONCURRENTLYon 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 Tool | What Rust executes before returning JSON (<= 64 KiB) |
|---|---|
fleet_attention | Calls WarehouseFleetReader to rank up to 25 databases needing attention (active incidents, new regressions, high findings, collector gaps) in one tool call. |
warehouse_plan_insights | Fetches 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_compare | Fetches 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):
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
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.
Microsoft retired Azure Data Studio in February 2026. Here is how I inspect .sqlplan files, diff execution plans, and untangle deadlocks on macOS and in VS Code now.