Skip to content

[Server] Add ClientGateway::supportsSampling() - #418

Merged
chr-hertel merged 1 commit into
modelcontextprotocol:mainfrom
chr-hertel:client-gateway-supports-sampling
Aug 15, 2026
Merged

[Server] Add ClientGateway::supportsSampling()#418
chr-hertel merged 1 commit into
modelcontextprotocol:mainfrom
chr-hertel:client-gateway-supports-sampling

Conversation

@chr-hertel

Copy link
Copy Markdown
Member

Sampling was the one client capability a tool could not check before asking.

supportsRoots() and supportsElicitation() both read the capabilities the client advertised during the handshake. Sampling is stored in that same session data — ClientCapabilities::jsonSerialize() emits it alongside roots and elicitation — but had no accessor, so a tool had to issue the request and catch the refusal:

// before
try {
    $result = $context->getClientGateway()->sample($prompt);
} catch (ClientException) {
    // client cannot sample
}

// after
if ($context->getClientGateway()->supportsSampling()) {
    $result = $context->getClientGateway()->sample($prompt);
}

Four lines mirroring supportsElicitation(), plus unit tests matching the existing supportsRoots pair.

🤖 Generated with Claude Code

Sampling was the one client capability a tool could not check before asking.
`supportsRoots()` and `supportsElicitation()` both read the capabilities the
client advertised during the handshake; sampling is stored in that same session
data but had no accessor, so a tool had to issue the request and catch the
refusal.
@chr-hertel
chr-hertel requested a lite review from Copilot August 14, 2026 23:43
@chr-hertel chr-hertel added Server Issues & PRs related to the Server component enhancement Request for a new feature that's not currently supported labels Aug 14, 2026

Copilot AI left a comment

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.

Pull request overview

Adds a server-side capability accessor for client sampling support, enabling tools to check the client’s advertised sampling capability before attempting sampling/createMessage requests (consistent with existing supportsRoots() / supportsElicitation() patterns).

Changes:

  • Add ClientGateway::supportsSampling() which reads the advertised client_capabilities session data.
  • Add unit tests covering supportsSampling() returning true/false based on advertised capabilities.
  • Document the new accessor in the changelog for the next release.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/Server/ClientGateway.php Adds supportsSampling() to check for the sampling capability in session-stored client capabilities.
tests/Unit/Server/ClientGatewayTest.php Adds tests verifying supportsSampling() behavior when sampling is present/absent.
CHANGELOG.md Notes the addition of ClientGateway::supportsSampling() and its intended usage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@chr-hertel
chr-hertel merged commit c4b163b into modelcontextprotocol:main Aug 15, 2026
18 checks passed
@chr-hertel
chr-hertel deleted the client-gateway-supports-sampling branch August 15, 2026 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Request for a new feature that's not currently supported Server Issues & PRs related to the Server component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants