-
Notifications
You must be signed in to change notification settings - Fork 881
Adding invalidateCredentials()
to OAuthClientProvider
#570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
geelen
wants to merge
1
commit into
modelcontextprotocol:main
Choose a base branch
from
geelen:invalidate-credentials
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+502
−82
Conversation
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
This was referenced May 30, 2025
I like this idea! a few notes on the approach:
alternative to avoid recursion + nested try/catch:
|
e63c5ba
to
3d1aaa6
Compare
This makes it possible to parse them from JSON, using OAUTH_ERRORS Invalidating credentials & retrying when server OAuth errors occur Updated existing tests Added some initial test coverage refactored to avoid recursion as recommended
3d1aaa6
to
ecb41f5
Compare
Updated. Available for testing on I'm going to cut an mcp-remote release using this now, since it seems to make a big difference to have any invalid data automatically cleaned |
geelen
added a commit
to geelen/mcp-remote
that referenced
this pull request
Jun 6, 2025
geelen
added a commit
to geelen/mcp-remote
that referenced
this pull request
Jun 6, 2025
geelen
added a commit
to geelen/mcp-remote
that referenced
this pull request
Jun 6, 2025
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.
From working on
mcp-remote
, I'm seeing a lot of cases where the local state and the server state drift apart. It's especially common when iterating locally (see geelen/mcp-remote#36), but seems to be happening with production servers too.The issue was that while the SDK defines a series of specific OAuthError types, they're only used on the server side of things. At the crucial point, where
POST /token
is being called and ainvalid_client
orinvalid_grant
are being received, the client simply logs that the request failed and continues: https://github.com/modelcontextprotocol/typescript-sdk/blob/main/src/client/auth.ts#L166This PR addresses this by looking for those particular error codes and invoking a new method on the
OAuthClientProvider
(if present):invalidateCredentials
. This takes an argument of'all' | 'client' | 'tokens' | 'verifier'
, but currently onlyall
andtokens
are used.How Has This Been Tested?
Some tests have been added (generated by Amp, I'm not entirely happy with them but ran out of time and wanted to submit for feedback).
mcp-remote
has been released in preview underhttps://pkg.pr.new/mcp-remote@96
with these changes and has confirmed that the errors in geelen/mcp-remote#36 are fixed.Breaking Changes
Any error other than
invalid_client
orinvalid_grant
are now re-thrown, rather than silently swallowed. But those errors were likely unrecoverable anyway so this would arguably just change the kind of crash message.Types of changes
Checklist
Additional context
Marked as draft as
main
has moved on so merging isn't possible yet. Would love reviews on the approach though. I will clean up and merge next week.