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\Elicitation;
15:
16: /**
17: * @implements PrimitiveSchemaDefinition<array{
18: * type: 'string',
19: * description?: non-empty-string,
20: * title?: non-empty-string,
21: * minLength?: int<0, max>,
22: * maxLength?: int<0, max>,
23: * format?: 'date'|'date-time'|'email'|'uri',
24: * default?: string,
25: * }>
26: */
27: final readonly class StringSchema implements PrimitiveSchemaDefinition
28: {
29: /**
30: * @var non-empty-string
31: */
32: public string $type;
33:
34: /**
35: * @param null|non-empty-string $description
36: * @param null|non-empty-string $title
37: * @param null|int<0, max> $minLength
38: * @param null|int<0, max> $maxLength
39: * @param null|'date'|'date-time'|'email'|'uri' $format
40: */
41: public function __construct(
42: public ?string $description = null,
43: public ?string $title = null,
44: public ?int $minLength = null,
45: public ?int $maxLength = null,
46: public ?string $format = null,
47: public ?string $default = null,
48: ) {
49: $this->type = 'string';
50: }
51:
52: #[\Override]
53: public function toArray(): array
54: {
55: return array_filter([
56: 'type' => $this->type,
57: 'description' => $this->description,
58: 'title' => $this->title,
59: 'minLength' => $this->minLength,
60: 'maxLength' => $this->maxLength,
61: 'format' => $this->format,
62: 'default' => $this->default,
63: ], static fn(mixed $value): bool => null !== $value);
64: }
65:
66: /**
67: * @return template-type<self, PrimitiveSchemaDefinition, 'T'>
68: */
69: #[\Override]
70: public function jsonSerialize(): array
71: {
72: return $this->toArray();
73: }
74: }
75: