Skip to content

fix: add Transfer-Encoding header to SSE responses for HTTP/2 compati…#1620

Open
tinynakji wants to merge 1 commit intomodelcontextprotocol:mainfrom
tinynakji:tn/add_transfer_encoding_headers
Open

fix: add Transfer-Encoding header to SSE responses for HTTP/2 compati…#1620
tinynakji wants to merge 1 commit intomodelcontextprotocol:mainfrom
tinynakji:tn/add_transfer_encoding_headers

Conversation

@tinynakji
Copy link

…bility

Adds Transfer-Encoding: chunked header to all SSE response headers in WebStandardStreamableHTTPServerTransport to prevent HTTP/2 protocol errors.

Motivation and Context

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.

Adding Transfer-Encoding: chunked prevents this buffering behavior and ensures SSE streams work correctly over HTTP/2.

Fixes #1619

How Has This Been Tested?

  • Ran all existing streamableHttp tests across packages:
    • @modelcontextprotocol/server: 28 tests passed
    • @modelcontextprotocol/client: 38 tests passed
    • @modelcontextprotocol/node: 73 tests passed

Breaking Changes

None. This is an additive change to response headers.

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

Additional context

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

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

Reference: https://github.com/honojs/node-server/blob/main/src/listener.ts#L463-L491

@tinynakji tinynakji requested a review from a team as a code owner March 3, 2026 15:47
@changeset-bot
Copy link

changeset-bot bot commented Mar 3, 2026

⚠️ No Changeset found

Latest commit: 7127af8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 3, 2026

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/server

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

@modelcontextprotocol/express

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 07d76e4

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.

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

2 participants