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\Server;
15:
16: use Nexus\Mcp\Arrayable;
17:
18: /**
19: * Capabilities that a server may support. Known capabilities are defined here, in this schema,
20: * but this is not a closed set: any server can define its own, additional capabilities.
21: */
22: final readonly class ServerCapabilities implements \JsonSerializable, Arrayable
23: {
24: /**
25: * @param null|array<string, object> $experimental Experimental, non-standard capabilities that the server supports.
26: * @param bool $logging Present if the server supports sending log messages to the client.
27: * @param bool $completions Present if the server supports argument autocompletion suggestions.
28: * @param bool $prompts Present if the server offers any prompt templates.
29: * @param null|bool $promptsListChanged Whether this server supports notifications for changes to the prompt list.
30: * @param bool $resources Present if the server offers any resources to read.
31: * @param null|bool $resourcesSubscribe Whether this server supports subscribing to resource updates.
32: * @param null|bool $resourcesListChanged Whether this server supports notifications for changes to the resource list.
33: * @param bool $tools Present if the server offers any tools to call.
34: * @param null|bool $toolsListChanged Whether this server supports notifications for changes to the tool list.
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: * @return array{
51: * experimental?: array<string, object>,
52: * logging?: object,
53: * completions?: object,
54: * prompts?: object{listChanged?: bool},
55: * resources?: object{subscribe?: bool, listChanged?: bool},
56: * tools?: object{listChanged?: bool},
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: * @return object{
115: * experimental?: array<string, object>,
116: * logging?: object,
117: * completions?: object,
118: * prompts?: object{listChanged?: bool},
119: * resources?: object{subscribe?: bool, listChanged?: bool},
120: * tools?: object{listChanged?: bool},
121: * }
122: */
123: #[\Override]
124: public function jsonSerialize(): object
125: {
126: return (object) $this->toArray();
127: }
128: }
129: