StreamableHTTPClientTransport should handle 404 and 406 gracefully for GET SSE stream

Aberta Para iniciantes
#1,635 3 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@nanookclaw já está trabalhando nisso.

Desde 27/4/2026.

  • #1637 de @Aboudjem — fechado sem integrar
  • #1799 de @4444J99 — fechado sem integrar
  • #1969 de @nanookclaw — aberto

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
76/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Pouca atividade
Stack de tecnologia
typescript
Domínio
api, networking

Direção de pesquisa

Comece em packages/client/src/client/streamableHttp.ts, especificamente em StreamableHTTPClientTransport._startOrAuthSse(), e acompanhe como o status da resposta GET é tratado durante a inicialização. Verifique o comportamento com um servidor MCP POST-only ou com um teste de cliente focado, se disponível. Considera-se concluído quando 404 e 406, assim como 405, permitirem que a comunicação baseada em POST continue sem um erro fatal.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

bug fix proposed P2 ready for work

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)
Linguagem predominante
TypeScript
Estrelas
13.7k
Forks
2.4k
Merge médio
1d 22h
PRs com merge (30d)
18

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de modelcontextprotocol/typescript-sdk

Todas as issues de modelcontextprotocol/typescript-sdk

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.