Skip to content

fix(middleware-node): accumulate SSE reads in tests instead of assuming one chunk - #2812

Open
huzaifafarooqusa-spec wants to merge 2 commits into
modelcontextprotocol:mainfrom
huzaifafarooqusa-spec:fix/sse-test-chunking-assumption
Open

huzaifafarooqusa-spec wants to merge 2 commits into
modelcontextprotocol:mainfrom
huzaifafarooqusa-spec:fix/sse-test-chunking-assumption

Conversation

@huzaifafarooqusa-spec

Copy link
Copy Markdown

Summary

streamableHttp.test.ts had two tests that call reader.read() once and assert the decoded text contains multiple SSE events, assuming Node's fetch coalesces closely-timed events into a single chunk. That assumption doesn't hold on newer Node versions, where events can arrive as separate chunks across separate reads — causing the test to fail before the later event is ever read, even though the middleware itself works correctly.

This was reported in #2661 with a clear repro and root cause (thanks to the original reporter for the diagnosis).

Fix

Adds a small readUntilContains helper that accumulates decoded text across repeated reader.read() calls until the expected substrings show up (or a timeout elapses), and uses it in:

  • should handle batch request messages with SSE stream for responses
  • should store and replay MCP server tool notifications

Testing

  • pnpm build:all
  • pnpm --filter @modelcontextprotocol/node test -- test/streamableHttp.test.ts → 102/102 passing
  • pnpm --filter @modelcontextprotocol/node exec eslint src/ → clean
  • prettier --check → clean (ran --write once to match repo style)

Closes #2661

…ng one chunk

streamableHttp.test.ts asserted on multiple SSE events after a single
reader.read() call, assuming Node's fetch would coalesce them into one
chunk. That assumption doesn't hold on newer Node versions, where
closely-timed events can arrive as separate chunks across separate
reads, failing the test before the later event is read.

Adds a readUntilContains helper that accumulates decoded text across
reads until the expected content appears (or times out), and uses it
in the two tests that were asserting on multiple SSE events from a
single read.
@huzaifafarooqusa-spec
huzaifafarooqusa-spec requested a review from a team as a code owner September 14, 2026 01:16
@changeset-bot

changeset-bot Bot commented Sep 14, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 40d497b

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 Sep 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/codemod

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

@modelcontextprotocol/core

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

@modelcontextprotocol/server

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

@modelcontextprotocol/server-legacy

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

@modelcontextprotocol/express

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

@modelcontextprotocol/fastify

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 40d497b

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7ccbd6655c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/middleware/node/test/streamableHttp.test.ts Outdated
…hand

readUntilContains only checked the deadline before calling
reader.read(). If the expected event never arrives (e.g. a batch
handler emits only one response), that read() call itself hangs
indefinitely, so the helper's advertised timeoutMs never fires and
the test instead waits for vitest's runner-level timeout.

Race each read() against a per-iteration timer so a missing event
fails at the intended deadline with the helper's diagnostic message.
huzaifafarooqusa-spec

This comment was marked as duplicate.

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