modelcontextprotocol / modelcontextprotocol/kotlin-sdk
The `onConnect` and `setNotificationHandler` callback should provide the `ServerSession`
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.
I've been trying to create a reactive listener based on per-session roots notification and found it impossible or wired.
onConnect {
sessions.forEach { (_, session) ->
session.setNotificationHandler<RootsListChangedNotification>(Method.Defined.NotificationsRootsListChanged) {
scope.launch {
session.listRoots()
// do Something with roots per session
}
CompletableDeferred()
}
}
}
I have to reset notifications for all sessions on each new session to properly get the per-session info.
Describe the solution you'd like
onConnect { session : ServerSession ->
// do something with session
}
or
server.setNotificationHandler<RootsListChangedNotification>(Method.Defined.NotificationsRootsListChanged) {session : ServerSession ->
// do something with session
}
or both.
Other infos
I suspect that the no-session-arg style onConnect and other callbacks are the legacy of the old new server per transport architecture.
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 tracing the existing onConnect and setNotificationHandler callback entry points and compare them with the ServerSession examples in the issue. Determine which callback API should receive the session, then verify that per-session roots notifications can be handled without resetting handlers for all sessions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100