fix: implement saveDiscoveryState/discoveryState on NodeOAuthClientProvider#236
Closed
mano1233 wants to merge 1 commit into
Closed
fix: implement saveDiscoveryState/discoveryState on NodeOAuthClientProvider#236mano1233 wants to merge 1 commit into
mano1233 wants to merge 1 commit into
Conversation
…ovider - Update @modelcontextprotocol/sdk from 1.25.3 to 1.27.1 - Implement saveDiscoveryState() / discoveryState() with in-memory + disk persistence (discovery_state.json) - Add 'discovery' scope to invalidateCredentials() for re-discovery on auth failures Fixes geelen/mcp-remote#231
|
I proposed a solution that reuses the same transport and therefore does not need |
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
Implement
saveDiscoveryState()/discoveryState()onNodeOAuthClientProviderto fix OAuth metadata loss in proxy mode.Root cause
In proxy mode,
connectToRemoteServer(null, ...)creates a testStreamableHTTPClientTransportthat correctly discovers_resourceMetadataUrlviaPOST → 401 → WWW-Authenticateheader. But the main transport never gets this URL, sofinishAuth()sends the token exchange to the MCP server URL instead of the authorization server — producing the"Invalid api path"error.Why the try/finally approach from #231 is fragile
It accesses
transport._resourceMetadataUrldirectly, which is a private property onStreamableHTTPClientTransport. This couplesmcp-remoteto SDK internals that could change without notice.Cleaner fix — SDK v1.27.0+ already solved this
PR modelcontextprotocol/typescript-sdk#1527 (merged Feb 13) added
saveDiscoveryState()anddiscoveryState()to theOAuthClientProviderinterface. When the test transport'sauth()call discovers the authorization server, it callsprovider.saveDiscoveryState(). When the main transport'sfinishAuth()callsauth(), it checksprovider.discoveryState()first — retrieving the cached metadata instead of re-discovering.Since both transports share the same
authProviderinstance, the discovery state propagates correctly without touching any private fields.Changes
@modelcontextprotocol/sdkfrom1.25.3→1.27.1saveDiscoveryState()/discoveryState()onNodeOAuthClientProviderwith in-memory + disk persistence (discovery_state.json)'discovery'scope toinvalidateCredentials()for re-discovery on auth failuresTest plan
pnpm run build— passespnpm run test:unit— 103/103 tests pass"Invalid api path".Fixes #231