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

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.
This commit is contained in:
Christopher Hertel 2026-08-15 02:11:15 +02:00 • committed by GitHub
commit c4b163b4c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -250,6 +250,23 @@ class ClientGateway
return \array_key_exists('elicitation', $capabilities);
}
/**
* Check if the connected client supports sampling.
*
* Sampling lets a server borrow the client's model during tool execution.
* This method checks the client's advertised capabilities to determine if
* sampling/createMessage requests are supported.
*
* @return bool True if the client supports sampling, false otherwise
*/
public function supportsSampling(): bool
{
$capabilities = (array) $this->session->get('client_capabilities', []);
// MCP spec: capability presence indicates support (value is typically {} or [])
return \array_key_exists('sampling', $capabilities);
}
/**
* Send a request to the client and wait for a response (blocking).
*