altimate-code icon indicating copy to clipboard operation
altimate-code copied to clipboard

Remote MCP server fails to connect when initial GET returns 400 instead of 405

Open kn0wsnothing opened this issue 3 months ago • 3 comments

Problem

Remote MCP servers that return HTTP 400 for the initial GET request (sent by StreamableHTTPClientTransport._startOrAuthSse()) fail to connect entirely. The SDK only gracefully handles 405 for this optional GET SSE stream endpoint.

Root cause

In @modelcontextprotocol/[email protected] (streamableHttp.js), the _startOrAuthSse() method sends a GET request with Accept: text/event-stream before the initialize POST. Per the MCP Streamable HTTP spec, this GET is optional — the server MAY return 405 to indicate it doesn't support SSE streaming.

The SDK handles this correctly for 405:

if (response.status === 405) {
    return;  // Expected — server doesn't offer GET SSE
}

But if the server returns 400 (e.g., "Missing session ID" — a valid response when no session has been established yet), the SDK falls through to:

throw new StreamableHTTPError(response.status, `Failed to open SSE stream: ${response.statusText}`);

This throws, the Streamable HTTP transport fails, the fallback SSE transport also fails (wrong transport type), and Altimate Code logs "server unavailable" key=<server> status=failed.

Reproduction

  1. Configure a remote MCP server (e.g., a FastMCP-based server on Cloud Run) that requires a session ID for GET requests
  2. The server returns 400 "Missing session ID" for GET requests without a session
  3. Altimate Code fails to connect with WARN message="server unavailable" status=failed

Direct curl test confirms the server works:

  • POST /mcp with initialize → 200 SSE response with session ID ✓
  • GET /mcp without session ID → 400 "Missing session ID" (this causes the SDK to throw)

Affected version

Altimate Code 0.9.5, MCP SDK @modelcontextprotocol/[email protected]

Suggested fix

In _startOrAuthSse(), treat 400 the same as 405 — the GET SSE stream is optional, and a 400 for a missing session before initialize is a valid response that should not cause the transport to fail. At minimum, the initial GET (when no session ID is set) should be skipped or its failure non-fatal.

Alternatively, skip the _startOrAuthSse() call entirely when this._sessionId is undefined (no session established yet), since the GET SSE endpoint requires a session to be useful.

Workaround

A local reverse proxy that returns 405 for GET requests and proxies POST requests to the real server would work around the issue, but is not a practical fix.


Metadata

Field Value
CLI Version 0.9.5
Platform darwin
Architecture arm64
OS Release 25.5.0
Category bug
Working Directory editorial-intelligence
Session ID ses_fe273aefdffeKVRGOtYcW574qX

kn0wsnothing avatar Aug 20 '26 05:08 kn0wsnothing

@kn0wsnothing Thanks for raising the issue. We will look into this and get back to you soon.

githnm avatar Aug 20 '26 05:08 githnm

Update: root cause was NOT the GET-400 — it was an expired token

After further investigation, the GET-400 theory described in this issue was wrong. The StreamableHTTPClientTransport.start() method does not send a GET request during the initial connection — it only creates an AbortController. The only network request during connect() is the POST initialize, which works fine.

The actual root cause was an expired bearer token. The token in the config had expired (30-day TTL, expired July 18). The server returned 401 on the POST initialize, which the SDK correctly threw as an error — but the error message was swallowed by Altimate Code's logging (see #1121).

We confirmed this by:

  1. Running altimate mcp list from the CLI with a fresh token → connected successfully
  2. Starting a new TUI session with the fresh token → Exodus MCP tools appeared and worked

The proxy workaround described above is no longer needed. The real fix is:

  1. #1121 — log the actual error message so a 401 "token expired" is visible, not just status=failed
  2. Monitor token expiry externally (we added a script that checks the JWT exp claim and alerts 7 days before expiry)

I'm closing this as invalid since the described root cause was incorrect.

kn0wsnothing avatar Aug 20 '26 07:08 kn0wsnothing

Closing — root cause was an expired token, not the SDK transport. The swallowed error message is tracked in #1121.

kn0wsnothing avatar Aug 20 '26 07:08 kn0wsnothing