Sentry MCP + AI: from crash to fix PR, automatically
The problem: most crash fixes are guesses
A TypeError shows up in Sentry.
Cannot read properties of undefined (reading 'id').
The usual fix takes five minutes. Add a ?., ship it, resolve the issue, move on.
The error is gone. The bug isn’t.
The data was still missing. The user still saw a broken screen, just without the crash. And nobody knows why the data was missing in the first place, so it comes back a month later in a different component.
A real root cause analysis takes much longer. You open the Sentry issue, watch the session replay, read the trace, check the breadcrumbs, map the stack to your code, work out where the bad data came from, and check whether this release even contains the bug.
That’s a lot of tabs and a lot of context switching. So most teams skip it.
So I automated it. Not the five-minute guess. The full investigation, from Sentry issue to a reviewed fix PR.
Step 1: give your AI eyes into Sentry, (Claude Code in my case)
Sentry runs a hosted MCP server. MCP is the protocol Claude Code uses to talk to external tools, so connecting it means the agent can read Sentry directly instead of me copy-pasting stack traces.
The setup is one file committed at the repo root:
Notice what’s not in it: no token, no API key, no secret.
Each developer authenticates with their own Sentry account through OAuth. Pull the repo, open Claude Code, approve the server, run /mcp, log in. That’s the whole setup. Nothing sensitive ever touches the repo, and everyone only sees what their own Sentry access allows.
Once connected, the agent can:
- Search issues and fetch any issue, event or trace
- Search and read session replays
- Search traces and logs
- Ask Sentry’s own AI (Seer) for a second opinion
- Update an issue’s status
That’s the raw access. But access alone doesn’t produce a good RCA. An agent with Sentry access and no method will still add a ?. and call it a day.
Step 2: turn the method into a pipeline
So I wrote my investigation process as a pipeline the agent runs, in a markdown file in the repo: docs/sentry-rca-context.md. Hand it a Sentry issue ID and it runs end to end on its own: investigate, write the RCA, fix, open the PR, review.
The first step is the simplest, and it saves the most time.
Is this bug already fixed? Before investigating anything, the agent finds the release that contains the fix, then compares it with the releases the events came from. If every event came from an older bundle, the user was simply running a stale version of the app. No code change needed. Resolve the issue and move on.
That single check filters out a whole class of fake bugs.
If the bug is real, the investigation continues:
- Fetch the issue. Culprit, release, URL, and the app state captured at the moment of the crash.
- Watch the replay. What did the user click? What had loaded on screen by then?
- Read the trace. A long page load followed by a crash often means the user interacted before the data arrived.
- Read the breadcrumbs. The exact order of network calls versus user actions.
- Map it to code. Component, selector, data-fetching layer, including every fallback along the way.
- Get a second opinion. Optionally, ask Sentry’s Seer to analyse the issue independently.
- Write the RCA. (More on what that must contain below.)
- Fix it at the right layer, verify, and record the RCA.
- Open the PR with
Fixes <ISSUE-ID>in the commit, so the Sentry issue resolves automatically on merge. - Review it. The fix PR goes through the same AI PR review skill as every other PR, until it’s clean.
Attaching my article, regarding my own AI PR Review Skill, which has automated my review process and reduced my review bandwidth by about 60–70%. Link
A crash from an old bundle is closed immediately. Only real bugs go through the full investigation, and every fix still ends with a human merging it.
The rule that matters most: a nil-check is not an RCA
This line is written into the context doc in plain words, because without it every agent takes the shortcut.
Every RCA must answer:
- Trigger: what the user did that led to the crash
- Data path: API → data layer → state → selector → component → the exact crashing line
- The exact field that was missing or wrong, and its actual vs expected value
- The real payload from the backend, sanitised. Required, never guessed
- The source of the bad data: usually both a backend contract that changed and a frontend that didn’t guard against it
- Why it wasn’t caught:
git log -Sto find when the code was introduced - What’s confirmed vs inferred, clearly separated
Then the fix goes in at the right layer.
If the backend sent bad data, the frontend still ships a sensible fallback so users aren’t stuck, and the agent drafts a note for the backend team explaining the contract problem. Both sides get fixed, not just the symptom.
Step 3: give it memory with an RCA store
Every finished RCA is saved as its own markdown file in docs/rca/, with frontmatter tags:
---
component: SettingsDropdown
error_type: TypeError
root_cause: loading-race
flow: order-settings
release: v4.12.0
tags: [loading-race, premature-interaction]
---
---
component: SettingsDropdown
error_type: TypeError
root_cause: loading-race
flow: order-settings
release: v4.12.0
tags: [loading-race, premature-interaction]
---
The tags are short words for the cause, not the symptom. loading-race, not undefined-id.
Before every new investigation, the agent greps these tags first. Seen this pattern before? It reads the earlier RCA and starts from there instead of from zero.
The more RCAs you write, the faster the next one gets. Your bugs start to rhyme, and the agent notices.
Guardrails: crash data is user data
Sentry events contain real user information. So the context doc sets hard rules:
- Never paste raw Sentry dumps into an RCA, a PR or a commit. Payloads are sanitised before they’re written anywhere.
- Staging is not production. Staging issues get a fix and a PR, but no RCA file. The store stays a record of real production failures.
- No commit, push or deploy without a human saying so.
- Every fix PR goes through review, the same as code a person wrote.
The agent does the investigation. A human still decides what ships.
What I learned
Access isn’t the hard part. Method is. Connecting Sentry took one config file. Getting good RCAs took writing down exactly how a good investigation works.
Check the release before you debug. A surprising number of “bugs” come from users on an old bundle. One version comparison saves hours of hunting for something that’s already fixed.
Docs are the agent’s context. The RCA doc, the RCA store and the review skill aren’t one-off prompts. They’re files in the repo that get better over time, and every session of the agent starts from them.
Always remember, the crash is the symptom. The RCA is the fix.


