| 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; |
| 15: | |
| 16: | /** |
| 17: | * Common params for any request. |
| 18: | * |
| 19: | * @implements Arrayable<array{_meta?: template-type<RequestMetaObject, Arrayable, 'T'>, ...<string, mixed>}> |
| 20: | * |
| 21: | * @see https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/schema/2025-11-25/schema.ts |
| 22: | */ |
| 23: | abstract readonly class RequestParams implements Arrayable |
| 24: | { |
| 25: | public function __construct(public RequestMetaObject $meta = new RequestMetaObject()) |
| 26: | { |
| 27: | } |
| 28: | |
| 29: | /** |
| 30: | * @param array<string, mixed> $data |
| 31: | */ |
| 32: | #[\Override] |
| 33: | abstract public static function fromArray(array $data): static; |
| 34: | |
| 35: | /** |
| 36: | * Serializes the params body. Subclasses override to merge their own fields |
| 37: | * alongside the `_meta` slice returned here. |
| 38: | */ |
| 39: | #[\Override] |
| 40: | public function toArray(): array |
| 41: | { |
| 42: | $meta = $this->meta->toArray(); |
| 43: | |
| 44: | return [] === $meta ? [] : ['_meta' => $meta]; |
| 45: | } |
| 46: | |
| 47: | #[\Override] |
| 48: | public function jsonSerialize(): array |
| 49: | { |
| 50: | return $this->toArray(); |
| 51: | } |
| 52: | } |
| 53: |