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;
15:
16: /**
17: * The latest version of the Model Context Protocol that the client supports.
18: * The client MAY decide to support older versions as well.
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: ];
26:
27: private string $version;
28: private \DateTimeImmutable $versionAsDate; // @phpstan-ignore property.onlyWritten
29:
30: /**
31: * @param non-empty-string $version
32: */
33: public function __construct(string $version)
34: {
35: if (! \in_array($version, self::SUPPORTED_PROTOCOL_VERSIONS, true)) {
36: throw new \InvalidArgumentException(\sprintf(
37: 'Unsupported protocol version "%s". Supported versions are: "%s".',
38: $version,
39: implode('", "', self::SUPPORTED_PROTOCOL_VERSIONS),
40: ));
41: }
42:
43: $this->version = $version;
44: $this->versionAsDate = new \DateTimeImmutable($version, new \DateTimeZone('UTC'));
45: }
46:
47: #[\Override]
48: public function __toString(): string
49: {
50: return $this->version;
51: }
52:
53: #[\Override]
54: public function jsonSerialize(): string
55: {
56: return $this->version;
57: }
58: }
59: