modelcontextprotocol / modelcontextprotocol/kotlin-sdk

Add a way to register session cleanup actions from server handlers

Open
#553 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

api enhancement P2 ready for work
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.