ameliabooking
/
vendor
/
wordpress
/
php-mcp-schema
/
src
/
Common
/
Protocol
/
DTO
/
InitializeResult.php
ameliabooking
/
vendor
/
wordpress
/
php-mcp-schema
/
src
/
Common
/
Protocol
/
DTO
Last commit date
Annotations.php
1 month ago
BaseMetadata.php
1 month ago
BlobResourceContents.php
1 month ago
CancelledNotification.php
1 month ago
CancelledNotificationParams.php
1 month ago
EmbeddedResource.php
1 month ago
EmptyResult.php
1 month ago
GetTaskPayloadRequest.php
1 month ago
GetTaskPayloadRequestParams.php
1 month ago
GetTaskPayloadResult.php
1 month ago
Icons.php
1 month ago
InitializeRequest.php
1 month ago
InitializeRequestParams.php
1 month ago
InitializeResult.php
1 month ago
InitializedNotification.php
1 month ago
PaginatedRequest.php
1 month ago
PaginatedRequestParams.php
1 month ago
PaginatedResult.php
1 month ago
PingRequest.php
1 month ago
ProgressNotification.php
1 month ago
ProgressNotificationParams.php
1 month ago
Result.php
1 month ago
TextResourceContents.php
1 month ago
URLElicitationRequiredError.php
1 month ago
InitializeResult.php
168 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace WP\McpSchema\Common\Protocol\DTO; |
| 6 | |
| 7 | use WP\McpSchema\Common\Lifecycle\DTO\Implementation; |
| 8 | use WP\McpSchema\Common\Traits\ValidatesRequiredFields; |
| 9 | use WP\McpSchema\Server\Lifecycle\DTO\ServerCapabilities; |
| 10 | use WP\McpSchema\Server\Lifecycle\Union\ServerResultInterface; |
| 11 | |
| 12 | /** |
| 13 | * After receiving an initialize request from the client, the server sends this response. |
| 14 | * |
| 15 | * @since 2024-11-05 |
| 16 | * @last-updated 2025-11-25 (modified properties: capabilities, serverInfo) |
| 17 | * |
| 18 | * @mcp-domain Common |
| 19 | * @mcp-subdomain Protocol |
| 20 | * @mcp-version 2025-11-25 |
| 21 | */ |
| 22 | class InitializeResult extends Result implements ServerResultInterface |
| 23 | { |
| 24 | use ValidatesRequiredFields; |
| 25 | |
| 26 | /** |
| 27 | * The version of the Model Context Protocol that the server wants to use. This may not match the version that the client requested. If the client cannot support this version, it MUST disconnect. |
| 28 | * |
| 29 | * @since 2024-11-05 |
| 30 | * |
| 31 | * @var string |
| 32 | */ |
| 33 | protected string $protocolVersion; |
| 34 | |
| 35 | /** |
| 36 | * @since 2024-11-05 |
| 37 | * |
| 38 | * @var \WP\McpSchema\Server\Lifecycle\DTO\ServerCapabilities |
| 39 | */ |
| 40 | protected ServerCapabilities $capabilities; |
| 41 | |
| 42 | /** |
| 43 | * @since 2024-11-05 |
| 44 | * |
| 45 | * @var \WP\McpSchema\Common\Lifecycle\DTO\Implementation |
| 46 | */ |
| 47 | protected Implementation $serverInfo; |
| 48 | |
| 49 | /** |
| 50 | * Instructions describing how to use the server and its features. |
| 51 | * |
| 52 | * This can be used by clients to improve the LLM's understanding of available tools, resources, etc. It can be thought of like a "hint" to the model. For example, this information MAY be added to the system prompt. |
| 53 | * |
| 54 | * @since 2024-11-05 |
| 55 | * |
| 56 | * @var string|null |
| 57 | */ |
| 58 | protected ?string $instructions; |
| 59 | |
| 60 | /** |
| 61 | * @param string $protocolVersion @since 2024-11-05 |
| 62 | * @param \WP\McpSchema\Server\Lifecycle\DTO\ServerCapabilities $capabilities @since 2024-11-05 |
| 63 | * @param \WP\McpSchema\Common\Lifecycle\DTO\Implementation $serverInfo @since 2024-11-05 |
| 64 | * @param array<string, mixed>|null $_meta @since 2024-11-05 |
| 65 | * @param string|null $instructions @since 2024-11-05 |
| 66 | */ |
| 67 | public function __construct( |
| 68 | string $protocolVersion, |
| 69 | ServerCapabilities $capabilities, |
| 70 | Implementation $serverInfo, |
| 71 | ?array $_meta = null, |
| 72 | ?string $instructions = null |
| 73 | ) { |
| 74 | parent::__construct($_meta); |
| 75 | $this->protocolVersion = $protocolVersion; |
| 76 | $this->capabilities = $capabilities; |
| 77 | $this->serverInfo = $serverInfo; |
| 78 | $this->instructions = $instructions; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Creates an instance from an array. |
| 83 | * |
| 84 | * @param array{ |
| 85 | * _meta?: array<string, mixed>|null, |
| 86 | * protocolVersion: string, |
| 87 | * capabilities: array<string, mixed>|\WP\McpSchema\Server\Lifecycle\DTO\ServerCapabilities, |
| 88 | * serverInfo: array<string, mixed>|\WP\McpSchema\Common\Lifecycle\DTO\Implementation, |
| 89 | * instructions?: string|null |
| 90 | * } $data |
| 91 | * @phpstan-param array<string, mixed> $data |
| 92 | * @return self |
| 93 | */ |
| 94 | public static function fromArray(array $data): self |
| 95 | { |
| 96 | self::assertRequired($data, ['protocolVersion', 'capabilities', 'serverInfo']); |
| 97 | |
| 98 | /** @var \WP\McpSchema\Server\Lifecycle\DTO\ServerCapabilities $capabilities */ |
| 99 | $capabilities = is_array($data['capabilities']) |
| 100 | ? ServerCapabilities::fromArray(self::asArray($data['capabilities'])) |
| 101 | : $data['capabilities']; |
| 102 | |
| 103 | /** @var \WP\McpSchema\Common\Lifecycle\DTO\Implementation $serverInfo */ |
| 104 | $serverInfo = is_array($data['serverInfo']) |
| 105 | ? Implementation::fromArray(self::asArray($data['serverInfo'])) |
| 106 | : $data['serverInfo']; |
| 107 | |
| 108 | return new self( |
| 109 | self::asString($data['protocolVersion']), |
| 110 | $capabilities, |
| 111 | $serverInfo, |
| 112 | self::asArrayOrNull($data['_meta'] ?? null), |
| 113 | self::asStringOrNull($data['instructions'] ?? null) |
| 114 | ); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Converts the instance to an array. |
| 119 | * |
| 120 | * @return array<string, mixed> |
| 121 | */ |
| 122 | public function toArray(): array |
| 123 | { |
| 124 | $result = parent::toArray(); |
| 125 | |
| 126 | $result['protocolVersion'] = $this->protocolVersion; |
| 127 | $result['capabilities'] = $this->capabilities->toArray(); |
| 128 | $result['serverInfo'] = $this->serverInfo->toArray(); |
| 129 | if ($this->instructions !== null) { |
| 130 | $result['instructions'] = $this->instructions; |
| 131 | } |
| 132 | |
| 133 | return $result; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * @return string |
| 138 | */ |
| 139 | public function getProtocolVersion(): string |
| 140 | { |
| 141 | return $this->protocolVersion; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * @return \WP\McpSchema\Server\Lifecycle\DTO\ServerCapabilities |
| 146 | */ |
| 147 | public function getCapabilities(): ServerCapabilities |
| 148 | { |
| 149 | return $this->capabilities; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * @return \WP\McpSchema\Common\Lifecycle\DTO\Implementation |
| 154 | */ |
| 155 | public function getServerInfo(): Implementation |
| 156 | { |
| 157 | return $this->serverInfo; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * @return string|null |
| 162 | */ |
| 163 | public function getInstructions(): ?string |
| 164 | { |
| 165 | return $this->instructions; |
| 166 | } |
| 167 | } |
| 168 |