1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | namespace Nexus\Mcp\Server\Message\Result; |
15: | |
16: | use Nexus\Mcp\Implementation; |
17: | use Nexus\Mcp\Message\Result; |
18: | use Nexus\Mcp\ProtocolVersion; |
19: | use Nexus\Mcp\Server\ServerCapabilities; |
20: | |
21: | |
22: | |
23: | |
24: | final readonly class InitializeResult extends Result implements ServerResult |
25: | { |
26: | |
27: | |
28: | |
29: | |
30: | |
31: | public function __construct( |
32: | public ProtocolVersion $protocolVersion, |
33: | public ServerCapabilities $capabilities, |
34: | public Implementation $serverInfo, |
35: | public ?string $instructions = null, |
36: | public ?array $meta = null, |
37: | ) {} |
38: | |
39: | |
40: | |
41: | |
42: | |
43: | |
44: | |
45: | |
46: | |
47: | |
48: | #[\Override] |
49: | public function toArray(): array |
50: | { |
51: | return array_filter([ |
52: | '_meta' => $this->meta, |
53: | 'capabilities' => $this->capabilities->toArray(), |
54: | 'instructions' => $this->instructions, |
55: | 'protocolVersion' => $this->protocolVersion->__toString(), |
56: | 'serverInfo' => $this->serverInfo->toArray(), |
57: | ], static fn(mixed $value): bool => null !== $value); |
58: | } |
59: | |
60: | |
61: | |
62: | |
63: | |
64: | |
65: | |
66: | |
67: | |
68: | |
69: | #[\Override] |
70: | public function jsonSerialize(): array |
71: | { |
72: | return $this->toArray(); |
73: | } |
74: | } |
75: | |