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\Request;
15:
16: use Nexus\Mcp\Schema\Arrayable;
17: use Nexus\Mcp\Schema\ClientCapabilities;
18: use Nexus\Mcp\Schema\Implementation;
19: use Nexus\Mcp\Schema\Message\JsonRpcRequest;
20: use Nexus\Mcp\Schema\Message\RequestId;
21: use Nexus\Mcp\Schema\ProtocolVersion;
22:
23: /**
24: * This request is sent from the client to the server when it first connects, asking it to begin initialization.
25: *
26: * @extends JsonRpcRequest<array{
27: * jsonrpc: '2.0',
28: * id: int|non-empty-string,
29: * method: 'initialize',
30: * params: array{
31: * _meta?: array<string, mixed>,
32: * capabilities: template-type<ClientCapabilities, Arrayable, 'T'>,
33: * clientInfo: template-type<Implementation, Arrayable, 'T'>,
34: * protocolVersion: non-empty-string,
35: * },
36: * }>
37: */
38: final readonly class InitializeRequest extends JsonRpcRequest implements ClientRequest
39: {
40: /**
41: * @param ClientCapabilities $capabilities Capabilities a client may support. Known capabilities are defined here,
42: * in this schema, but this is not a closed set: any client can define its
43: * own, additional capabilities.
44: * @param Implementation $clientInfo Describes the name and version of an MCP implementation, with an optional
45: * title for UI representation.
46: * @param ProtocolVersion $protocolVersion The latest version of the Model Context Protocol that the client
47: * supports. The client MAY decide to support older versions as well.
48: * @param null|array<string, mixed> $meta Reserved by MCP to allow clients and servers to attach
49: * additional metadata to their interactions.
50: */
51: public function __construct(
52: RequestId $id,
53: ClientCapabilities $capabilities,
54: Implementation $clientInfo,
55: ProtocolVersion $protocolVersion,
56: ?array $meta = null,
57: ) {
58: parent::__construct(self::JSON_RPC_VERSION, $id, 'initialize', array_filter([
59: '_meta' => $meta,
60: 'capabilities' => $capabilities->toArray(),
61: 'clientInfo' => $clientInfo->toArray(),
62: 'protocolVersion' => $protocolVersion->__toString(),
63: ], static fn(mixed $value): bool => null !== $value));
64: }
65: }
66: