AI-powered incident response
PLAI-powered incident response connects Claude Code, Codex or Cursor to Sentry, Grafana, Datadog and PagerDuty through read-only MCP servers. The agent correlates alerts, deploys and errors into a sourced timeline, tests hypotheses, and drafts the mitigation, status updates and post-mortem. People keep the decisions: the incident commander approves every production change, and a monitoring query declares recovery.
It is 02:47. PagerDuty has paged you about checkout errors, Grafana, Datadog and Sentry are open in six tabs, and your product manager is already asking for an ETA in the incident channel. The fix may take two minutes; working out what broke is what takes the time. This page is for the on-call developer who runs that incident and the tech lead who owns the incident process. It shows where the agent works in each phase, the prompts to paste, and the gates that let you trust its output without reading every line of it.
What this workflow gives you
Section titled “What this workflow gives you”- A phase-by-phase split of what the agent does and what a named person decides, from page to post-mortem.
- Read-only MCP setup for Sentry, Grafana, Datadog and PagerDuty in Claude Code, Codex and Cursor, with the switch that makes each server read-only.
- Six copy-paste prompts: correlate, test the hypothesis, prepare the mitigation, check recovery, draft the status update, and draft the post-mortem.
- A decision table for rollback, feature flag or fix forward, and the recovery check that closes the incident.
- A post-mortem routine that turns each contributing factor into a test, an alert rule or an eval.
Where does the agent help in an incident, and where does it stop?
Section titled “Where does the agent help in an incident, and where does it stop?”The agent is the incident’s analyst and scribe. It never operates production. Each phase has an output you can check without trusting the agent’s prose.
| Phase | The agent does | A person decides | The evidence you check |
|---|---|---|---|
| Detect | Nothing: monitoring pages a human | On-call engineer opens the incident | Alert ID in the incident tool |
| Correlate | Builds a UTC timeline from alerts, errors and deploys | — | Every line cites a query, alert ID, issue ID or commit SHA |
| Diagnose | Ranks hypotheses with evidence and counter-evidence | Incident commander picks one to act on | Cited sources re-opened by a second run |
| Mitigate | Prepares the runbook step, revert or flag change | Incident commander approves; the pipeline executes | Deploy or flag system audit log |
| Recover | Runs the recovery query against thresholds set earlier | Commander declares recovery | SLO query result, attached to the incident |
| Communicate | Drafts each status update | Comms lead or commander posts it | The posted message, by a named person |
| Learn | Drafts the post-mortem and the regression tests | Service owners merge the post-mortem pull request | Tests and evals that fail on the old behaviour |
Two neighbouring pages cover the edges of this workflow. To lock the triage agent down under its own service account, with a tool allowlist and an injection drill, follow scoped AI incident triage. When an agent caused the incident, start with when an agent causes an incident: containment there begins with revoking the agent’s identity.
Connect read-only incident sources before the next page
Section titled “Connect read-only incident sources before the next page”Set this up on a quiet afternoon, not during the incident. MCP configuration differs only in the command or file; the servers, URLs and read-only switches are the same in every agent. The full install guide, including OAuth scopes and context cost, is on observability MCP servers.
| Server | Official package or URL (checked 2026-09-26) | What makes it read-only |
|---|---|---|
| Sentry | https://mcp.sentry.dev/mcp (OAuth); stdio @sentry/mcp-server 0.42.0 for self-hosted | Narrow the exposed tools with ?skills= in the URL, for example ?skills=inspect,seer (Sentry MCP README, checked 2026-09-26). seer starts Seer analysis runs; use ?skills=inspect for strict read-only access |
| Grafana | PyPI mcp-grafana 1.6.3, run with uvx | --disable-write and a Viewer-role service account |
| Datadog | https://mcp.datadoghq.com/v1/mcp (US1; EU uses mcp.datadoghq.eu) | No read-only switch in its README; log in as a user whose role fits |
| PagerDuty | PyPI pagerduty-mcp 1.1.0, run with uvx (repository deprecated 2026; still read-only by default). The maintained path is PagerDuty’s hosted remote MCP server with OAuth; see its knowledge base | Read-only by default; never add --enable-write-tools for triage |
Run in a terminal at the service repository’s root. -s project writes .mcp.json, so the setup goes through review, and single quotes keep each ${VAR} unexpanded until launch:
claude mcp add -s project --transport http sentry 'https://mcp.sentry.dev/mcp?skills=inspect,seer'claude mcp add -s project grafana \ -e GRAFANA_URL=https://yourstack.grafana.net \ -e 'GRAFANA_SERVICE_ACCOUNT_TOKEN=${GRAFANA_SERVICE_ACCOUNT_TOKEN}' \ -- uvx mcp-grafana --disable-writeclaude mcp add -s project --transport http datadog https://mcp.datadoghq.com/v1/mcpclaude mcp add -s project pagerduty \ -e 'PAGERDUTY_USER_API_KEY=${PAGERDUTY_USER_API_KEY}' \ -- uvx pagerduty-mcpRun /mcp inside a session to complete the OAuth logins and confirm every server shows as connected.
Add the remote servers with codex mcp add; in our test it started the OAuth flow straight away, and codex mcp login <name> repeats it. The two stdio servers go into ~/.codex/config.toml, where env_vars forwards the token from your shell without writing it into the file:
codex mcp add sentry --url 'https://mcp.sentry.dev/mcp?skills=inspect,seer'codex mcp add datadog --url https://mcp.datadoghq.com/v1/mcp[mcp_servers.grafana]command = "uvx"args = ["mcp-grafana", "--disable-write"]env = { GRAFANA_URL = "https://yourstack.grafana.net" }env_vars = ["GRAFANA_SERVICE_ACCOUNT_TOKEN"]
[mcp_servers.pagerduty]command = "uvx"args = ["pagerduty-mcp"]env_vars = ["PAGERDUTY_USER_API_KEY"]Check each entry with codex mcp list (codex-cli 0.157.1).
In .cursor/mcp.json at the repository root. Cursor’s MCP docs (via a SECONDARY snippet, 2026-08-28) write environment variables as ${env:NAME}:
{ "mcpServers": { "sentry": { "url": "https://mcp.sentry.dev/mcp?skills=inspect,seer" }, "datadog": { "url": "https://mcp.datadoghq.com/v1/mcp" }, "grafana": { "command": "uvx", "args": ["mcp-grafana", "--disable-write"], "env": { "GRAFANA_URL": "https://yourstack.grafana.net", "GRAFANA_SERVICE_ACCOUNT_TOKEN": "${env:GRAFANA_SERVICE_ACCOUNT_TOKEN}" } }, "pagerduty": { "command": "uvx", "args": ["pagerduty-mcp"], "env": { "PAGERDUTY_USER_API_KEY": "${env:PAGERDUTY_USER_API_KEY}" } } }}Complete each OAuth sign-in when Cursor asks for it.
Read-only belongs to the credential, not the prompt. A token that cannot write survives an agent that has been talked into trying; a line saying “do not change anything” does not. Name servers in plain language (“Using the Grafana and Sentry MCP servers, …”). In Claude Code, @server:protocol://resource mentions reference MCP resources, not tools (checked on 2.1.283).
How do you correlate alerts into one timeline?
Section titled “How do you correlate alerts into one timeline?”Start the agent the moment you acknowledge the page. The first output you want is a timeline in which every line points at its source, because that is the only form you can check in two minutes.
Interactively, start in plan mode so the agent can query but cannot edit files: claude --permission-mode plan, then paste the prompt. To post the timeline to the incident record from a script, run it headless with only the MCP servers allowed:
claude -p "$(cat prompts/correlate.md) Incident: $INCIDENT_ID" \ --allowedTools "mcp__sentry mcp__grafana mcp__datadog mcp__pagerduty" \ --permission-mode dontAsk \ --output-format stream-json --verbose > "timeline-$INCIDENT_ID.jsonl"dontAsk denies every tool call that would prompt instead of waiting for an answer nobody will give (Claude Code 2.1.283). Servers added with -s project need a one-time approval before they load, so a fresh machine or CI runner can start this run with no MCP tools and return a timeline with no tool calls. Approve the project servers once in an interactive session (or add them with -s user on the machine that runs the script), then confirm with claude mcp list before you rely on the headless run.
Interactively, run codex in the repository and paste the prompt. Headless, use the read-only permission profile (beta, codex-cli 0.138.0 and later) and keep the JSONL event stream, which records every MCP call:
codex exec -c default_permissions=":read-only" \ --json -o "timeline-$INCIDENT_ID.md" \ "$(cat prompts/correlate.md) Incident: $INCIDENT_ID" \ < /dev/null > "timeline-$INCIDENT_ID.jsonl"The profile constrains the shell commands Codex runs. It is not documented to constrain MCP calls (codex-cli 0.157.1), which is why the read-only switches in the table above carry the real guarantee.
Open the agent in Plan Mode and paste the prompt. Cursor Automations can also start a cloud agent from a Sentry or PagerDuty event (Cursor docs, checked 2026-08-28), so the timeline can be waiting when you open the laptop. A cloud agent has a full VM with a shell, so give its environment only the read-only tokens above and have it deliver a report, not a branch.
A useful reply is short and checkable. For example (illustrative):
02:30 payment-service v2.3.1 deployed [commit 9f3c2e1]02:44 DB connection wait p95 150 ms -> 4.2 s [grafana: query A]02:45 5xx rate 0.2% -> 15% [datadog monitor 81234]02:47 ConnectionTimeoutError spike, first seen in v2.3.1 [sentry PAY-4F2]02:47 PagerDuty incident triggered [pagerduty Q2X9]
Downstream: checkout-web 502s follow payment-service 5xx.H1 connection pool too small after v2.3.1 (pool config changed in 9f3c2e1). Against: none found.H2 database saturation. Against: DB CPU flat at 35% [grafana: query B].How do you test the leading hypothesis before anyone mitigates?
Section titled “How do you test the leading hypothesis before anyone mitigates?”A timeline suggests a cause; it does not prove one. Before anyone touches production, ask the agent to try to break its own best hypothesis and to name what would confirm it.
“Smallest reversible action” is deliberate. It steers the answer toward a flag or a revert, both of which you can undo, and away from a speculative code change written under pressure.
Should you roll back, turn off a flag, or fix forward?
Section titled “Should you roll back, turn off a flag, or fix forward?”Pick the mitigation before anyone writes code. The agent’s job is to prepare the option the incident commander chooses and to state the recovery threshold in advance.
| Situation | Mitigation | What the agent prepares |
|---|---|---|
| A deploy in the window and a clean previous release | Roll back through the pipeline | The revert pull request and the rollback runbook step |
| The change sits behind a feature flag | Turn the flag off | The exact flag, its current targeting and the expected metric change |
| Rollback is unsafe (a migration ran, data shape changed) | Fix forward | A minimal patch with a failing-then-passing test |
| No change correlates (capacity, dependency outage) | Scale, fail over or shed load per runbook | The runbook step and the numbers that justify it |
A rollback path you have never exercised fails at 03:00. Rehearsed rollback with human production authority covers building it, and production approval as a system boundary covers who may press the button.
Mitigation is the phase to slow down. With v2.1.283 or later (both release channels on 2026-10-12), auto mode is the starting mode for interactive sessions, so start this one in Manual to get a prompt for every action:
claude --permission-mode manualNever use --dangerously-skip-permissions or bypassPermissions during an incident. The agent opens a pull request; the pipeline deploys it.
Work in a separate worktree so the incident branch cannot collide with anything else, and use -a on-request, which lets the model ask for your approval when it needs it:
codex --worktree -a on-request -c default_permissions=":workspace"Codex asks before crossing the workspace boundary, for example to push. Do not use --dangerously-bypass-approvals-and-sandbox outside a disposable, network-restricted sandbox.
Use Plan Mode, read the plan, then let the agent edit and review the diff before you accept it. Set Cursor’s Run modes so terminal commands and MCP calls need your approval; the modes are Auto-review, Allowlist and Run Everything, under Settings > Agents > Approvals & Execution (Cursor docs, checked 2026-10-12). Bugbot can review the resulting pull request like any other.
How do you declare recovery without trusting the agent’s summary?
Section titled “How do you declare recovery without trusting the agent’s summary?”Recovery is a query result compared against the thresholds written before the deploy. Setting the bar after seeing the numbers is how a partial fix gets called done. The agent runs the check and reports pass or fail; the incident commander declares recovery.
How do you keep stakeholders updated during the incident?
Section titled “How do you keep stakeholders updated during the incident?”The agent drafts; a named person posts. A bot that posts on its own sooner or later tells customers something the commander has not agreed to.
For Slack, the official Slack MCP server ships inside plugins: /plugin install slack@claude-plugins-official in Claude Code and codex plugin add slack@openai-curated in Codex (both checked 2026-09-26). On Claude Team and Enterprise plans the Slack path is Claude Tag, which acts as the organization’s shared identity, so check what access your admin gave it before inviting it to an incident channel. Codex also works from Slack: mention @ChatGPT, and with Cloud delegation enabled ChatGPT sends repository work to a Codex Cloud task (OpenAI docs, checked 2026-10-12).
How do you turn the post-mortem into tests and evals?
Section titled “How do you turn the post-mortem into tests and evals?”The post-mortem pays off only when each contributing factor becomes a check that fails if the problem comes back. The agent reconstructs the timeline from the same queries it ran live, so the draft starts from evidence, not from memory. Tag each contributing factor with a class from the failure taxonomy, so repeat causes show up across incidents.
A service owner reviews the post-mortem as a pull request, and it merges only with its tests in the same change or linked issues for each action item. When the cause was an agent-written change, the eval case goes into your continuous evals suite, so the same mistake fails a build instead of paging someone.
How do you know the agent’s incident work is trustworthy?
Section titled “How do you know the agent’s incident work is trustworthy?”You check the agent’s output with gates, not by rereading it:
- Sources, then audit. Every timeline line carries a source, and a second run re-opens each one and marks it VERIFIED, CONTRADICTED or UNSOURCED. The audit prompt is on scoped AI incident triage. A hypothesis that rests on an unsourced line does not reach the commander.
- The tool-call log. The Claude Code stream-json output and the Codex JSONL stream record every MCP call. A timeline with no calls behind it is invented.
- Credentials, not instructions. Viewer roles,
--disable-write, Sentry’s skill list (inspectalone for strict read-only) and PagerDuty’s default read-only mode decide what the agent can touch. - Pre-declared thresholds. Recovery passes or fails against numbers written into the pull request before deploy.
- Normal delivery gates. The revert or fix goes through review, CI and the deploy pipeline like any change. See how to review an agent’s pull request.
- Named sign-off. The incident commander approves mitigation and declares recovery; service owners merge the post-mortem.
To judge the practice over a quarter, track three things per incident: minutes from page to a first sourced timeline, the share of timeline lines the audit marks VERIFIED, and post-mortem action items closed with a check attached. The agent’s own runs, costs and tool calls belong on your agent observability dashboard.
Roll the workflow out in the same order as the table at the top: read-only correlation first, then drafted updates and post-mortems, and prepared mitigations only after the team has seen the timelines hold up in several real incidents.
What breaks in AI-powered incident response, and how do you recover?
Section titled “What breaks in AI-powered incident response, and how do you recover?”The agent reports metrics it never queried. Symptom: a confident timeline with no tool calls behind it. Recovery: check /mcp (Claude Code), codex mcp list or Cursor’s MCP settings; most failures are an expired OAuth token or a missing scope. Re-run with the servers named explicitly, and reject any line without a source. The full triage is on MCP connection issues.
A stdio server exits at start. Symptom: Grafana or PagerDuty never connects. Recovery: both are Python packages, so they run with uvx, not npx; install uv on the machine. The npm package @leval/mcp-grafana is a community port, not Grafana’s server.
The Datadog server returns 401 or the wrong data. Symptom: authentication fails, or queries hit an empty org. Recovery: match the MCP host to the site in your Datadog URL; app.datadoghq.eu means mcp.datadoghq.eu.
The agent silences, acknowledges or resolves. Symptom: pages stop while users still see errors. Recovery: remove write access at the source (--disable-write, no --enable-write-tools, no Sentry triage skill) and resume paging from the incident tool.
Log text steers the agent. Symptom: the agent proposes an action that came from a log line or a ticket. Recovery: treat channel text, logs and traces as data; keep write tools out of reach, and run the injection drill from scoped AI incident triage before the agent joins a live incident.
Updates flood the channel. Symptom: people stop reading. Recovery: post only on a state change or at the agreed interval, cap each update at five lines, and let a person post.
The post-mortem blames the model. Symptom: “the AI made a mistake” as the root cause. Recovery: end the causal chain at the control that should have caught the change, such as a missing test, a permission or a review route, and follow when an agent causes an incident.
Where to go next with incident response
Section titled “Where to go next with incident response”- Monitoring and observability — the alert rules and dashboards that page you, built and tested with an agent.
- Scoped AI incident triage — the locked-down identity, allowlist and drill for the triage agent.
- Observability MCP servers — full install, OAuth scopes and context cost for Sentry, Grafana, Datadog and PostHog.
- Rehearsed rollback with human production authority — the mitigation path this page relies on.
- Disaster recovery — when the incident is a lost region or lost data, not a bad deploy.
- When an agent causes an incident — containment and attribution when the agent is the cause.