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\RequestParams;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\Cursor;
18: use Nexus\Mcp\Core\Schema\RequestMetaObject;
19: use Nexus\Mcp\Core\Schema\RequestParams;
20:
21: /**
22: * Common parameters for paginated requests.
23: *
24: * @see https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/schema/2025-11-25/schema.ts
25: */
26: final readonly class PaginatedRequestParams extends RequestParams
27: {
28: public function __construct(public ?Cursor $cursor = null, RequestMetaObject $meta = new RequestMetaObject())
29: {
30: parent::__construct($meta);
31: }
32:
33: /**
34: * @param array<string, mixed> $data
35: */
36: #[\Override]
37: public static function fromArray(array $data): static
38: {
39: $cursor = null;
40:
41: if (\array_key_exists('cursor', $data)) {
42: $raw = $data['cursor'];
43: Assert::that($raw)->isString('"params.cursor" must be a string, {type} given.');
44: $cursor = new Cursor($raw);
45: }
46:
47: $meta = new RequestMetaObject();
48:
49: if (\array_key_exists('_meta', $data)) {
50: Assert::that($data['_meta'])
51: ->isArray('"params._meta" must be an object, {type} given.')
52: ->isMap('"params._meta" must be a string-keyed object.')
53: ;
54: $meta = RequestMetaObject::fromArray($data['_meta']);
55: }
56:
57: return new self($cursor, $meta);
58: }
59:
60: #[\Override]
61: public function toArray(): array
62: {
63: $data = parent::toArray();
64:
65: if (null !== $this->cursor) {
66: $data['cursor'] = $this->cursor->cursor;
67: }
68:
69: return $data;
70: }
71:
72: #[\Override]
73: public function jsonSerialize(): array
74: {
75: return $this->toArray();
76: }
77: }
78: