Skip to content

fix(mcp): Tell direct-token clients to replace a rejected token - #2496

Open
sentry-junior[bot] wants to merge 2 commits into
mainfrom
fix/direct-token-401-guidance
Open

sentry-junior[bot] wants to merge 2 commits into
mainfrom
fix/direct-token-401-guidance

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

A Sentry 401 during a tool call always answered "Authorization Expired … Please re-authorize to continue." (packages/mcp-core/src/internal/error-handling.ts). That fits OAuth sessions, where onUpstreamUnauthorized revokes the grant and the client is pushed into re-auth. A Sentry-Bearer session sends its own token: the Cloudflare handler sets no onUpstreamUnauthorized for it, so there's nothing stored and nothing to re-authorize. An agent in MCP user feedback got this message on several tools in a row and couldn't act on it.

When the session has neither onUpstreamUnauthorized nor credentialRouter, the 401 now answers "Access Token Rejected": the token the client sent is expired, revoked, or invalid, the server can't refresh it, and the client should replace it (for example the Sentry-Bearer header). OAuth sessions and CLI stdio sessions keep the current message. docs/operations/security.md notes the direct-token behavior.

Open question: a CLI credential-router credential with no refresh still gets the re-authorize text. Left out to keep this scoped.

Fixes #2495

via automation evt_905b9c478746fd9deeb853f85ad7441b · Run ID dispatch_ac15be8a7fe392f735cd1a5fe054e869.

--

View Session [Sentry]

A Sentry 401 during a tool call always answered "Authorization Expired ...
Please re-authorize to continue." That fits OAuth sessions, where the
server revokes the grant and the client re-authorizes. A Sentry-Bearer
session sends its own token, so nothing on the server can re-authorize
or refresh it, and the agent was left with advice it couldn't follow.

When the session has no onUpstreamUnauthorized hook and no credential
router, the 401 now answers "Access Token Rejected" and says to replace
the token the client sends.
@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
cli Ready Ready Preview Nov 28, 2026 4:12pm UTC
sentry-local Ready Ready Preview Nov 28, 2026 4:12pm UTC

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

This PR has had no activity for 3 days. It closes in 2 days unless someone pushes, comments, or adds the WIP label.

@github-actions github-actions Bot added the Stale label Nov 28, 2026

This branch was successfully deployed

2 active deployments
Preview – cli — f1455cdf Deployed Nov 28, 2026 by vercel[bot]
Preview – sentry-local — f1455cdf Deployed Nov 28, 2026 by vercel[bot]
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 Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upstream 401 tells Sentry-Bearer clients to re-authorize, which they can't

0 participants