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\BaseMetadata;
17: use Nexus\Mcp\Schema\Resource\ResourceTemplate;
18:
19: /**
20: * The server's response to a `resources/templates/list` request from the client.
21: *
22: * @extends PaginatedResult<array{
23: * _meta?: array<string, mixed>,
24: * resourceTemplates: list<template-type<ResourceTemplate, BaseMetadata, 'T'>>,
25: * }>
26: */
27: final readonly class ListResourceTemplatesResult extends PaginatedResult implements ServerResult
28: {
29: /**
30: * @param list<ResourceTemplate> $resourceTemplates
31: */
32: public function __construct(
33: public array $resourceTemplates,
34: ?string $nextCursor = null,
35: ?array $meta = null,
36: ) {
37: parent::__construct($nextCursor, $meta);
38: }
39:
40: #[\Override]
41: public function toArray(): array
42: {
43: return array_filter([
44: '_meta' => $this->meta,
45: 'resourceTemplates' => array_map(
46: static fn(ResourceTemplate $resourceTemplate): array => $resourceTemplate->toArray(),
47: $this->resourceTemplates,
48: ),
49: 'nextCursor' => $this->nextCursor,
50: ], static fn(mixed $value): bool => null !== $value);
51: }
52: }
53: