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 / Server / Prompts / DTO / GetPromptResult.php

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

129 lines 3.4 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\Server\Prompts\DTO;
6
7 use WP\McpSchema\Common\Protocol\DTO\Result;
8 use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
9 use WP\McpSchema\Server\Lifecycle\Union\ServerResultInterface;
10
11 /**
12 * The server's response to a prompts/get request from the client.
13 *
14 * @since 2024-11-05
15 * @last-updated 2025-11-25 (modified property: messages)
16 *
17 * @mcp-domain Server
18 * @mcp-subdomain Prompts
19 * @mcp-version 2025-11-25
20 */
21 class GetPromptResult extends Result implements ServerResultInterface
22 {
23 use ValidatesRequiredFields;
24
25 /**
26 * Wire keys this class models. Anything else is kept in $additionalProperties.
27 *
28 * @var array<int, string>
29 */
30 private const KNOWN_KEYS = ['_meta', 'description', 'messages'];
31
32 /**
33 * An optional description for the prompt.
34 *
35 * @since 2024-11-05
36 *
37 * @var string|null
38 */
39 protected ?string $description;
40
41 /**
42 * @since 2024-11-05
43 *
44 * @var array<\WP\McpSchema\Server\Prompts\DTO\PromptMessage>
45 */
46 protected array $messages;
47
48 /**
49 * @param array<\WP\McpSchema\Server\Prompts\DTO\PromptMessage> $messages @since 2024-11-05
50 * @param array<string, mixed>|null $_meta @since 2024-11-05
51 * @param string|null $description @since 2024-11-05
52 * @param array<string, mixed>|null $additionalProperties
53 */
54 public function __construct(
55 array $messages,
56 ?array $_meta = null,
57 ?string $description = null,
58 ?array $additionalProperties = null
59 ) {
60 parent::__construct($_meta, $additionalProperties);
61 $this->messages = $messages;
62 $this->description = $description;
63 }
64
65 /**
66 * Creates an instance from an array.
67 *
68 * @param array{
69 * _meta?: array<string, mixed>|null,
70 * description?: string|null,
71 * messages: array<array<string, mixed>|\WP\McpSchema\Server\Prompts\DTO\PromptMessage>
72 * } $data
73 * @phpstan-param array<string, mixed> $data
74 * @return self
75 */
76 public static function fromArray(array $data): self
77 {
78 self::assertRequired($data, ['messages']);
79
80 /** @var array<\WP\McpSchema\Server\Prompts\DTO\PromptMessage> $messages */
81 $messages = array_map(
82 static fn($item) => is_array($item)
83 ? PromptMessage::fromArray($item)
84 : $item,
85 self::asArray($data['messages'])
86 );
87
88 return new self(
89 $messages,
90 self::asArrayOrNull($data['_meta'] ?? null),
91 self::asStringOrNull($data['description'] ?? null),
92 self::additionalFields($data, self::KNOWN_KEYS)
93 );
94 }
95
96 /**
97 * Converts the instance to an array.
98 *
99 * @return array<string, mixed>
100 */
101 public function toArray(): array
102 {
103 $result = parent::toArray();
104
105 if ($this->description !== null) {
106 $result['description'] = $this->description;
107 }
108 $result['messages'] = array_map(static fn($item) => $item->toArray(), $this->messages);
109
110 return $result;
111 }
112
113 /**
114 * @return string|null
115 */
116 public function getDescription(): ?string
117 {
118 return $this->description;
119 }
120
121 /**
122 * @return array<\WP\McpSchema\Server\Prompts\DTO\PromptMessage>
123 */
124 public function getMessages(): array
125 {
126 return $this->messages;
127 }
128 }
129