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\Result;
15:
16: use Nexus\Mcp\Core\Schema\Cursor;
17: use Nexus\Mcp\Core\Schema\MetaObject;
18: use Nexus\Mcp\Core\Schema\Result;
19:
20: /**
21: * Common shape for results that paginate via an opaque cursor. Subclasses add their own
22: * payload field alongside the optional `nextCursor`.
23: *
24: * @see https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/schema/2025-11-25/schema.ts
25: */
26: abstract readonly class PaginatedResult extends Result
27: {
28: public function __construct(public ?Cursor $nextCursor = null, MetaObject $meta = new MetaObject())
29: {
30: parent::__construct($meta);
31: }
32:
33: #[\Override]
34: public function toArray(): array
35: {
36: $data = parent::toArray();
37:
38: if (null !== $this->nextCursor) {
39: $data['nextCursor'] = $this->nextCursor->cursor;
40: }
41:
42: return $data;
43: }
44:
45: #[\Override]
46: public function jsonSerialize(): array
47: {
48: return $this->toArray();
49: }
50: }
51: