Skip to content

test(node): make streamable HTTP SSE tests chunk-tolerant - #3273

Open
mia03ther wants to merge 2 commits into
modelcontextprotocol:mainfrom
mia03ther:fix/2661-sse-chunk-assumption
Open

mia03ther wants to merge 2 commits into
modelcontextprotocol:mainfrom
mia03ther:fix/2661-sse-chunk-assumption

Conversation

@mia03ther

Copy link
Copy Markdown

Fixes #2661

The batch-response test (should handle batch request messages with SSE stream for responses) and the notification-replay test (should store and replay MCP server tool notifications) in packages/middleware/node/test/streamableHttp.test.ts each called reader.read() once and assumed every SSE event arrived in a single fetch chunk. On newer Node versions fetch can deliver the events in separate chunks, so the tests failed before the later events arrived even though the middleware behaved correctly.

This adds a readSSEUntil helper that keeps reading chunks until the accumulated text contains the expected event(s) (with a short timeout that cancels the stream so a missing event fails the test instead of hanging it), and uses it in the two affected tests. No production code is changed.

Verified:

  • pnpm --filter @modelcontextprotocol/node test -- test/streamableHttp.test.ts: 105 passed (streamableHttp.test.ts: 75 passed)
  • pnpm --filter @modelcontextprotocol/node check (typecheck + lint): pass

Fixes modelcontextprotocol#2661

The batch-response and notification-replay tests read the SSE
stream once and assumed every event arrived in a single fetch
chunk. On newer Node versions fetch can split the events across
chunks, so the tests failed before the later events arrived.

Add a readSSEUntil helper that keeps reading until the expected
text appears (or a short timeout cancels the stream) and use it
in the two affected tests.
@mia03ther
mia03ther requested a review from a team as a code owner December 3, 2026 10:35
@changeset-bot

changeset-bot Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8674e68

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@modelcontextprotocol/node Patch

Not sure what this means? Click here to learn what changesets are.

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

@pkg-pr-new

pkg-pr-new Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@3273

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/@modelcontextprotocol/codemod@3273

@modelcontextprotocol/core

npm i https://pkg.pr.new/@modelcontextprotocol/core@3273

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@3273

@modelcontextprotocol/server-legacy

npm i https://pkg.pr.new/@modelcontextprotocol/server-legacy@3273

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@3273

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@3273

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@3273

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@3273

commit: 8674e68

@claude claude Bot added the v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes label Dec 4, 2026
The streamable HTTP SSE tests now keep reading until the expected
event arrives instead of assuming a single fetch chunk.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streamable HTTP SSE tests assume multiple events share one fetch chunk

1 participant