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\Result;
15:
16: use Nexus\Mcp\Schema\Arrayable;
17: use Nexus\Mcp\Schema\Implementation;
18: use Nexus\Mcp\Schema\ProtocolVersion;
19: use Nexus\Mcp\Schema\ServerCapabilities;
20:
21: /**
22: * After receiving an initialize request from the client, the server sends this response.
23: *
24: * @extends Result<array{
25: * _meta?: array<string, mixed>,
26: * capabilities: template-type<ServerCapabilities, Arrayable, 'T'>,
27: * instructions?: string,
28: * protocolVersion: string,
29: * serverInfo: template-type<Implementation, Arrayable, 'T'>,
30: * }>
31: */
32: final readonly class InitializeResult extends Result implements ServerResult
33: {
34: /**
35: * @param null|non-empty-string $instructions Instructions describing how to use the server and its features.
36: */
37: public function __construct(
38: public ProtocolVersion $protocolVersion,
39: public ServerCapabilities $capabilities,
40: public Implementation $serverInfo,
41: public ?string $instructions = null,
42: ?array $meta = null,
43: ) {
44: parent::__construct($meta);
45: }
46:
47: #[\Override]
48: public function toArray(): array
49: {
50: return array_filter([
51: '_meta' => $this->meta,
52: 'capabilities' => $this->capabilities->toArray(),
53: 'instructions' => $this->instructions,
54: 'protocolVersion' => $this->protocolVersion->__toString(),
55: 'serverInfo' => $this->serverInfo->toArray(),
56: ], static fn(mixed $value): bool => null !== $value);
57: }
58: }
59: