1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | namespace Nexus\Mcp; |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | final readonly class ProtocolVersion implements \JsonSerializable, \Stringable |
21: | { |
22: | public const string LATEST_PROTOCOL_VERSION = '2025-06-18'; |
23: | public const array SUPPORTED_PROTOCOL_VERSIONS = [ |
24: | self::LATEST_PROTOCOL_VERSION, |
25: | '2025-03-26', |
26: | '2024-11-05', |
27: | ]; |
28: | |
29: | private string $version; |
30: | private \DateTimeImmutable $versionAsDate; |
31: | |
32: | |
33: | |
34: | |
35: | public function __construct(string $version) |
36: | { |
37: | if (! \in_array($version, self::SUPPORTED_PROTOCOL_VERSIONS, true)) { |
38: | throw new \InvalidArgumentException(\sprintf( |
39: | 'Unsupported protocol version "%s". Supported versions are: "%s".', |
40: | $version, |
41: | implode('", "', self::SUPPORTED_PROTOCOL_VERSIONS), |
42: | )); |
43: | } |
44: | |
45: | $this->version = $version; |
46: | $this->versionAsDate = new \DateTimeImmutable($version, new \DateTimeZone('UTC')); |
47: | } |
48: | |
49: | #[\Override] |
50: | public function __toString(): string |
51: | { |
52: | return $this->version; |
53: | } |
54: | |
55: | #[\Override] |
56: | public function jsonSerialize(): string |
57: | { |
58: | return $this->version; |
59: | } |
60: | |
61: | public function supportsBatchRequest(): bool |
62: | { |
63: | return $this->versionAsDate <= new \DateTimeImmutable('2025-03-26', new \DateTimeZone('UTC')); |
64: | } |
65: | |
66: | public function supportsElicitation(): bool |
67: | { |
68: | return $this->versionAsDate >= new \DateTimeImmutable('2025-06-18', new \DateTimeZone('UTC')); |
69: | } |
70: | } |
71: | |