1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus MCP SDK package.
7: *
8: * (c) 2025 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\Schema\Result;
15:
16: use Nexus\Mcp\Schema\Arrayable;
17: use Nexus\Mcp\Schema\Root;
18:
19: /**
20: * The client's response to a `roots/list` request from the server. This result contains an array of `Root` objects,
21: * each representing a root directory or file that the server can operate on.
22: *
23: * @extends Result<array{
24: * _meta?: array<string, mixed>,
25: * roots: list<template-type<Root, Arrayable, 'T'>>,
26: * }>
27: */
28: final readonly class ListRootsResult extends Result implements ClientResult
29: {
30: /**
31: * @param list<Root> $roots
32: */
33: public function __construct(
34: public array $roots,
35: ?array $meta = null,
36: ) {
37: parent::__construct($meta);
38: }
39:
40: #[\Override]
41: public function toArray(): array
42: {
43: return array_filter([
44: '_meta' => $this->meta,
45: 'roots' => array_map(
46: static fn(Root $root): array => $root->toArray(),
47: $this->roots,
48: ),
49: ], static fn(mixed $value): bool => null !== $value);
50: }
51: }
52: