Skip to content

StreamableHTTPClientTransport should handle 404 and 406 gracefully for GET SSE stream #1635

Open

Description

@ac-aashugupta

Problem

The StreamableHTTPClientTransport._startOrAuthSse() method sends a GET request to open an SSE stream during initialization. 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.

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

  • 404: Server doesn't have a GET handler for the MCP endpoint (only POST)
  • 406: Server rejects Accept: text/event-stream header (e.g., requires both application/json and text/event-stream)

Both cases mean the same thing: the server does not offer an SSE stream at the GET endpoint. But the client treats them as fatal errors, preventing the connection even though POST-based communication would work fine.

Current Behavior

// packages/client/src/client/streamableHttp.ts, _startOrAuthSse()
if (response.status === 405) {
    return;  // Only 405 is handled gracefully
}
throw new SdkError(...);  // 404 and 406 throw, killing the connection

This causes errors like:

StreamableHTTPError: Streamable HTTP error: Failed to open SSE stream: Not Found

Affected Clients

This impacts any client consuming the SDK, including:

  • Gemini CLI (google-gemini/gemini-cli) — #5268, #2787
  • MCP Inspector — #1150
  • LibreChat and other MCP consumers

Proposed Fix

Treat 404 and 406 the same as 405 — all indicate the server does not offer an SSE stream at the GET endpoint:

// 404: Server has no GET handler (only POST)
// 405: Server explicitly doesn't allow GET
// 406: Server rejects the Accept header for GET
if (response.status === 404 || response.status === 405 || response.status === 406) {
    return;
}

The client will then proceed with POST-based communication, which works correctly for these servers.

Reproduction

  1. Set up an MCP server that only supports POST (no GET SSE stream)
  2. Connect using StreamableHTTPClientTransport
  3. The GET request returns 404 → client throws and disconnects
  4. POST would have worked fine

Environment

  • @modelcontextprotocol/sdk: latest
  • Discovered while debugging Gemini CLI v0.32.1 connecting to a remote HTTP MCP server (ArmorCode)

Activity

  1. Aboudjem commented on Mar 6, 2026

    @Aboudjem

    Ran into this same thing. Looking at _startOrAuthSse() in packages/client/src/client/streamableHttp.ts (around line 240), the fix is pretty minimal -- just widen the early-return guard to include 404 and 406 alongside 405. All three mean the same thing: no SSE stream here, fall back to POST.

    I can put together a PR for this if nobody's already on it.

  2. added a commit that references this issue on Mar 6, 2026
    4729c87
  3. 4444J99 commented on Mar 27, 2026

    @4444J99

    The fix is straightforward — _startOrAuthSse() already handles 405 by returning early; 404 and 406 carry the same semantic meaning (no SSE stream available at the GET endpoint) and should follow the same path.

    I've widened the guard in _startOrAuthSse() to include all three status codes, added regression tests for 404 and 406 (same pattern as the existing 405 test), and included a changeset. PR incoming.

  4. ghost added
    bug
    on Apr 16, 2026
  5. ghost added
    ready for work
    on Apr 16, 2026
  6. ghost added
    P2
    on Apr 16, 2026
  7. ghost added
    fix proposed
    on Apr 16, 2026
  8. josuetrindade commented on Nov 29, 2026

    @josuetrindade

    I traced and implemented a minimal fix for this in StreamableHTTPClientTransport._startOrAuthSse() (packages/client/src/client/streamableHttp.ts):

    • Track whether a GET SSE stream has previously opened (_hasOpenedGetSse, reset on close()).
    • Treat HTTP 406 and initial 404 (!this._hasOpenedGetSse && response.status === 404) the same as 405 (call options.onRequestStreamEnd?.() and return without throwing SdkHttpError or firing onerror), while continuing to treat 404 after a previously opened GET SSE stream and unexpected 5xx responses as errors so reconnect failure behavior (client-transport:http:reconnect-failure-onerror) is preserved.

    Verified locally on Windows:

    • Added unit tests in packages/client/test/client/streamableHttp.test.ts (confirmed 4 new 404/406 cases fail on upstream/main and pass with the fix).
    • corepack pnpm --filter @modelcontextprotocol/client test (47 files, 1122 tests passed), corepack pnpm --filter @modelcontextprotocol/test-e2e exec vitest run scenarios/transport-http.test.ts (46 passed, 4 expected fail), build, typecheck, and lint all passed.

    Branch ready on my fork: https://github.com/josuetrindade/typescript-sdk/tree/fix/streamable-http-get-404-406

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2bugfix proposedready for work

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions