PluginProbe
ZIP AI – AI Website Builder & AI Agent (Beta) / 0.0.8
ZIP AI – AI Website Builder & AI Agent (Beta) v0.0.8
0.0.10 0.0.9 trunk 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8
zip-ai / lib / php-mcp-schema / src / Server / Prompts / DTO / Prompt.php

Prompt.php in ZIP AI – AI Website Builder & AI Agent (Beta) 0.0.8, at lib/php-mcp-schema/src/Server/Prompts/DTO/Prompt.php

197 lines 5.6 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\Core\DTO\Icon;
8 use WP\McpSchema\Common\Protocol\DTO\BaseMetadata;
9 use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
10
11 /**
12 * A prompt or prompt template that the server offers.
13 *
14 * @since 2024-11-05
15 * @last-updated 2025-11-25 (added properties: icons; modified property: arguments)
16 *
17 * @mcp-domain Server
18 * @mcp-subdomain Prompts
19 * @mcp-version 2025-11-25
20 */
21 class Prompt extends BaseMetadata
22 {
23 use ValidatesRequiredFields;
24
25 /**
26 * An optional description of what this prompt provides
27 *
28 * @since 2024-11-05
29 *
30 * @var string|null
31 */
32 protected ?string $description;
33
34 /**
35 * A list of arguments to use for templating the prompt.
36 *
37 * @since 2024-11-05
38 *
39 * @var array<\WP\McpSchema\Server\Prompts\DTO\PromptArgument>|null
40 */
41 protected ?array $arguments;
42
43 /**
44 * See [General fields: `_meta`](/specification/2025-11-25/basic/index#meta) for notes on `_meta` usage.
45 *
46 * @since 2025-06-18
47 *
48 * @var array<string, mixed>|null
49 */
50 protected ?array $_meta;
51
52 /**
53 * Optional set of sized icons that the client can display in a user interface.
54 *
55 * Clients that support rendering icons MUST support at least the following MIME types:
56 * - `image/png` - PNG images (safe, universal compatibility)
57 * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility)
58 *
59 * Clients that support rendering icons SHOULD also support:
60 * - `image/svg+xml` - SVG images (scalable but requires security precautions)
61 * - `image/webp` - WebP images (modern, efficient format)
62 *
63 * @since 2025-11-25
64 *
65 * @var array<\WP\McpSchema\Common\Core\DTO\Icon>|null
66 */
67 protected ?array $icons;
68
69 /**
70 * @param string $name @since 2024-11-05
71 * @param string|null $title @since 2025-06-18
72 * @param string|null $description @since 2024-11-05
73 * @param array<\WP\McpSchema\Server\Prompts\DTO\PromptArgument>|null $arguments @since 2024-11-05
74 * @param array<string, mixed>|null $_meta @since 2025-06-18
75 * @param array<\WP\McpSchema\Common\Core\DTO\Icon>|null $icons @since 2025-11-25
76 */
77 public function __construct(
78 string $name,
79 ?string $title = null,
80 ?string $description = null,
81 ?array $arguments = null,
82 ?array $_meta = null,
83 ?array $icons = null
84 ) {
85 parent::__construct($name, $title);
86 $this->description = $description;
87 $this->arguments = $arguments;
88 $this->_meta = $_meta;
89 $this->icons = $icons;
90 }
91
92 /**
93 * Creates an instance from an array.
94 *
95 * @param array{
96 * name: string,
97 * title?: string|null,
98 * description?: string|null,
99 * arguments?: array<array<string, mixed>|\WP\McpSchema\Server\Prompts\DTO\PromptArgument>|null,
100 * _meta?: array<string, mixed>|null,
101 * icons?: array<array<string, mixed>|\WP\McpSchema\Common\Core\DTO\Icon>|null
102 * } $data
103 * @phpstan-param array<string, mixed> $data
104 * @return self
105 */
106 public static function fromArray(array $data): self
107 {
108 self::assertRequired($data, ['name']);
109
110 /** @var array<\WP\McpSchema\Server\Prompts\DTO\PromptArgument>|null $arguments */
111 $arguments = isset($data['arguments'])
112 ? array_map(
113 static fn($item) => is_array($item)
114 ? PromptArgument::fromArray($item)
115 : $item,
116 self::asArray($data['arguments'])
117 )
118 : null;
119
120 /** @var array<\WP\McpSchema\Common\Core\DTO\Icon>|null $icons */
121 $icons = isset($data['icons'])
122 ? array_map(
123 static fn($item) => is_array($item)
124 ? Icon::fromArray($item)
125 : $item,
126 self::asArray($data['icons'])
127 )
128 : null;
129
130 return new self(
131 self::asString($data['name']),
132 self::asStringOrNull($data['title'] ?? null),
133 self::asStringOrNull($data['description'] ?? null),
134 $arguments,
135 self::asArrayOrNull($data['_meta'] ?? null),
136 $icons
137 );
138 }
139
140 /**
141 * Converts the instance to an array.
142 *
143 * @return array<string, mixed>
144 */
145 public function toArray(): array
146 {
147 $result = parent::toArray();
148
149 if ($this->description !== null) {
150 $result['description'] = $this->description;
151 }
152 if ($this->arguments !== null) {
153 $result['arguments'] = array_map(static fn($item) => $item->toArray(), $this->arguments);
154 }
155 if ($this->_meta !== null) {
156 $result['_meta'] = $this->_meta;
157 }
158 if ($this->icons !== null) {
159 $result['icons'] = array_map(static fn($item) => $item->toArray(), $this->icons);
160 }
161
162 return $result;
163 }
164
165 /**
166 * @return string|null
167 */
168 public function getDescription(): ?string
169 {
170 return $this->description;
171 }
172
173 /**
174 * @return array<\WP\McpSchema\Server\Prompts\DTO\PromptArgument>|null
175 */
176 public function getArguments(): ?array
177 {
178 return $this->arguments;
179 }
180
181 /**
182 * @return array<string, mixed>|null
183 */
184 public function get_meta(): ?array
185 {
186 return $this->_meta;
187 }
188
189 /**
190 * @return array<\WP\McpSchema\Common\Core\DTO\Icon>|null
191 */
192 public function getIcons(): ?array
193 {
194 return $this->icons;
195 }
196 }
197