Skip to content

mcp: handle oauth2.RetrieveError during token refresh#917

Open
smlx wants to merge 1 commit intomodelcontextprotocol:mainfrom
smlx:simple-receiveerror
Open

mcp: handle oauth2.RetrieveError during token refresh#917
smlx wants to merge 1 commit intomodelcontextprotocol:mainfrom
smlx:simple-receiveerror

Conversation

@smlx
Copy link
Copy Markdown

@smlx smlx commented Apr 30, 2026

Previously, an expired refresh token in the oauth2.Token returned from OAuthHandler.TokenSource() would cause the connection to fail.

From the client perspective, this meant that the MCP connection was in a hard-failed state with no way to re-authorize.

The change in this commit causes Authorize() to be called in the event of both an oauth2.RetrieveError from the token endpoint, as well as in the pre-existing case of a 401/403 HTTP response from the MCP server. Clients will handle this in their existing Authorize() flows to get a new valid token for the connection.

Supersedes and closes: #909.

Comment thread mcp/streamable.go Outdated
Previously, an expired refresh token in the oauth2.Token returned from
OAuthHandler.TokenSource() would cause the connection to fail.

From the client perspective, this meant that the MCP connection was in a
hard-failed state with no way to re-authorize.

The change in this commit causes Authorize() to be called in the event
of both an oauth2.RetrieveError from the token endpoint, as well as in
the pre-existing case of a 401/403 HTTP response from the MCP server.
Clients will handle this in their existing Authorize() flows to get a
new valid token for the connection.
@smlx smlx force-pushed the simple-receiveerror branch from 22b64f3 to b5e4148 Compare May 1, 2026 02:27
@smlx smlx requested a review from yarolegovich May 1, 2026 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants