fix(streamable-http): map stale session 401 to status-aware error#709
Open
adam-r-kowalski wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
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
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.
Fixes #688.
This PR fixes streamable HTTP stale-session handling in the reqwest client: non-success HTTP responses are now surfaced as a status-aware transport error that preserves the HTTP status and response body (for example
401 Unauthorized: Session not found) instead of failing early withUnexpectedContentType(None)whenContent-Typeis missing.Motivation and Context
When a stale or invalid
mcp-session-idis sent to a statefulStreamableHttpService, the server correctly responds with401 Unauthorizedand a plain-text body. The client previously attempted content-type processing before handling non-success statuses, which hid the real failure asUnexpectedContentType(None).This change makes stale-session and similar non-2xx HTTP failures actionable by preserving status/body context in
UnexpectedServerResponse.How Has This Been Tested?
Tested locally with:
Added regression test:
crates/rmcp/tests/test_streamable_http_stale_session.rsStreamableHttpError::UnexpectedServerResponsecontaining status/body context.Breaking Changes
None. This is a bug fix in error mapping behavior for non-success responses.
Types of changes
Checklist
Additional context
Primary code change:
crates/rmcp/src/transport/common/reqwest/streamable_http_client.rsUnexpectedServerResponse("HTTP {status}: {body}").This preserves server intent for stale-session failures and avoids misleading content-type errors when error responses do not include a
Content-Typeheader.