Skip to content

test(node): make SSE tests robust to chunked delivery - #2833

Open
DrMkdaddy wants to merge 1 commit into
modelcontextprotocol:mainfrom
DrMkdaddy:noor/2661-sse-test-chunks
Open

DrMkdaddy wants to merge 1 commit into
modelcontextprotocol:mainfrom
DrMkdaddy:noor/2661-sse-test-chunks

Conversation

@DrMkdaddy

Copy link
Copy Markdown

Summary

packages/middleware/node/test/streamableHttp.test.ts assumed every SSE event for a response arrives in a single reader.read() chunk. On newer Node versions fetch can deliver those events in separate chunks, so the tests fail even though the transport behavior is correct.

Fixes #2661.

Changes

  • Add readSSEEventUntil(reader, predicate), which accumulates chunks with a streaming TextDecoder until the predicate matches or the stream ends.
  • Use it in the two affected tests:
    • should handle batch request messages with SSE stream for responses
    • should store and replay MCP server tool notifications (including the reconnect read)

Testing

  • Reproduced on Node v26.8.2: pnpm --filter @modelcontextprotocol/node test -- test/streamableHttp.test.ts → 2 failed, 100 passed.
  • After the change: 102 passed.
  • pnpm --filter @modelcontextprotocol/node lint passes (eslint + prettier).
  • pnpm build:all succeeds.

AI assistance

Drafted with AI assistance; I ran the reproduction, reviewed every line, and verified the fix against the full package suite.

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
@DrMkdaddy
DrMkdaddy requested a review from a team as a code owner September 19, 2026 06:07
@changeset-bot

changeset-bot Bot commented Sep 19, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 931785e

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 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/codemod

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

@modelcontextprotocol/core

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

@modelcontextprotocol/server

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

@modelcontextprotocol/server-legacy

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

@modelcontextprotocol/express

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

@modelcontextprotocol/fastify

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 931785e

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