Skip to content

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

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

mia03ther wants to merge 1 commit 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

⚠️ No Changeset found

Latest commit: 207e49f

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

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: 207e49f

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

None yet

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