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 / Tools / DTO / ToolOutputSchema.php

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

139 lines 3.1 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\Tools\DTO;
6
7 use WP\McpSchema\Common\AbstractDataTransferObject;
8 use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
9
10 /**
11 * An optional JSON Schema object defining the structure of the tool's output returned in
12 * the structuredContent field of a CallToolResult.
13 *
14 * Defaults to JSON Schema 2020-12 when no explicit $schema is provided.
15 * Currently restricted to type: "object" at the root level.
16 *
17 * @mcp-domain Server
18 * @mcp-subdomain Tools
19 * @mcp-version 2025-11-25
20 */
21 class ToolOutputSchema extends AbstractDataTransferObject
22 {
23 use ValidatesRequiredFields;
24
25 public const TYPE = 'object';
26
27 /**
28 * @var string|null
29 */
30 protected ?string $schema;
31
32 /**
33 * @var 'object'
34 */
35 protected string $type;
36
37 /**
38 * @var array<string, object>|null
39 */
40 protected ?array $properties;
41
42 /**
43 * @var array<string>|null
44 */
45 protected ?array $required;
46
47 /**
48 * @param string|null $schema
49 * @param array<string, object>|null $properties
50 * @param array<string>|null $required
51 */
52 public function __construct(
53 ?string $schema = null,
54 ?array $properties = null,
55 ?array $required = null
56 ) {
57 $this->type = self::TYPE;
58 $this->schema = $schema;
59 $this->properties = $properties;
60 $this->required = $required;
61 }
62
63 /**
64 * Creates an instance from an array.
65 *
66 * @param array{
67 * '$schema'?: string|null,
68 * type: 'object',
69 * properties?: array<string, object>|null,
70 * required?: array<string>|null
71 * } $data
72 * @phpstan-param array<string, mixed> $data
73 * @return self
74 */
75 public static function fromArray(array $data): self
76 {
77 return new self(
78 self::asStringOrNull($data['$schema'] ?? null),
79 self::asObjectMapOrNull($data['properties'] ?? null),
80 self::asStringArrayOrNull($data['required'] ?? null)
81 );
82 }
83
84 /**
85 * Converts the instance to an array.
86 *
87 * @return array<string, mixed>
88 */
89 public function toArray(): array
90 {
91 $result = [];
92
93 if ($this->schema !== null) {
94 $result['$schema'] = $this->schema;
95 }
96 $result['type'] = $this->type;
97 $result['properties'] = !empty($this->properties)
98 ? $this->properties
99 : new \stdClass();
100 if ($this->required !== null) {
101 $result['required'] = $this->required;
102 }
103
104 return $result;
105 }
106
107 /**
108 * @return string|null
109 */
110 public function getSchema(): ?string
111 {
112 return $this->schema;
113 }
114
115 /**
116 * @return 'object'
117 */
118 public function getType(): string
119 {
120 return $this->type;
121 }
122
123 /**
124 * @return array<string, object>|null
125 */
126 public function getProperties(): ?array
127 {
128 return $this->properties;
129 }
130
131 /**
132 * @return array<string>|null
133 */
134 public function getRequired(): ?array
135 {
136 return $this->required;
137 }
138 }
139