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\RequestId;
18: use Nexus\Mcp\Core\Schema\RequestParams;
19: use Nexus\Mcp\Core\Schema\RequestParams\PaginatedRequestParams;
20:
21: /**
22: * Sent from the client to request a list of resource templates the server has.
23: *
24: * @property-read PaginatedRequestParams $params
25: *
26: * @extends PaginatedRequest<'resources/templates/list', array{
27: * jsonrpc: '2.0',
28: * id: int|non-empty-string,
29: * method: 'resources/templates/list',
30: * params: template-type<PaginatedRequestParams, RequestParams, 'T'>,
31: * }>
32: *
33: * @see https://modelcontextprotocol.io/specification/draft/schema#listresourcetemplatesrequest
34: */
35: final readonly class ListResourceTemplatesRequest extends PaginatedRequest implements ClientRequest
36: {
37: public function __construct(RequestId $id, PaginatedRequestParams $params)
38: {
39: parent::__construct(id: $id, params: $params);
40: }
41:
42: #[\Override]
43: public static function getMethod(): string
44: {
45: return 'resources/templates/list';
46: }
47:
48: #[\Override]
49: public static function fromArray(array $data): static
50: {
51: Assert::that($data)->hasOffset('id', 'missing the required "id" key.');
52: $id = $data['id'];
53: Assert::that($id)->isArrayKey('"id" must be an int or string, {type} given.');
54:
55: Assert::that($data)->hasOffset('params', 'missing the required "params" key.');
56: Assert::that($data['params'])
57: ->isArray('"params" must be an object, {type} given.')
58: ->isMap('"params" must be a string-keyed object.')
59: ;
60: $params = PaginatedRequestParams::fromArray($data['params']);
61:
62: return new self(id: new RequestId(id: $id), params: $params);
63: }
64:
65: #[\Override]
66: public function toArray(): array
67: {
68: return [
69: 'jsonrpc' => self::JSONRPC_VERSION,
70: 'id' => $this->id->id,
71: 'method' => static::getMethod(),
72: 'params' => $this->params->toArray(),
73: ];
74: }
75: }
76: