feat(server): expose client implementation and capabilities to handlers#733
feat(server): expose client implementation and capabilities to handlers#733jskjw157 wants to merge 1 commit into
Conversation
ba5f1aa to
ab167b0
Compare
ab167b0 to
03fff84
Compare
|
@devcrocod when you get a chance — implements #552 by delegating to what |
| /** | ||
| * The client's reported [Implementation] (name and version) after initialization. | ||
| */ | ||
| public val clientImplementation: Implementation? |
There was a problem hiding this comment.
These could be non-null properties
There was a problem hiding this comment.
Pull request overview
Adds handler-accessible client metadata to the server-side ClientConnection abstraction by exposing the client’s reported implementation info and capabilities captured during the initialize handshake (closes #552).
Changes:
- Add
clientImplementationandclientCapabilitiesproperties toClientConnection, delegated fromServerSession. - Update server API surface (
.api) to include the new getters. - Extend integration tests to assert both properties are visible inside tool/prompt/resource handlers.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/ClientConnection.kt | Adds new ClientConnection properties and delegates them from ServerSession in ClientConnectionImpl. |
| kotlin-sdk-server/api/kotlin-sdk-server.api | Updates API dump to reflect the new interface members. |
| integration-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/server/ClientConnectionTest.kt | Adds integration assertions that the new properties are populated within handlers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /** | ||
| * The client's reported [Implementation] (name and version) after initialization. | ||
| */ | ||
| public val clientImplementation: Implementation? | ||
|
|
||
| /** | ||
| * The client's reported [ClientCapabilities] after initialization. | ||
| * | ||
| * Consult before invoking [createMessage], [listRoots], or [createElicitation] | ||
| * to fall back gracefully when a capability is not advertised. | ||
| */ | ||
| public val clientCapabilities: ClientCapabilities? |
| * The client's reported [Implementation] (name and version) after initialization. | ||
| */ | ||
| public val clientImplementation: Implementation? | ||
|
|
||
| /** | ||
| * The client's reported [ClientCapabilities] after initialization. | ||
| * | ||
| * Consult before invoking [createMessage], [listRoots], or [createElicitation] |
Adds
clientImplementationandclientCapabilitiesproperties onClientConnection, delegating to whatServerSessionalready tracks during the initialize handshake.closes #552
Motivation and Context
Server handlers (tools, prompts, resources) currently have no first-class way to read the connected client's name/version or advertised capabilities. The only workaround is to extract the full
ServerSessionfrom theServerinstance viasessionId— awkward, and easy to get wrong. This blocks two real use cases:createMessage/listRoots/createElicitationfail with a non-specificIllegalStateExceptionHow Has This Been Tested?
Integration tests in
ClientConnectionTestassert both properties are populated inside tool, prompt, and resource handlers (matching the existingcallAllMethodspattern that exercises everyClientConnectionmember).Breaking Changes
None for consumers. Adds two abstract members to
ClientConnection, which would require any external implementer to recompile — butClientConnectionImplis the only implementation and isinternal.A small naming note:
clientImplementationmatches the MCP spec'sclientInfo: Implementationfield as suggested in the issue. This creates temporary dual naming with the existingServerSession.clientVersion(also anImplementation). RenamingServerSession.clientVersionis a wider public-API change, so I left it as a follow-up unless maintainers want it bundled here.Types of changes
Checklist