Add elicitation support for server-to-client user input requests (#228)

- Add ElicitAction enum (accept/decline/cancel)
- Add schema definitions for elicitation fields (string, number, boolean, enum)
- Add ElicitationSchema wrapper for requestedSchema
- Add ElicitRequest and ElicitResult for elicitation/create method
- Update ClientCapabilities to support elicitation capability
- Add elicit() method to ClientGateway
- Store client capabilities in session during initialization
- Add comprehensive unit tests
- Add elicitation example server with book_restaurant, confirm_action, and collect_feedback tools
This commit is contained in:
Johannes Wachter 2026-02-15 23:34:19 +01:00 • committed by GitHub
commit 02e86377e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -26,6 +26,7 @@ class ClientCapabilities implements \JsonSerializable
public readonly ?bool $roots = false,
public readonly ?bool $rootsListChanged = null,
public readonly ?bool $sampling = null,
public readonly ?bool $elicitation = null,
public readonly ?array $experimental = null,
) {
}
@ -36,6 +37,7 @@ class ClientCapabilities implements \JsonSerializable
* listChanged?: bool,
* },
* sampling?: bool,
* elicitation?: bool,
* experimental?: array<string, mixed>,
* } $data
*/
@ -56,10 +58,16 @@ class ClientCapabilities implements \JsonSerializable
$sampling = true;
}
$elicitation = null;
if (isset($data['elicitation'])) {
$elicitation = true;
}
return new self(
$rootsEnabled,
$rootsListChanged,
$sampling,
$elicitation,
$data['experimental'] ?? null
);
}
@ -68,6 +76,7 @@ class ClientCapabilities implements \JsonSerializable
* @return array{
* roots?: object,
* sampling?: object,
* elicitation?: object,
* experimental?: object,
* }
*/
@ -85,6 +94,10 @@ class ClientCapabilities implements \JsonSerializable
$data['sampling'] = new \stdClass();
}
if ($this->elicitation) {
$data['elicitation'] = new \stdClass();
}
if ($this->experimental) {
$data['experimental'] = (object) $this->experimental;
}