Skip to content

Conversation

@evalstate
Copy link
Member

This is a fix to the _onProgress handler to follow the exception pattern used elsewhere in the SDK.

Motivation and Context

Specific scenario is usage in a proxy scenario, where Progress Notifications are relayed from the Server to the Client, and the Client disconnects with a close handler. At the moment, exceptions in the on progress handler terminate the Node process with:

Error: Not connected
    at Server.notification (/home/shaun/source/typescript-sdk/src/shared/protocol.ts:1282:19)
    at <anonymous> (/home/shaun/source/typescript-sdk/src/examples/server/disconnectTestServer.ts:43:35)
    at async McpServer.executeToolHandler (/home/shaun/source/typescript-sdk/src/server/mcp.ts:352:20)
    at async <anonymous> (/home/shaun/source/typescript-sdk/src/server/mcp.ts:214:32)
    at async wrappedHandler (/home/shaun/source/typescript-sdk/src/server/index.ts:262:32)

To demonstrate the failure:
tsx src/examples/client/disconnectTestServer.ts
tsx src/examples/client/disconnectTestClient.ts

The Client terminates after 5 notifications, triggering the error condition.

Server output after fix:

Sending notification 4/10
Sending notification 5/10
Client disconnected unexpectedly
Transport closed for session: 3de16462-5919-4760-9fb0-a38cd8496b4a
Sending notification 6/10
[onerror] Not connected
Sending notification 7/10
[onerror] Not connected
Sending notification 8/10
[onerror] Not connected
Sending notification 9/10
[onerror] Not connected
Sending notification 10/10
[onerror] Not connected
[onerror] Failed to send response: Error: No connection established for request ID: 1

Notes on the test programs:

  • If you don't have a close handler you don't see the exception
  • There is an abort controller flag which is the "correct" way to do this (start with --abort to use it) which also avoids the process termination, but could be missed in a production scenario.

Consistent error handling, not terminating the Node process unexpec

How Has This Been Tested?

Local testing, sample Server and Client provided to show failure and fix (discardable on merge)

Breaking Changes

No

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

@evalstate evalstate requested a review from a team as a code owner December 10, 2025 16:00
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 10, 2025

Open in StackBlitz

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/sdk@1283

commit: 8a41031

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