fix(client/streamableHttp): retry sendMessage on 401 #425
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.
After receiving a 401, attempt to
auth
. Whether the authorization works immediately or causes a redirect, retry sending the message.Motivation and Context
I'm reading between the lines of the implementation a bit: without this change, client users have to catch the
UnauthorizedError
from the first 401 and attempt calling the client method again to re-submit the failed message if and only if they also received a call to their OAuth provider'sredirectToAuthorization
call. With this change in place, if client users calltransport.finishAuth
before resolving the call toredirectToAuthorization
, message re-submission will be handled by the transport automatically.I believe this matches the intent of the API, which is that the transport should retry after re-authorizing. However, I wanted to propose the behavior change – do we expect consumers of the client to drive re-submission after authorization, or should the transport handle that internally?
How Has This Been Tested?
I tested this using a jig that creates an MCP client and connects to an (in-development) server which acts as an oauth provider.
If this behavior change is desired, I can write additional tests.
Breaking Changes
If oauthProvider clients are currently relying on driving re-submission themselves via a
catch
exception handler, this change will no longer transfer control to their exception handler.Types of changes
Checklist