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\Extension\Skills\Schema\RequestParams;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\Cursor;
18: use Nexus\Mcp\Core\Schema\MetaObject;
19: use Nexus\Mcp\Core\Schema\MetaObject\RequestMetaObject;
20: use Nexus\Mcp\Core\Schema\RequestParams;
21:
22: /**
23: * Parameters for a `resources/directory/read` request.
24: *
25: * @extends RequestParams<array{
26: * _meta: template-type<RequestMetaObject, MetaObject, 'T'>,
27: * uri: non-empty-string,
28: * cursor?: non-empty-string,
29: * }>
30: *
31: * @see https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/seps/2640-skills-extension.md
32: */
33: final readonly class ReadResourceDirectoryRequestParams extends RequestParams
34: {
35: /**
36: * @param non-empty-string $uri URI of the directory resource, written without a trailing slash
37: */
38: public function __construct(
39: public string $uri,
40: RequestMetaObject $meta,
41: public ?Cursor $cursor = null,
42: ) {
43: Assert::that($uri)->isNonEmptyString('"params.uri" must be a non-empty string.');
44:
45: parent::__construct(meta: $meta);
46: }
47:
48: #[\Override]
49: public static function fromArray(array $data): static
50: {
51: Assert::that($data)->hasOffset('uri', '"params" is missing the required "uri" key.');
52: $uri = $data['uri'];
53: Assert::that($uri)->isNonEmptyString('"params.uri" must be a non-empty string, {type} given.');
54:
55: $cursor = null;
56:
57: if (\array_key_exists('cursor', $data)) {
58: $raw = $data['cursor'];
59: Assert::that($raw)->isNonEmptyString('"params.cursor" must be a non-empty string, {type} given.');
60: $cursor = new Cursor(cursor: $raw);
61: }
62:
63: Assert::that($data)->hasOffset('_meta', '"params" is missing the required "_meta" key.');
64: Assert::that($data['_meta'])
65: ->isArray('"params._meta" must be an object, {type} given.')
66: ->not()->isNonEmptyList('"params._meta" must be a string-keyed object.')
67: ;
68:
69: return new self(uri: $uri, meta: RequestMetaObject::fromArray($data['_meta']), cursor: $cursor);
70: }
71:
72: #[\Override]
73: public function toArray(): array
74: {
75: $data = [
76: '_meta' => $this->meta->toArray(),
77: 'uri' => $this->uri,
78: ];
79:
80: if (null !== $this->cursor) {
81: $data['cursor'] = $this->cursor->cursor;
82: }
83:
84: return $data;
85: }
86: }
87: