Skip to content

fix(client): handle 404 and 406 gracefully in GET SSE stream#1799

Open
4444J99 wants to merge 1 commit intomodelcontextprotocol:mainfrom
4444J99:fix/graceful-get-sse-404-406
Open

fix(client): handle 404 and 406 gracefully in GET SSE stream#1799
4444J99 wants to merge 1 commit intomodelcontextprotocol:mainfrom
4444J99:fix/graceful-get-sse-404-406

Conversation

@4444J99
Copy link
Copy Markdown

@4444J99 4444J99 commented Mar 27, 2026

Motivation and Context

_startOrAuthSse() sends a GET request to open an SSE stream during start(). Per the MCP spec, the server MAY respond with 405 Method Not Allowed if it doesn't support SSE streams, and the client correctly handles this by returning early and falling back to POST-only communication.

However, many MCP servers return 404 Not Found or 406 Not Acceptable instead of 405:

  • 404: Server has no GET handler at the endpoint (only POST)
  • 406: Server rejects Accept: text/event-stream (e.g., requires both application/json and text/event-stream)

Both carry the same semantic meaning as 405: no SSE stream is available at the GET endpoint. The client currently treats them as fatal errors, preventing the connection even though POST-based communication would work fine.

This affects downstream consumers including Gemini CLI (google-gemini/gemini-cli#5268, google-gemini/gemini-cli#2787), MCP Inspector, and LibreChat.

Fixes #1635

How Has This Been Tested?

  • Added two new test cases (should handle 404 gracefully when server has no GET handler and should handle 406 gracefully when server rejects Accept header for GET) following the same pattern as the existing 405 test
  • Both verify the GET attempt is made, no error is thrown, and the transport remains functional for subsequent POST requests
  • All 313 client tests pass; typecheck and lint are clean

Breaking Changes

None.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Widen the early-return guard in _startOrAuthSse() to include 404 and
406 alongside the existing 405 check. All three status codes indicate
the server does not offer an SSE stream at the GET endpoint — the
client falls back to POST-only communication.

Fixes modelcontextprotocol#1635
@4444J99 4444J99 requested a review from a team as a code owner March 27, 2026 22:10
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 27, 2026

🦋 Changeset detected

Latest commit: 30e1d33

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@modelcontextprotocol/client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 27, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1799

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1799

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1799

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1799

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1799

commit: 30e1d33

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StreamableHTTPClientTransport should handle 404 and 406 gracefully for GET SSE stream

1 participant