Skip to content

Conversation

@evalstate
Copy link
Member

@evalstate evalstate commented Dec 10, 2025

This is a fix to the _onProgress handler to follow the exception pattern used elsewhere in the SDK. At the moment, exceptions in the handler terminate the Node process with:

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.

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.

@evalstate evalstate requested a review from a team as a code owner December 10, 2025 15:26
@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@1282

commit: 5722754

@evalstate evalstate closed this Dec 10, 2025
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