PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.4.3
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.4.3
3.4.3 3.4.2 3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 All 196 releases
convertkit / vendor / wordpress / php-mcp-schema / src / Common / Protocol / DTO / InitializeResult.php

InitializeResult.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 3.4.3, at vendor/wordpress/php-mcp-schema/src/Common/Protocol/DTO/InitializeResult.php

178 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 * Wire keys this class models. Anything else is kept in $additionalProperties.
28 *
29 * @var array<int, string>
30 */
31 private const KNOWN_KEYS = ['_meta', 'protocolVersion', 'capabilities', 'serverInfo', 'instructions'];
32
33 /**
34 * 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.
35 *
36 * @since 2024-11-05
37 *
38 * @var string
39 */
40 protected string $protocolVersion;
41
42 /**
43 * @since 2024-11-05
44 *
45 * @var \WP\McpSchema\Server\Lifecycle\DTO\ServerCapabilities
46 */
47 protected ServerCapabilities $capabilities;
48
49 /**
50 * @since 2024-11-05
51 *
52 * @var \WP\McpSchema\Common\Lifecycle\DTO\Implementation
53 */
54 protected Implementation $serverInfo;
55
56 /**
57 * Instructions describing how to use the server and its features.
58 *
59 * 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.
60 *
61 * @since 2024-11-05
62 *
63 * @var string|null
64 */
65 protected ?string $instructions;
66
67 /**
68 * @param string $protocolVersion @since 2024-11-05
69 * @param \WP\McpSchema\Server\Lifecycle\DTO\ServerCapabilities $capabilities @since 2024-11-05
70 * @param \WP\McpSchema\Common\Lifecycle\DTO\Implementation $serverInfo @since 2024-11-05
71 * @param array<string, mixed>|null $_meta @since 2024-11-05
72 * @param string|null $instructions @since 2024-11-05
73 * @param array<string, mixed>|null $additionalProperties
74 */
75 public function __construct(
76 string $protocolVersion,
77 ServerCapabilities $capabilities,
78 Implementation $serverInfo,
79 ?array $_meta = null,
80 ?string $instructions = null,
81 ?array $additionalProperties = null
82 ) {
83 parent::__construct($_meta, $additionalProperties);
84 $this->protocolVersion = $protocolVersion;
85 $this->capabilities = $capabilities;
86 $this->serverInfo = $serverInfo;
87 $this->instructions = $instructions;
88 }
89
90 /**
91 * Creates an instance from an array.
92 *
93 * @param array{
94 * _meta?: array<string, mixed>|null,
95 * protocolVersion: string,
96 * capabilities: array<string, mixed>|\WP\McpSchema\Server\Lifecycle\DTO\ServerCapabilities,
97 * serverInfo: array<string, mixed>|\WP\McpSchema\Common\Lifecycle\DTO\Implementation,
98 * instructions?: string|null
99 * } $data
100 * @phpstan-param array<string, mixed> $data
101 * @return self
102 */
103 public static function fromArray(array $data): self
104 {
105 self::assertRequired($data, ['protocolVersion', 'capabilities', 'serverInfo']);
106
107 /** @var \WP\McpSchema\Server\Lifecycle\DTO\ServerCapabilities $capabilities */
108 $capabilities = is_array($data['capabilities'])
109 ? ServerCapabilities::fromArray(self::asArray($data['capabilities']))
110 : $data['capabilities'];
111
112 /** @var \WP\McpSchema\Common\Lifecycle\DTO\Implementation $serverInfo */
113 $serverInfo = is_array($data['serverInfo'])
114 ? Implementation::fromArray(self::asArray($data['serverInfo']))
115 : $data['serverInfo'];
116
117 return new self(
118 self::asString($data['protocolVersion']),
119 $capabilities,
120 $serverInfo,
121 self::asArrayOrNull($data['_meta'] ?? null),
122 self::asStringOrNull($data['instructions'] ?? null),
123 self::additionalFields($data, self::KNOWN_KEYS)
124 );
125 }
126
127 /**
128 * Converts the instance to an array.
129 *
130 * @return array<string, mixed>
131 */
132 public function toArray(): array
133 {
134 $result = parent::toArray();
135
136 $result['protocolVersion'] = $this->protocolVersion;
137 $result['capabilities'] = $this->capabilities->toArray();
138 $result['serverInfo'] = $this->serverInfo->toArray();
139 if ($this->instructions !== null) {
140 $result['instructions'] = $this->instructions;
141 }
142
143 return $result;
144 }
145
146 /**
147 * @return string
148 */
149 public function getProtocolVersion(): string
150 {
151 return $this->protocolVersion;
152 }
153
154 /**
155 * @return \WP\McpSchema\Server\Lifecycle\DTO\ServerCapabilities
156 */
157 public function getCapabilities(): ServerCapabilities
158 {
159 return $this->capabilities;
160 }
161
162 /**
163 * @return \WP\McpSchema\Common\Lifecycle\DTO\Implementation
164 */
165 public function getServerInfo(): Implementation
166 {
167 return $this->serverInfo;
168 }
169
170 /**
171 * @return string|null
172 */
173 public function getInstructions(): ?string
174 {
175 return $this->instructions;
176 }
177 }
178