Skip to content

feat(server): expose client implementation and capabilities to handlers#733

Open
jskjw157 wants to merge 1 commit into
modelcontextprotocol:mainfrom
jskjw157:feature/issue-552-client-info
Open

feat(server): expose client implementation and capabilities to handlers#733
jskjw157 wants to merge 1 commit into
modelcontextprotocol:mainfrom
jskjw157:feature/issue-552-client-info

Conversation

@jskjw157
Copy link
Copy Markdown
Contributor

Adds clientImplementation and clientCapabilities properties on ClientConnection, delegating to what ServerSession already 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 ServerSession from the Server instance via sessionId — awkward, and easy to get wrong. This blocks two real use cases:

  • Adapting handler behavior for known client-side quirks
  • Gracefully falling back when a capability (sampling, roots, elicitation) is not advertised, instead of letting createMessage/listRoots/createElicitation fail with a non-specific IllegalStateException

How Has This Been Tested?

Integration tests in ClientConnectionTest assert both properties are populated inside tool, prompt, and resource handlers (matching the existing callAllMethods pattern that exercises every ClientConnection member).

./gradlew :integration-test:jvmTest --tests "*ClientConnectionTest"
./gradlew :kotlin-sdk-server:apiCheck
./gradlew :kotlin-sdk-server:detekt :integration-test:detekt
./gradlew :integration-test:ktlintCheck

Breaking Changes

None for consumers. Adds two abstract members to ClientConnection, which would require any external implementer to recompile — but ClientConnectionImpl is the only implementation and is internal.

A small naming note: clientImplementation matches the MCP spec's clientInfo: Implementation field as suggested in the issue. This creates temporary dual naming with the existing ServerSession.clientVersion (also an Implementation). Renaming ServerSession.clientVersion is a wider public-API change, so I left it as a follow-up unless maintainers want it bundled here.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

@jskjw157 jskjw157 force-pushed the feature/issue-552-client-info branch 2 times, most recently from ba5f1aa to ab167b0 Compare April 29, 2026 23:02
@jskjw157
Copy link
Copy Markdown
Contributor Author

@devcrocod when you get a chance — implements #552 by delegating to what ServerSession already exposes. The one open question is whether to consolidate the clientImplementation / ServerSession.clientVersion naming in this PR or leave it as a follow-up; happy either way.

Copy link
Copy Markdown
Contributor

@devcrocod devcrocod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with pr #737, the purpose of ClientConnection is not entirely clear, since properties are being added here as well
This significantly complicates the class itself and makes its responsibility less clear

/**
* The client's reported [Implementation] (name and version) after initialization.
*/
public val clientImplementation: Implementation?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could be non-null properties

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 clientImplementation and clientCapabilities properties to ClientConnection, delegated from ServerSession.
  • 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.

Comment on lines +46 to +57
/**
* 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?
Comment on lines +47 to +54
* 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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make client information available in server handlers

3 participants