Skip to content

SSE streams cause HTTP/2 PROTOCOL_ERROR with some HTTP adapters (e.g., @hono/node-server) #1619

@tinynakji

Description

@tinynakji

Description

Some HTTP adapters (e.g., @hono/node-server) buffer small SSE responses and automatically add a Content-Length header. When the SSE stream closes, this causes an HTTP/2 PROTOCOL_ERROR because HTTP/2 doesn't allow Content-Length with streaming responses.

Reproduction

  1. Use WebStandardStreamableHTTPServerTransport with @hono/node-server over HTTP/2
  2. Perform an MCP operation that returns a small SSE response
  3. Observe PROTOCOL_ERROR on stream close

Expected Behavior

SSE streams should work correctly over HTTP/2 without protocol errors.

Proposed Fix

Add Transfer-Encoding: chunked header to all SSE responses in WebStandardStreamableHTTPServerTransport. This prevents HTTP adapters from buffering and adding Content-Length.

Affected locations in packages/server/src/server/streamableHttp.ts:

  • handleGetRequest method (~line 450)
  • replayEvents method (~line 507)
  • handlePostRequest method (~line 757)

Additional Context

Reference: https://github.com/honojs/node-server/blob/main/src/listener.ts#L463-L491 (Hono's buffering logic)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions