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 that a server may support. Known capabilities are defined here, in this schema,
18: * but this is not a closed set: any server can define its own, additional capabilities.
19: *
20: * @implements Arrayable<array{
21: * experimental?: array<string, object>,
22: * logging?: object,
23: * completions?: object,
24: * prompts?: object{listChanged?: bool},
25: * resources?: object{subscribe?: bool, listChanged?: bool},
26: * tools?: object{listChanged?: bool},
27: * }>
28: */
29: final readonly class ServerCapabilities implements \JsonSerializable, Arrayable
30: {
31: /**
32: * @param null|array<string, object> $experimental Experimental, non-standard capabilities that the server supports.
33: * @param bool $logging Present if the server supports sending log messages to the client.
34: * @param bool $completions Present if the server supports argument autocompletion suggestions.
35: * @param bool $prompts Present if the server offers any prompt templates.
36: * @param null|bool $promptsListChanged If this server supports notifications for changes to the prompt list.
37: * @param bool $resources Present if the server offers any resources to read.
38: * @param null|bool $resourcesSubscribe If this server supports subscribing to resource updates.
39: * @param null|bool $resourcesListChanged If this server supports notifications for changes to the resource list.
40: * @param bool $tools Present if the server offers any tools to call.
41: * @param null|bool $toolsListChanged If this server supports notifications for changes to the tool list.
42: */
43: public function __construct(
44: public ?array $experimental = null,
45: public bool $logging = false,
46: public bool $completions = false,
47: public bool $prompts = false,
48: private ?bool $promptsListChanged = null,
49: public bool $resources = false,
50: private ?bool $resourcesSubscribe = null,
51: private ?bool $resourcesListChanged = null,
52: public bool $tools = false,
53: private ?bool $toolsListChanged = null,
54: ) {}
55:
56: #[\Override]
57: public function toArray(): array
58: {
59: $capabilities = [];
60:
61: if (null !== $this->experimental && [] !== $this->experimental) {
62: $capabilities['experimental'] = $this->experimental;
63: }
64:
65: if ($this->logging) {
66: $capabilities['logging'] = new \stdClass();
67: }
68:
69: if ($this->completions) {
70: $capabilities['completions'] = new \stdClass();
71: }
72:
73: if ($this->prompts || null !== $this->promptsListChanged) {
74: $capabilities['prompts'] = [];
75:
76: if (null !== $this->promptsListChanged) {
77: $capabilities['prompts']['listChanged'] = $this->promptsListChanged;
78: }
79:
80: $capabilities['prompts'] = (object) $capabilities['prompts'];
81: }
82:
83: if ($this->resources || null !== $this->resourcesSubscribe || null !== $this->resourcesListChanged) {
84: $capabilities['resources'] = [];
85:
86: if (null !== $this->resourcesSubscribe) {
87: $capabilities['resources']['subscribe'] = $this->resourcesSubscribe;
88: }
89:
90: if (null !== $this->resourcesListChanged) {
91: $capabilities['resources']['listChanged'] = $this->resourcesListChanged;
92: }
93:
94: $capabilities['resources'] = (object) $capabilities['resources'];
95: }
96:
97: if ($this->tools || null !== $this->toolsListChanged) {
98: $capabilities['tools'] = [];
99:
100: if (null !== $this->toolsListChanged) {
101: $capabilities['tools']['listChanged'] = $this->toolsListChanged;
102: }
103:
104: $capabilities['tools'] = (object) $capabilities['tools'];
105: }
106:
107: return $capabilities;
108: }
109:
110: /**
111: * @return object{
112: * experimental?: array<string, object>,
113: * logging?: object,
114: * completions?: object,
115: * prompts?: object{listChanged?: bool},
116: * resources?: object{subscribe?: bool, listChanged?: bool},
117: * tools?: object{listChanged?: bool},
118: * }
119: */
120: #[\Override]
121: public function jsonSerialize(): object
122: {
123: return (object) $this->toArray();
124: }
125: }
126: