fix: add Transfer-Encoding header to SSE responses for HTTP/2 compati…#1620
Open
tinynakji wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
fix: add Transfer-Encoding header to SSE responses for HTTP/2 compati…#1620tinynakji wants to merge 1 commit intomodelcontextprotocol:mainfrom
tinynakji wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…bility
Adds
Transfer-Encoding: chunkedheader to all SSE response headers inWebStandardStreamableHTTPServerTransportto prevent HTTP/2 protocol errors.Motivation and Context
Some HTTP adapters (e.g.,
@hono/node-server) buffer small SSE responses and automatically add aContent-Lengthheader. When the SSE stream closes, this causes an HTTP/2PROTOCOL_ERRORbecause HTTP/2 doesn't allowContent-Lengthwith streaming responses.Adding
Transfer-Encoding: chunkedprevents this buffering behavior and ensures SSE streams work correctly over HTTP/2.Fixes #1619
How Has This Been Tested?
@modelcontextprotocol/server: 28 tests passed@modelcontextprotocol/client: 38 tests passed@modelcontextprotocol/node: 73 tests passedBreaking Changes
None. This is an additive change to response headers.
Types of changes
Checklist
Additional context
Affected locations in
packages/server/src/server/streamableHttp.ts:handleGetRequestmethod (~line 450)replayEventsmethod (~line 507)handlePostRequestmethod (~line 757)Reference: https://github.com/honojs/node-server/blob/main/src/listener.ts#L463-L491