1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus MCP SDK package.
7: *
8: * (c) 2025 John Paul E. Balandan, CPA <paulbalandan@gmail.com>
9: *
10: * For the full copyright and license information, please view
11: * the LICENSE file that was distributed with this source code.
12: */
13:
14: namespace Nexus\Mcp\Schema;
15:
16: /**
17: * Capabilities a client may support. Known capabilities are defined here, in this schema,
18: * but this is not a closed set: any client can define its own, additional capabilities.
19: *
20: * @implements Arrayable<array{
21: * experimental?: array<string, object>,
22: * roots?: object{listChanged?: bool},
23: * sampling?: object,
24: * elicitation?: object,
25: * }>
26: */
27: final readonly class ClientCapabilities implements \JsonSerializable, Arrayable
28: {
29: /**
30: * @param null|array<string, object> $experimental Experimental, non-standard capabilities that the client supports.
31: * @param bool $roots Present if the client supports listing roots.
32: * @param null|bool $rootsListChanged Whether the client supports notifications for changes to the roots list.
33: * @param bool $sampling Present if the client supports sampling from an LLM.
34: * @param bool $elicitation Present if the client supports elicitation from the server.
35: */
36: public function __construct(
37: public ?array $experimental = null,
38: public bool $roots = false,
39: private ?bool $rootsListChanged = null,
40: public bool $sampling = false,
41: public bool $elicitation = false,
42: ) {}
43:
44: #[\Override]
45: public function toArray(): array
46: {
47: $capabilities = [];
48:
49: if (null !== $this->experimental && [] !== $this->experimental) {
50: $capabilities['experimental'] = $this->experimental;
51: }
52:
53: if ($this->roots || null !== $this->rootsListChanged) {
54: $capabilities['roots'] = [];
55:
56: if (null !== $this->rootsListChanged) {
57: $capabilities['roots']['listChanged'] = $this->rootsListChanged;
58: }
59:
60: $capabilities['roots'] = (object) $capabilities['roots'];
61: }
62:
63: if ($this->sampling) {
64: $capabilities['sampling'] = new \stdClass();
65: }
66:
67: if ($this->elicitation) {
68: $capabilities['elicitation'] = new \stdClass();
69: }
70:
71: return $capabilities;
72: }
73:
74: /**
75: * @return object{
76: * experimental?: array<string, object>,
77: * roots?: object{listChanged?: bool},
78: * sampling?: object,
79: * elicitation?: object,
80: * }
81: */
82: #[\Override]
83: public function jsonSerialize(): object
84: {
85: return (object) $this->toArray();
86: }
87: }
88: