1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus MCP SDK package.
7: *
8: * (c) 2026 John Paul E. Balandan, CPA <paulbalandan@gmail.com>
9: *
10: * For the full copyright and license information, please view
11: * the LICENSE file that was distributed with this source code.
12: */
13:
14: namespace Nexus\Mcp\Core\Schema\Request;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\JsonRpc\JsonRpcRequest;
18: use Nexus\Mcp\Core\Schema\RequestId;
19: use Nexus\Mcp\Core\Schema\RequestParams\EmptyRequestParams;
20:
21: /**
22: * Sent from the server to request a list of root URIs from the client. Roots allow servers to
23: * ask for specific directories or files to operate on. A common example for roots is providing
24: * a set of repositories or directories a server should operate on.
25: *
26: * This request is typically used when the server needs to understand the file system structure
27: * or access specific locations that the client has permission to read from.
28: *
29: * @extends JsonRpcRequest<'roots/list'>
30: *
31: * @see https://modelcontextprotocol.io/specification/2025-11-25/schema#listrootsrequest
32: */
33: final readonly class ListRootsRequest extends JsonRpcRequest implements ServerRequest
34: {
35: #[\Override]
36: public static function getMethod(): string
37: {
38: return 'roots/list';
39: }
40:
41: #[\Override]
42: public static function fromArray(array $data): static
43: {
44: Assert::that($data)->hasOffset('id', 'missing the required "id" key.');
45: $id = $data['id'];
46: Assert::that($id)->isArrayKey('"id" must be an int or string, {type} given.');
47:
48: $params = new EmptyRequestParams();
49:
50: if (\array_key_exists('params', $data)) {
51: Assert::that($data['params'])
52: ->isArray('"params" must be an object, {type} given.')
53: ->isMap('"params" must be a string-keyed object.')
54: ;
55: $params = EmptyRequestParams::fromArray($data['params']);
56: }
57:
58: return new self(new RequestId($id), $params);
59: }
60: }
61: