| 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\Request; |
| 15: | |
| 16: | use Nexus\Mcp\Schema\Message\JsonRpcRequest; |
| 17: | use Nexus\Mcp\Schema\Message\RequestId; |
| 18: | |
| 19: | /** |
| 20: | * The base object for paginated requests. |
| 21: | * |
| 22: | * @template T of array{ |
| 23: | * jsonrpc: non-empty-string, |
| 24: | * id: int|non-empty-string, |
| 25: | * method: non-empty-string, |
| 26: | * params?: array<string, mixed>, |
| 27: | * } |
| 28: | * |
| 29: | * @extends JsonRpcRequest<T> |
| 30: | */ |
| 31: | abstract readonly class PaginatedRequest extends JsonRpcRequest |
| 32: | { |
| 33: | /** |
| 34: | * @param null|non-empty-string $cursor An opaque token representing the current pagination position. |
| 35: | * If provided, the server should return results starting after this cursor. |
| 36: | * @param null|array<string, mixed> $meta Reserved by MCP to allow clients and servers to attach |
| 37: | * additional metadata to their interactions. |
| 38: | */ |
| 39: | public function __construct(RequestId $id, string $method, ?string $cursor = null, ?array $meta = null) |
| 40: | { |
| 41: | $params = ! isset($cursor) && ! isset($meta) ? null : array_filter([ |
| 42: | '_meta' => $meta, |
| 43: | 'cursor' => $cursor, |
| 44: | ], static fn(mixed $value): bool => null !== $value); |
| 45: | |
| 46: | parent::__construct(self::JSON_RPC_VERSION, $id, $method, $params); |
| 47: | } |
| 48: | } |
| 49: |