1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | namespace Nexus\Mcp\Server; |
15: | |
16: | use Nexus\Mcp\Arrayable; |
17: | |
18: | |
19: | |
20: | |
21: | |
22: | final readonly class ServerCapabilities implements \JsonSerializable, Arrayable |
23: | { |
24: | |
25: | |
26: | |
27: | |
28: | |
29: | |
30: | |
31: | |
32: | |
33: | |
34: | |
35: | |
36: | public function __construct( |
37: | public ?array $experimental = null, |
38: | public bool $logging = false, |
39: | public bool $completions = false, |
40: | public bool $prompts = false, |
41: | public ?bool $promptsListChanged = null, |
42: | public bool $resources = false, |
43: | public ?bool $resourcesSubscribe = null, |
44: | public ?bool $resourcesListChanged = null, |
45: | public bool $tools = false, |
46: | public ?bool $toolsListChanged = null, |
47: | ) {} |
48: | |
49: | |
50: | |
51: | |
52: | |
53: | |
54: | |
55: | |
56: | |
57: | |
58: | |
59: | #[\Override] |
60: | public function toArray(): array |
61: | { |
62: | $capabilities = []; |
63: | |
64: | if (null !== $this->experimental && [] !== $this->experimental) { |
65: | $capabilities['experimental'] = $this->experimental; |
66: | } |
67: | |
68: | if ($this->logging) { |
69: | $capabilities['logging'] = new \stdClass(); |
70: | } |
71: | |
72: | if ($this->completions) { |
73: | $capabilities['completions'] = new \stdClass(); |
74: | } |
75: | |
76: | if ($this->prompts || null !== $this->promptsListChanged) { |
77: | $capabilities['prompts'] = []; |
78: | |
79: | if (null !== $this->promptsListChanged) { |
80: | $capabilities['prompts']['listChanged'] = $this->promptsListChanged; |
81: | } |
82: | |
83: | $capabilities['prompts'] = (object) $capabilities['prompts']; |
84: | } |
85: | |
86: | if ($this->resources || null !== $this->resourcesSubscribe || null !== $this->resourcesListChanged) { |
87: | $capabilities['resources'] = []; |
88: | |
89: | if (null !== $this->resourcesSubscribe) { |
90: | $capabilities['resources']['subscribe'] = $this->resourcesSubscribe; |
91: | } |
92: | |
93: | if (null !== $this->resourcesListChanged) { |
94: | $capabilities['resources']['listChanged'] = $this->resourcesListChanged; |
95: | } |
96: | |
97: | $capabilities['resources'] = (object) $capabilities['resources']; |
98: | } |
99: | |
100: | if ($this->tools || null !== $this->toolsListChanged) { |
101: | $capabilities['tools'] = []; |
102: | |
103: | if (null !== $this->toolsListChanged) { |
104: | $capabilities['tools']['listChanged'] = $this->toolsListChanged; |
105: | } |
106: | |
107: | $capabilities['tools'] = (object) $capabilities['tools']; |
108: | } |
109: | |
110: | return $capabilities; |
111: | } |
112: | |
113: | |
114: | |
115: | |
116: | |
117: | |
118: | |
119: | |
120: | |
121: | |
122: | |
123: | #[\Override] |
124: | public function jsonSerialize(): object |
125: | { |
126: | return (object) $this->toArray(); |
127: | } |
128: | } |
129: | |