modelcontextprotocol / modelcontextprotocol/kotlin-sdk
Add a way to register session cleanup actions from server handlers
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 1.5k
- Forks
- 248
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 23
Description
Is your feature request related to a problem? Please describe.
Some tools need to create long-lived resources, that may be queried in the future by other tools or interactions. Currently, it is impossible to clean these resources up when a MCP session ends.
Describe the solution you'd like
Add a onSessionClose method to ClientConnection, that adds the close handler to the ServerSession.
Describe alternatives you've considered
This can be somewhat worked around by using the session ID to get the session from the server, but it's ugly and awkward. Even the server isn't easily accessible from the handlers.
Additional context
Add any other context or screenshots about the feature request here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the ClientConnection and ServerSession definitions to trace how server handlers access the session lifecycle. Implement the requested registration path and verify that registered cleanup actions run when the MCP session closes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100