fix(client): keep the original error as the cause of "SSE stream disconnected" - #2948
Draft
n-satoshi061 wants to merge 1 commit into
Draft
n-satoshi061 wants to merge 1 commit into
n-satoshi061 wants to merge 1 commit into
Conversation
…onnected"
When an SSE response stream failed while being read, the transport passed
`new Error(`SSE stream disconnected: ${error}`)` to onerror, which dropped the
type and stack of the original error. The error now carries it as `cause`; the
message is unchanged.
The e2e test for `client-transport:http:body-stream-error-preserved` opened its
stream with `data: {}`, which is not a JSON-RPC message, so the first error
reaching onerror was the parse failure and the test could not pass whatever the
transport did. It now opens the stream with a comment frame, and the
requirement's knownFailures entry is removed.
🦋 Changeset detectedLatest commit: 11bc250 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
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 |
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
SSE stream disconnectederror thatStreamableHTTPClientTransportpasses toonerrornow carries the original stream error as itscause. The message is unchanged.Motivation and Context
StreamableHTTPClientTransportis reading it, the transport reportsnew Error(`SSE stream disconnected: ${error}`)toonerror.error.causeisundefined.TypeError: terminatedfrom another failure has to parse the message string.test/e2e/requirements.tslists the behaviour asclient-transport:http:body-stream-error-preserved(onerrorshould receive an error that preserves the original one, either as the instance itself or via.cause), with aknownFailuresentry describing exactly this wrapper.Error.causeonSdkError).The change:
packages/client/src/client/streamableHttp.ts: pass{ cause: error }when constructing theSSE stream disconnectederror.@modelcontextprotocol/client, patch.How Has This Been Tested?
client-transport:http:body-stream-error-preservedpass with the change and fail when only the source change is reverted.@modelcontextprotocol/clientunit tests: 997 passed.typecheckandlintpass for the client and e2e packages.Breaking Changes
None. An existing error gains a
cause; its message and class are the same, so anything matching on the message keeps working.Types of changes
Checklist
Additional context
The e2e test needed a one-line fix:
data: {}, then errors the stream, and asserts onerrors[0].{}is not a JSON-RPC message, so the transport reports the schema parse failure toonerrorfirst. The stream error arrives second.ZodError(fromdata: {})Error: SSE stream disconnected: TypeError: ...withcause === originalError: open), which produces no message and no error, soerrors[0]is the stream error.knownFailuresentry for the requirement is removed.Not included:
v1.xhas the same line (src/client/streamableHttp.ts). Not touched here; happy to send a separate PR againstv1.xif wanted.Failed to reconnect SSE stream: ...) are left as they are. The requirement only covers the body-stream error.