client: preserve OAuth discovery metadata across browser redirects#1816
Open
windro-xdd wants to merge 35 commits intomodelcontextprotocol:mainfrom
Open
client: preserve OAuth discovery metadata across browser redirects#1816windro-xdd wants to merge 35 commits intomodelcontextprotocol:mainfrom
windro-xdd wants to merge 35 commits intomodelcontextprotocol:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 317fec5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
…odelcontextprotocol#1772) Co-authored-by: jnMetaCode <147776183+jnMetaCode@users.noreply.github.com> Co-authored-by: Konstantin Konstantinov <KKonstantinov@users.noreply.github.com>
…ort (modelcontextprotocol#1763) Co-authored-by: CHOIJEWON <alsrn6040@kakao.com>
Co-authored-by: Konstantin Konstantinov <KKonstantinov@users.noreply.github.com>
…protocol#1632) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com> Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>
…delcontextprotocol#1652) Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
…delcontextprotocol#1824) Co-authored-by: Konstantin Konstantinov <KKonstantinov@users.noreply.github.com>
…extprotocol#1390) Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
modelcontextprotocol#1825) Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
pcarleton
requested changes
Mar 31, 2026
Member
pcarleton
left a comment
There was a problem hiding this comment.
Hi, you should be able to do this with loadDiscoveryState / saveDiscoveryState, could be in an example implementation of OAuthProvider
Co-authored-by: Felix Weinberger <fweinberger@anthropic.com> Co-authored-by: Konstantin Konstantinov <KKonstantinov@users.noreply.github.com> Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
…lcontextprotocol#1660) Co-authored-by: Konstantin Konstantinov <KKonstantinov@users.noreply.github.com> Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
|
@claude review |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…uestedSchema (modelcontextprotocol#1768) Co-authored-by: Konstantin Konstantinov <KKonstantinov@users.noreply.github.com>
…ansport (modelcontextprotocol#1655) Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com> Co-authored-by: Felix Weinberger <fweinberger@anthropic.com>
…odelcontextprotocol#1552) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…modelcontextprotocol#1788) Co-authored-by: Felix Weinberger <fweinberger@anthropic.com> Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
… redirects Add OAuthProvider class to enable stateful OAuth flows in browser-based applications. The provider persists discovery state (resource metadata URL, scopes) across OAuth redirects using sessionStorage with automatic 15-minute expiry, graceful degradation when storage is unavailable, and comprehensive error handling. Key features: - saveDiscoveryState/loadDiscoveryState for state persistence - Automatic timestamp-based expiry validation - getAuthorizationUrl for RFC 6749 OAuth 2.0 compatibility - Createable client transport with restored state - Graceful handling of missing sessionStorage (private browsing) - Try-catch wrapped storage operations Includes: - Full implementation with JSDoc documentation - Comprehensive test suite (state persistence, expiry, error handling) - OAuth_REDIRECT_EXAMPLE.md with usage patterns and security notes Fixes the issue of losing discovery state during browser redirects in interactive OAuth flows when implementing MCP-compatible web applications.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
resource_metadataURL andscope) in browsersessionStoragefor both Streamable HTTP and SSE client transportsfinishAuth()works after full-page redirectsfinishAuth()on both transportsWhy
finishAuth()can fail in browser redirect flows when the original transport instance is lost and theWWW-Authenticatemetadata extracted before redirect is no longer in memory. Persisting and restoring this metadata keeps token exchange on the same discovered authorization path.Validation
pnpm --filter @modelcontextprotocol/client typecheckpnpm --filter @modelcontextprotocol/client lintpnpm --filter @modelcontextprotocol/client test -- test/client/streamableHttp.test.ts test/client/sse.test.tsCloses #1234