feat(server): add onSessionClose hook to ClientConnection#737
Open
jskjw157 wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
feat(server): add onSessionClose hook to ClientConnection#737jskjw157 wants to merge 1 commit intomodelcontextprotocol:mainfrom
jskjw157 wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
Contributor
Author
|
@devcrocod follow-up to #733 — same access pattern, just delegating to the existing |
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.
Adds an
onSessionClose(block: () -> Unit)hook onClientConnection, delegating to the existing callback chain onServerSession.onClose.closes #553
Motivation and Context
Tool, prompt, and resource handlers often acquire session-scoped resources — DB connections, temporary files, background coroutines — that need to be released when the session terminates. Today there's no first-class way for a handler to register that cleanup: the only workaround is to fish the
ServerSessionout of theServerviasessionIdand call its internalonClose, which is awkward and easy to get wrong.This mirrors the access pattern from #552 (#733): expose what
ServerSessionalready does through the publicClientConnectionsurface so handlers can reach it directly.How Has This Been Tested?
Two integration tests in
ClientConnectionTest:onSessionClose callback runs when the session closes— register from a tool handler, close the client, assert the callback fires.multiple onSessionClose callbacks run in registration order— verifies the documented ordering guarantee inherited fromServerSession.onClose.Only the tool-handler case is exercised because
onSessionCloseis session-scoped — the registration site (tool vs. prompt vs. resource) doesn't change behavior, and adding three near-identical tests would just be noise.Breaking Changes
None for consumers. Adds one abstract method to
ClientConnection, which would require any external implementer to recompile — butClientConnectionImplis the only implementation and isinternal.Types of changes
Checklist