Skip to content

fix(mcp): Name the missing scopes when Sentry answers 403 insufficient_scope - #2222

Merged
BYK merged 5 commits into
mainfrom
fix/insufficient-scope-403
Nov 13, 2026
Merged

BYK merged 5 commits into
mainfrom
fix/insufficient-scope-403

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2208.

When a token lacks the scope an endpoint needs, Sentry returns a 403 with DRF's generic detail and lists the accepted scopes only in WWW-Authenticate: Bearer error="insufficient_scope", scope="...". The MCP dropped that header and showed the generic Input Error template ("…address the concern and try again"), which can't work with the same token. For example, starting autofix in analyze_issue_with_seer needs event:write, event:admin, or seer:write. Sentry already sends the challenge for that endpoint (getsentry/sentry#118612), so no backend change is needed.

@sentry/api 1.83.0 (getsentry/sentry-api-schema#146) reads the header in the shared request core: ApiPermissionError.acceptedScopes holds the scopes, and its toUserMessage() names them. This PR bumps to 1.83.0 and uses that:

  • MCP: formatErrorForUser returns a Missing Permission message that names the accepted scopes and says retrying with the same token won't help. It also finds the error when a tool rewrapped it as cause (e.g. withApiErrorHandling's UserInputError). Embedded agent tools get the same message, without the "try again" advice.
  • CLI: the CLI already turned this challenge into scope guidance on its own request path. It now uses the shared parseInsufficientScopeChallenge instead of a local copy, so behavior is the same. sentry mcp gets the MCP fix through mcp-core.

The message only names the scopes the endpoint accepts, which are the same for every caller. Nothing about the user, role, org, or token is added. A role-based 403 has no challenge and keeps the old message.

Out of scope: analyze_issue_with_seer still declares requiredScopes: []. Gating the tool on event:write would hide it from grants that can read Seer results, so that's a product call for a separate change.

via @BYK.

--

View Session [Sentry]

…t_scope

Sentry names the scopes an endpoint accepts only in a 403's
WWW-Authenticate insufficient_scope challenge. The MCP dropped it and
told agents to fix their input and try again, which cannot work with the
same token (93 analyze_issue_with_seer calls across 9 orgs in 14 days).

@sentry/api now carries the scopes on ApiPermissionError.acceptedScopes.
formatErrorForUser and embedded agent tools return a Missing Permission
message that names them and says retrying won't help, also when a tool
rewrapped the error. The CLI drops its copy of the challenge parser for
the shared one; the CLI's own 403 guidance is unchanged, and its MCP
server gets the fix through mcp-core.

Fixes #2208

Co-Authored-By: Claude <[email protected]>
@vercel

vercel Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
sentry-local Ready Ready Preview Nov 13, 2026 12:29am UTC

Request Review

sentry-junior Bot and others added 2 commits November 12, 2026 23:39
1.83.0 carries the insufficient_scope challenge's scopes on
ApiPermissionError.acceptedScopes (getsentry/sentry-api-schema#146).

Co-Authored-By: Claude <[email protected]>
…e-403

# Conflicts:
#	packages/mcp-core/src/internal/error-handling.test.ts
#	packages/mcp-core/src/internal/error-handling.ts
@sentry-junior
sentry-junior Bot marked this pull request as ready for review November 13, 2026 07:36
@sentry-junior
sentry-junior Bot requested a review from BYK November 13, 2026 07:36
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 13, 2026

This branch was successfully deployed

2 active deployments
Preview — e202c080 Deployed Nov 13, 2026 by vercel[bot]
Actions — e202c080 Deployed Nov 13, 2026 by sentry-junior[bot] via eval #1851
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

403 tool errors drop Sentry's insufficient_scope challenge

1 participant