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\Sampling;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\Arrayable;
18:
19: /**
20: * Hints to use for model selection.
21: *
22: * Keys not declared here are currently left unspecified by the spec and are up
23: * to the client to interpret.
24: *
25: * @implements Arrayable<array{name?: non-empty-string}>
26: *
27: * @see https://modelcontextprotocol.io/specification/2025-11-25/schema#modelhint
28: */
29: final readonly class ModelHint implements Arrayable
30: {
31: /**
32: * @var null|non-empty-string
33: */
34: public ?string $name;
35:
36: public function __construct(?string $name = null)
37: {
38: Assert::that($name)->nullOr()->isNonEmptyString('"hints.name" must be a non-empty string or null.');
39:
40: $this->name = $name;
41: }
42:
43: /**
44: * @param array<string, mixed> $data
45: */
46: #[\Override]
47: public static function fromArray(array $data): static
48: {
49: $name = $data['name'] ?? null;
50: Assert::that($name)->nullOr()->isString('"hints.name" must be a string or null, {type} given.');
51:
52: return new self($name);
53: }
54:
55: #[\Override]
56: public function toArray(): array
57: {
58: if (null === $this->name) {
59: return [];
60: }
61:
62: return ['name' => $this->name];
63: }
64:
65: #[\Override]
66: public function jsonSerialize(): array|\stdClass
67: {
68: $data = $this->toArray();
69:
70: return [] === $data ? new \stdClass() : $data;
71: }
72: }
73: