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\Client;
15:
16: use Nexus\Mcp\Arrayable;
17:
18: /**
19: * Capabilities a client may support. Known capabilities are defined here, in this schema,
20: * but this is not a closed set: any client can define its own, additional capabilities.
21: */
22: final readonly class ClientCapabilities implements \JsonSerializable, Arrayable
23: {
24: /**
25: * @param null|array<string, object> $experimental Experimental, non-standard capabilities that the client supports.
26: * @param bool $roots Present if the client supports listing roots.
27: * @param null|bool $rootsListChanged Whether the client supports notifications for changes to the roots list.
28: * @param bool $sampling Present if the client supports sampling from an LLM.
29: * @param bool $elicitation Present if the client supports elicitation from the server.
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: * @return array{
41: * experimental?: array<string, object>,
42: * roots?: object{listChanged?: bool},
43: * sampling?: object,
44: * elicitation?: object,
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: * @return object{
79: * experimental?: array<string, object>,
80: * roots?: object{listChanged?: bool},
81: * sampling?: object,
82: * elicitation?: object,
83: * }
84: */
85: #[\Override]
86: public function jsonSerialize(): object
87: {
88: return (object) $this->toArray();
89: }
90: }
91: