[Schema][Server] Harden sampling tools against the spec (#420)

* harden sampling tools against the spec

Report tool-flow violations as -32602 instead of dropping the request,
accept resource_link in tool results, gate tools on sampling.tools, and
reject empty content.

* normalize keyed content arrays to lists

array_filter() and friends preserve keys, and a keyed array serializes as a
JSON object instead of the content-block array the schema requires.
This commit is contained in:
Christopher Hertel 2026-08-15 04:13:53 +02:00 • committed by GitHub
commit 43815e38a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -21,7 +21,12 @@ class ClientCapabilities implements \JsonSerializable
{
/**
* @param array<string, mixed> $experimental
* @param ?array<string, mixed> $extensions protocol extensions the client supports (e.g. io.modelcontextprotocol/ui)
* @param ?array<string, mixed> $extensions protocol extensions the client supports (e.g. io.modelcontextprotocol/ui)
* @param ?bool $samplingContext the `sampling.context` sub-capability
* @param ?bool $samplingTools the `sampling.tools` sub-capability
*
* The two sampling sub-capabilities trail `extensions` rather than sitting next to
* `sampling` so that existing positional calls keep working. Pass them by name.
*/
public function __construct(
public readonly ?bool $roots = false,