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 / Client / Roots / DTO / ListRootsRequest.php

ListRootsRequest.php in ZIP AI – AI Website Builder & AI Agent (Beta) 0.0.8, at lib/php-mcp-schema/src/Client/Roots/DTO/ListRootsRequest.php

116 lines 3.2 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\Client\Roots\DTO;
6
7 use WP\McpSchema\Common\JsonRpc\DTO\JSONRPCRequest;
8 use WP\McpSchema\Common\JsonRpc\DTO\RequestParams;
9 use WP\McpSchema\Common\Protocol\Union\ServerRequestInterface;
10 use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
11
12 /**
13 * Sent from the server to request a list of root URIs from the client. Roots allow
14 * servers to ask for specific directories or files to operate on. A common example
15 * for roots is providing a set of repositories or directories a server should operate
16 * on.
17 *
18 * This request is typically used when the server needs to understand the file system
19 * structure or access specific locations that the client has permission to read from.
20 *
21 * @since 2024-11-05
22 * @last-updated 2025-11-25 (modified property: params)
23 *
24 * @mcp-domain Client
25 * @mcp-subdomain Roots
26 * @mcp-version 2025-11-25
27 */
28 class ListRootsRequest extends JSONRPCRequest implements ServerRequestInterface
29 {
30 use ValidatesRequiredFields;
31
32 public const METHOD = 'roots/list';
33
34 public const DISCRIMINATOR_FIELD = 'method';
35 public const DISCRIMINATOR_VALUE = 'roots/list';
36
37 /**
38 * @var \WP\McpSchema\Common\JsonRpc\DTO\RequestParams|null
39 */
40 protected ?RequestParams $typedParams;
41
42 /**
43 * @param '2.0' $jsonrpc @since 2025-11-25
44 * @param string|number $id @since 2025-11-25
45 * @param \WP\McpSchema\Common\JsonRpc\DTO\RequestParams|null $params @since 2024-11-05
46 */
47 public function __construct(
48 string $jsonrpc,
49 $id,
50 ?RequestParams $params = null
51 ) {
52 parent::__construct(self::METHOD, $jsonrpc, $id, null);
53 $this->typedParams = $params;
54 }
55
56 /**
57 * Creates an instance from an array.
58 *
59 * @param array{
60 * jsonrpc: '2.0',
61 * id: string|number,
62 * method: 'roots/list',
63 * params?: array<string, mixed>|\WP\McpSchema\Common\JsonRpc\DTO\RequestParams|null
64 * } $data
65 * @phpstan-param array<string, mixed> $data
66 * @return self
67 */
68 public static function fromArray(array $data): self
69 {
70 self::assertRequired($data, ['jsonrpc', 'id']);
71
72 /** @var '2.0' $jsonrpc */
73 $jsonrpc = self::asString($data['jsonrpc']);
74
75 /** @var string|number $id */
76 $id = self::asStringOrNumber($data['id']);
77
78 /** @var \WP\McpSchema\Common\JsonRpc\DTO\RequestParams|null $params */
79 $params = isset($data['params'])
80 ? (is_array($data['params'])
81 ? RequestParams::fromArray(self::asArray($data['params']))
82 : $data['params'])
83 : null;
84
85 return new self(
86 $jsonrpc,
87 $id,
88 $params
89 );
90 }
91
92 /**
93 * Converts the instance to an array.
94 *
95 * @return array<string, mixed>
96 */
97 public function toArray(): array
98 {
99 $result = parent::toArray();
100
101 if ($this->typedParams !== null) {
102 $result['params'] = $this->typedParams->toArray();
103 }
104
105 return $result;
106 }
107
108 /**
109 * @return \WP\McpSchema\Common\JsonRpc\DTO\RequestParams|null
110 */
111 public function getTypedParams(): ?RequestParams
112 {
113 return $this->typedParams;
114 }
115 }
116