1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | namespace Nexus\Mcp\Client; |
15: | |
16: | use Nexus\Mcp\Arrayable; |
17: | |
18: | |
19: | |
20: | |
21: | |
22: | final readonly class ClientCapabilities implements \JsonSerializable, Arrayable |
23: | { |
24: | |
25: | |
26: | |
27: | |
28: | |
29: | |
30: | |
31: | public function __construct( |
32: | public ?array $experimental = null, |
33: | public bool $roots = false, |
34: | public ?bool $rootsListChanged = null, |
35: | public bool $sampling = false, |
36: | public bool $elicitation = false, |
37: | ) {} |
38: | |
39: | |
40: | |
41: | |
42: | |
43: | |
44: | |
45: | |
46: | |
47: | #[\Override] |
48: | public function toArray(): array |
49: | { |
50: | $capabilities = []; |
51: | |
52: | if (null !== $this->experimental && [] !== $this->experimental) { |
53: | $capabilities['experimental'] = $this->experimental; |
54: | } |
55: | |
56: | if ($this->roots || null !== $this->rootsListChanged) { |
57: | $capabilities['roots'] = []; |
58: | |
59: | if (null !== $this->rootsListChanged) { |
60: | $capabilities['roots']['listChanged'] = $this->rootsListChanged; |
61: | } |
62: | |
63: | $capabilities['roots'] = (object) $capabilities['roots']; |
64: | } |
65: | |
66: | if ($this->sampling) { |
67: | $capabilities['sampling'] = new \stdClass(); |
68: | } |
69: | |
70: | if ($this->elicitation) { |
71: | $capabilities['elicitation'] = new \stdClass(); |
72: | } |
73: | |
74: | return $capabilities; |
75: | } |
76: | |
77: | |
78: | |
79: | |
80: | |
81: | |
82: | |
83: | |
84: | |
85: | #[\Override] |
86: | public function jsonSerialize(): object |
87: | { |
88: | return (object) $this->toArray(); |
89: | } |
90: | } |
91: | |