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; |
15: | |
16: | /** |
17: | * Describes the name and version of an MCP implementation, with an optional title for UI representation. |
18: | */ |
19: | final readonly class Implementation implements \JsonSerializable, Arrayable |
20: | { |
21: | /** |
22: | * @param non-empty-string $name Intended for programmatic or logical use, but used as a display |
23: | * name in past specs or fallback (if title isn’t present) |
24: | * @param non-empty-string $version |
25: | * @param null|non-empty-string $title Intended for UI and end-user contexts — optimized to be human-readable |
26: | * and easily understood, even by those unfamiliar with domain-specific terminology |
27: | */ |
28: | public function __construct( |
29: | public string $name, |
30: | public string $version, |
31: | public ?string $title = null, |
32: | ) {} |
33: | |
34: | /** |
35: | * @return array{ |
36: | * name: non-empty-string, |
37: | * version: non-empty-string, |
38: | * title?: non-empty-string, |
39: | * } |
40: | */ |
41: | #[\Override] |
42: | public function toArray(): array |
43: | { |
44: | return array_filter([ |
45: | 'name' => $this->name, |
46: | 'version' => $this->version, |
47: | 'title' => $this->title, |
48: | ], static fn(mixed $value): bool => null !== $value); |
49: | } |
50: | |
51: | /** |
52: | * @return array{ |
53: | * name: non-empty-string, |
54: | * version: non-empty-string, |
55: | * title?: non-empty-string, |
56: | * } |
57: | */ |
58: | #[\Override] |
59: | public function jsonSerialize(): array |
60: | { |
61: | return $this->toArray(); |
62: | } |
63: | } |
64: |