HttpClientStreamHttpTransport: add authorization error handler#861
Open
HttpClientStreamHttpTransport: add authorization error handler#861
Conversation
1ccce75 to
f8c77f9
Compare
f8c77f9 to
e0c1225
Compare
chemicL
requested changes
Mar 10, 2026
Member
chemicL
left a comment
There was a problem hiding this comment.
I like the overall design. I have a couple of suggestions regarding method names and also the blocking avoidance in the sync implementation. Feel free to merge once these are addressed. Thanks!
...modelcontextprotocol/client/transport/customizer/McpHttpClientAuthorizationErrorHandler.java
Show resolved
Hide resolved
...modelcontextprotocol/client/transport/customizer/McpHttpClientAuthorizationErrorHandler.java
Outdated
Show resolved
Hide resolved
...modelcontextprotocol/client/transport/customizer/McpHttpClientAuthorizationErrorHandler.java
Outdated
Show resolved
Hide resolved
64106af to
4861c93
Compare
7e30b31 to
9e3a897
Compare
- Closes #240 Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
9e3a897 to
fa1861e
Compare
chemicL
requested changes
Mar 12, 2026
Member
chemicL
left a comment
There was a problem hiding this comment.
I like the changes, thanks. One type change request and one test request :)
| * @return a {@link Publisher} to signal either an error or a retry | ||
| */ | ||
| default Publisher<Void> onAuthorizationError(HttpResponse.ResponseInfo responseInfo, McpTransportContext context, | ||
| Publisher<Void> retryAction, Publisher<Void> defaultError) { |
Member
There was a problem hiding this comment.
For the default error:
- currently the exception is eagerly created so there is no need for wrapping it in a Mono
- instead, a Supplier can be used which would lazily be evaluated and would capture the actual stack at invocation time.
| * If the returned {@link Publisher} errors, the error will be propagated to the | ||
| * calling method, to be handled by the caller. | ||
| * <p> | ||
| * The caller is responsible for bounding the number of retries. |
Member
There was a problem hiding this comment.
Can you add a test that shows how one would limit the retries? We should follow-up with another PR for the documentation about this case I suppose.
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.
Motivation and Context
In the context of authorization management, we need to handle authorization errors (HTTP 401 and 403) in the client transports. This PR introduces a hook to react to these specific errors. See gh-240.
The hook exposes a "retry" mechanism, so that handlers can decide the request must be replayed, for example, after performing a dynamic client registration, or after updating the scopes in the "step up" scenario. The retry mechanism is unbounded, retry limitation is the caller's responsibility.
This PR does not target the SSE transport as we don't intend to evolve it.
How Has This Been Tested?
Test with spring's
mcp-securityproject.Breaking Changes
n/a
Types of changes