Skip to content

Conversation

@DePasqualeOrg
Copy link

@DePasqualeOrg DePasqualeOrg commented Jan 15, 2026

While developing my Swift SDK for MCP, I encountered the following issue in the TypeScript SDK:

The StreamableHTTPClientTransport only checked for success responses (isJSONRPCResultResponse) when processing SSE stream messages. This caused two issues:

  1. Unnecessary reconnection: Error responses didn't set receivedResponse, potentially triggering reconnection attempts
  2. Missing ID remapping: Error response IDs weren't remapped during stream resumption

Solution

Handle both success and error responses when detecting stream completion and remapping IDs:

if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
    receivedResponse = true;
    if (replayMessageId !== undefined) {
        message.id = replayMessageId;
    }
}

This aligns with the MCP specification which states the SSE stream should include a "JSON-RPC response" (which per JSON-RPC 2.0 spec includes both success and error responses), and matches the Python SDK implementation.

Testing

Added test case verifying that error responses in SSE streams prevent unnecessary reconnection and are properly delivered to the message handler.

Breaking Changes

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

Handle both success (JSONRPCResultResponse) and error (JSONRPCErrorResponse)
responses for:
- Setting receivedResponse flag to prevent unnecessary reconnection
- ID remapping during stream resumption

Previously only success responses were handled, which could cause:
1. Unnecessary reconnection attempts after receiving an error response
2. Incorrect request/response correlation during stream resumption

This aligns with the Python SDK and Swift SDK implementations.
Verify that error responses (not just success responses) also:
- Set receivedResponse flag to prevent reconnection
- Get delivered to the message handler correctly
@changeset-bot
Copy link

changeset-bot bot commented Jan 15, 2026

🦋 Changeset detected

Latest commit: 6b4426a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@modelcontextprotocol/client Patch

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 15, 2026

Open in StackBlitz

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1390
npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1390

commit: 6b4426a

@DePasqualeOrg DePasqualeOrg marked this pull request as ready for review January 15, 2026 22:14
@DePasqualeOrg DePasqualeOrg requested a review from a team as a code owner January 15, 2026 22:14
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.

1 participant