fix(mcp): call onclose when standalone SSE stream aborts on client disconnect#1804
Open
ctonneslan wants to merge 2 commits intohonojs:mainfrom
Open
fix(mcp): call onclose when standalone SSE stream aborts on client disconnect#1804ctonneslan wants to merge 2 commits intohonojs:mainfrom
ctonneslan wants to merge 2 commits intohonojs:mainfrom
Conversation
When a client disconnects from the GET SSE stream (network drop, process exit, etc.), the stream abort handler only cleans up internal state but never notifies the application via onclose. Since MCP clients typically do not send DELETE requests when they disconnect, the SSE stream dropping is the only signal that the client is gone. Now calls onclose when the standalone GET SSE stream (identified by the _GET_stream ID) aborts, matching the semantic intent of onclose. Fixes honojs#1762
🦋 Changeset detectedLatest commit: ac33639 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Member
|
@ctonneslan Thank you for the PR. Hey @MathurAditya724 , can you handle this? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1804 +/- ##
=======================================
Coverage 91.73% 91.73%
=======================================
Files 113 113
Lines 3785 3787 +2
Branches 957 958 +1
=======================================
+ Hits 3472 3474 +2
Misses 281 281
Partials 32 32
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Summary
Calls
onclosewhen the standalone GET SSE stream aborts (client disconnect), so applications can detect when an MCP client is gone.Problem
When a client opens a GET SSE stream and then disconnects (process exit, network drop), the transport's
stream.onAborthandler fires and cleans up#streamMapping, but the disconnection is never propagated to theonclosecallback.oncloseis only called insideclose(), which is triggered by an explicit DELETE request. In practice, MCP clients (Cursor, Claude Code, etc.) do not send DELETE when they disconnect. The SSE stream dropping is the only signal available.This means applications have no way to know when a client has gone away.
Fix
When the standalone GET SSE stream (identified by
_GET_streamID) aborts, callthis.onclose?.()to notify the application. This only fires for the standalone stream, not for per-request POST SSE streams.Changes
packages/mcp/src/streamable-http.ts: Addedonclosecall in the standalone SSE stream'sonAborthandlerFixes #1762