Conversation
The Streamable HTTP SSE tests assumed every event for a response arrives in a single reader.read() chunk. fetch may deliver them in separate chunks, so the tests failed on newer Node versions even though the transport behavior was correct. Add readSSEEventUntil(), which accumulates chunks with a streaming TextDecoder until a predicate matches or the stream ends, and use it in the batch-response and notification-replay tests. Fixes modelcontextprotocol#2661
|
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@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.
Summary
packages/middleware/node/test/streamableHttp.test.tsassumed every SSE event for a response arrives in a singlereader.read()chunk. On newer Node versionsfetchcan deliver those events in separate chunks, so the tests fail even though the transport behavior is correct.Fixes #2661.
Changes
readSSEEventUntil(reader, predicate), which accumulates chunks with a streamingTextDecoderuntil the predicate matches or the stream ends.should handle batch request messages with SSE stream for responsesshould store and replay MCP server tool notifications(including the reconnect read)Testing
pnpm --filter @modelcontextprotocol/node test -- test/streamableHttp.test.ts→ 2 failed, 100 passed.pnpm --filter @modelcontextprotocol/node lintpasses (eslint + prettier).pnpm build:allsucceeds.AI assistance
Drafted with AI assistance; I ran the reproduction, reviewed every line, and verified the fix against the full package suite.