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\Elicitation;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\Arrayable;
18:
19: /**
20: * A single `{const, title}` entry inside a titled enum schema's option list.
21: *
22: * @implements Arrayable<array{const: non-empty-string, title: non-empty-string}>
23: *
24: * @see https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/schema/2026-07-28/schema.ts
25: */
26: final readonly class EnumOption implements Arrayable
27: {
28: /**
29: * @param non-empty-string $const
30: * @param non-empty-string $title
31: */
32: public function __construct(
33: public string $const,
34: public string $title,
35: ) {
36: Assert::that($const)->isNonEmptyString('"oneOf.const" must be a non-empty string.');
37: Assert::that($title)->isNonEmptyString('"oneOf.title" must be a non-empty string.');
38: }
39:
40: #[\Override]
41: public static function fromArray(array $data): static
42: {
43: Assert::that($data)->hasOffset('const', '"oneOf" is missing the required "const" key.');
44: $const = $data['const'];
45: Assert::that($const)->isNonEmptyString('"oneOf.const" must be a non-empty string, {type} given.');
46:
47: Assert::that($data)->hasOffset('title', '"oneOf" is missing the required "title" key.');
48: $title = $data['title'];
49: Assert::that($title)->isNonEmptyString('"oneOf.title" must be a non-empty string, {type} given.');
50:
51: return new self(const: $const, title: $title);
52: }
53:
54: #[\Override]
55: public function toArray(): array
56: {
57: return [
58: 'const' => $this->const,
59: 'title' => $this->title,
60: ];
61: }
62:
63: #[\Override]
64: public function jsonSerialize(): array
65: {
66: return $this->toArray();
67: }
68: }
69: