fix(client): handle 404 by clearing session ID per MCP spec#1805
Open
lanxevo3 wants to merge 3 commits intomodelcontextprotocol:mainfrom
Open
fix(client): handle 404 by clearing session ID per MCP spec#1805lanxevo3 wants to merge 3 commits intomodelcontextprotocol:mainfrom
lanxevo3 wants to merge 3 commits intomodelcontextprotocol:mainfrom
Conversation
OAuth 2.1 §3.2 requires token endpoint requests to use application/x-www-form-urlencoded regardless of grant type. Add an explicit header.set() call immediately before the fetch in executeTokenRequest() to prevent any addClientAuthentication implementation from accidentally overriding the Content-Type. Fixes modelcontextprotocol/inspector#1160
… spec Per MCP spec §Session Management (2025-03-26), when a client receives HTTP 404 in response to a request containing an Mcp-Session-Id, it MUST clear the session ID. Previously, both send() (POST) and _startOrAuthSse() (GET) would throw StreamableHTTPError without clearing _sessionId, permanently breaking the client with stale session IDs. This change: - Adds SdkErrorCode.ClientHttpNotFound - On 404, clears this._sessionId before throwing, so subsequent calls do not keep failing with the same stale session ID - Leaves full re-initialization to the caller (as InitializeRequest involves capability negotiation owned by the Client layer) Fixes modelcontextprotocol#1708.
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
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.
Per MCP spec Section "Session Management" (2025-03-26), when a client receives HTTP 404 in response to a request containing an
Mcp-Session-Id, it MUST clear the session ID. Previously, bothsend()(POST) and_startOrAuthSse()(GET) threwStreamableHTTPErrorwithout clearing_sessionId, permanently breaking SDK-based clients with stale session IDs.Changes
packages/core/src/errors/sdkErrors.ts
ClientHttpNotFound = 'CLIENT_HTTP_NOT_FOUND'error codepackages/client/src/client/streamableHttp.ts
this._sessionId = undefinedbefore throwing, so subsequent calls don't keep retrying with the same dead session IDBefore
404 with
Mcp-Session-Id→ throw error with stale session ID still set → client permanently brokenAfter
404 with
Mcp-Session-Id→ clearthis._sessionId→ throw informative error → caller can re-initialize cleanlyFixes #1708.