Skip to content

test(node): read SSE streams until expected events arrive - #3099

Open
ruqayya-parveen wants to merge 1 commit into
modelcontextprotocol:mainfrom
ruqayya-parveen:fix/node-sse-test-chunking
Open

ruqayya-parveen wants to merge 1 commit into
modelcontextprotocol:mainfrom
ruqayya-parveen:fix/node-sse-test-chunking

Conversation

@ruqayya-parveen

@ruqayya-parveen ruqayya-parveen commented Oct 25, 2026 •

Copy link
Copy Markdown

Several streamableHttp tests called reader.read() once and asserted that multiple SSE events
shared one fetch chunk. On Node 26 fetch can deliver them in separate chunks, so the tests
failed although the transport was correct. Add a readSSEUntil helper and use it in the two
affected tests.

Fixes #2661.

Motivation and Context

packages/middleware/node/test/streamableHttp.test.ts assumed that every SSE event written by
the server arrives in the first reader.read() result. That is a property of how the runtime
chunks the response body, not of the transport. On Node v26.7.0 the events can be split across
chunks, and two tests fail before reading the later events:

  • should handle batch request messages with SSE stream for responses reads only the req-1
    event and fails before req-2.
  • should store and replay MCP server tool notifications reads an earlier {} event and fails
    before "Second notification from MCP server".

The change:

  • Adds a readSSEUntil(reader, expected, timeoutMs) test helper. It reads until the
    accumulated text contains every expected string. It throws, including the text received so far,
    if the stream ends early or the 5s timeout is hit.
  • Uses it in both tests above, including the post-reconnect read in the replay test.
  • In the replay test, takes the Last-Event-ID from the event that carries the "First
    notification" message. Before, it took the first id: in the chunk, which could belong to the
    earlier {} event.

Test-only change. No library code is touched, so no changeset.

How Has This Been Tested?

  • pnpm build:all
  • pnpm --filter @modelcontextprotocol/node test -- test/streamableHttp.test.ts passes (all 5
    test files in the package, 105 tests) on Node v22.22.2.
  • prettier --check is clean on the changed file.
  • I have not run this on Node 26, where the issue was reported, so I could not reproduce the
    original failure. The helper removes the single-chunk assumption, but confirmation on Node 26
    (locally or in CI) would be welcome.

Breaking Changes

None. Test-only change.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Only the two tests named in the issue are changed. Other tests in this file also call
reader.read() once, but they don't assert on several events at a time, so I left them alone
to keep the change small.

  • "I have read the MCP Documentation": I left it unticked. Tick it only if you've read it.
  • "Tests pass locally": I ticked it, but it only covers the node package's tests. After your
    push, the pre-push hook will have run lint, build and typecheck, so tick it only if the hook
    passed.
  • Documentation box: left unticked on purpose, since none is needed.

Several streamableHttp tests called reader.read() once and asserted that
multiple SSE events shared one fetch chunk. On Node 26 fetch can deliver
them in separate chunks, so the tests failed although the transport was
correct. Add a readSSEUntil helper and use it in the two affected tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ruqayya-parveen
ruqayya-parveen requested a review from a team as a code owner October 25, 2026 07:02
@changeset-bot

changeset-bot Bot commented Oct 25, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 2e84cfb

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 Oct 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/codemod

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

@modelcontextprotocol/core

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

@modelcontextprotocol/server

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

@modelcontextprotocol/server-legacy

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

@modelcontextprotocol/express

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

@modelcontextprotocol/fastify

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 2e84cfb

@claude claude Bot added the v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes label Oct 25, 2026

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

2 participants