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\Server\Attribute;
15:
16: /**
17: * JSON Schema constraints for a discovered tool's input, applied at the parameter or method level.
18: */
19: #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PARAMETER)]
20: final readonly class InputSchema
21: {
22: /**
23: * @param null|array<string, mixed> $definition Explicit input schema (only its type, $schema, properties, and required keys are advertised)
24: * @param null|list<mixed> $enum
25: * @param null|array<string, mixed> $items
26: * @param null|array<string, mixed> $properties
27: * @param null|list<string> $required
28: * @param null|array<string, mixed>|bool $additionalProperties
29: */
30: public function __construct(
31: public ?array $definition = null,
32: public ?string $type = null,
33: public ?string $description = null,
34: public ?array $enum = null,
35: public ?string $format = null,
36: public ?int $minLength = null,
37: public ?int $maxLength = null,
38: public ?string $pattern = null,
39: public null|float|int $minimum = null,
40: public null|float|int $maximum = null,
41: public null|float|int $exclusiveMinimum = null,
42: public null|float|int $exclusiveMaximum = null,
43: public null|float|int $multipleOf = null,
44: public ?array $items = null,
45: public ?int $minItems = null,
46: public ?int $maxItems = null,
47: public ?bool $uniqueItems = null,
48: public ?array $properties = null,
49: public ?array $required = null,
50: public null|array|bool $additionalProperties = null,
51: ) {
52: }
53:
54: /**
55: * @return array<string, mixed>
56: */
57: public function toArray(): array
58: {
59: if (null !== $this->definition) {
60: return $this->definition;
61: }
62:
63: return array_filter([
64: 'type' => $this->type,
65: 'description' => $this->description,
66: 'enum' => $this->enum,
67: 'format' => $this->format,
68: 'minLength' => $this->minLength,
69: 'maxLength' => $this->maxLength,
70: 'pattern' => $this->pattern,
71: 'minimum' => $this->minimum,
72: 'maximum' => $this->maximum,
73: 'exclusiveMinimum' => $this->exclusiveMinimum,
74: 'exclusiveMaximum' => $this->exclusiveMaximum,
75: 'multipleOf' => $this->multipleOf,
76: 'items' => $this->items,
77: 'minItems' => $this->minItems,
78: 'maxItems' => $this->maxItems,
79: 'uniqueItems' => $this->uniqueItems,
80: 'properties' => $this->properties,
81: 'required' => $this->required,
82: 'additionalProperties' => $this->additionalProperties,
83: ], static fn(mixed $value): bool => null !== $value);
84: }
85: }
86: