PluginProbe ʕ •ᴥ•ʔ
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). / trunk
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). vtrunk
3.0.3 3.0.2 3.0.1 trunk 2.2.14 2.2.15 2.2.16 2.2.17 2.2.18 2.2.19 2.3.0 2.3.1 2.3.10 2.3.11 2.3.12 2.3.13 2.3.14 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.7.91 2.7.92 2.7.93 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.9.0 2.9.1 2.9.2 2.9.3 3.0.0
commercebird / vendor / wordpress / php-mcp-schema / src / Server / Prompts / DTO / GetPromptResult.php
commercebird / vendor / wordpress / php-mcp-schema / src / Server / Prompts / DTO Last commit date
GetPromptRequest.php 3 months ago GetPromptRequestParams.php 3 months ago GetPromptResult.php 3 months ago ListPromptsRequest.php 3 months ago ListPromptsResult.php 3 months ago Prompt.php 3 months ago PromptArgument.php 3 months ago PromptListChangedNotification.php 3 months ago PromptMessage.php 3 months ago
GetPromptResult.php
119 lines
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 * An optional description for the prompt.
27 *
28 * @since 2024-11-05
29 *
30 * @var string|null
31 */
32 protected ?string $description;
33
34 /**
35 * @since 2024-11-05
36 *
37 * @var array<\WP\McpSchema\Server\Prompts\DTO\PromptMessage>
38 */
39 protected array $messages;
40
41 /**
42 * @param array<\WP\McpSchema\Server\Prompts\DTO\PromptMessage> $messages @since 2024-11-05
43 * @param array<string, mixed>|null $_meta @since 2024-11-05
44 * @param string|null $description @since 2024-11-05
45 */
46 public function __construct(
47 array $messages,
48 ?array $_meta = null,
49 ?string $description = null
50 ) {
51 parent::__construct($_meta);
52 $this->messages = $messages;
53 $this->description = $description;
54 }
55
56 /**
57 * Creates an instance from an array.
58 *
59 * @param array{
60 * _meta?: array<string, mixed>|null,
61 * description?: string|null,
62 * messages: array<array<string, mixed>|\WP\McpSchema\Server\Prompts\DTO\PromptMessage>
63 * } $data
64 * @phpstan-param array<string, mixed> $data
65 * @return self
66 */
67 public static function fromArray(array $data): self
68 {
69 self::assertRequired($data, ['messages']);
70
71 /** @var array<\WP\McpSchema\Server\Prompts\DTO\PromptMessage> $messages */
72 $messages = array_map(
73 static fn($item) => is_array($item)
74 ? PromptMessage::fromArray($item)
75 : $item,
76 self::asArray($data['messages'])
77 );
78
79 return new self(
80 $messages,
81 self::asArrayOrNull($data['_meta'] ?? null),
82 self::asStringOrNull($data['description'] ?? null)
83 );
84 }
85
86 /**
87 * Converts the instance to an array.
88 *
89 * @return array<string, mixed>
90 */
91 public function toArray(): array
92 {
93 $result = parent::toArray();
94
95 if ($this->description !== null) {
96 $result['description'] = $this->description;
97 }
98 $result['messages'] = array_map(static fn($item) => $item->toArray(), $this->messages);
99
100 return $result;
101 }
102
103 /**
104 * @return string|null
105 */
106 public function getDescription(): ?string
107 {
108 return $this->description;
109 }
110
111 /**
112 * @return array<\WP\McpSchema\Server\Prompts\DTO\PromptMessage>
113 */
114 public function getMessages(): array
115 {
116 return $this->messages;
117 }
118 }
119