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\MetaObject;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\Implementation;
18: use Nexus\Mcp\Core\Schema\RequestId;
19:
20: /**
21: * Extends `ResultMetaObject` with the subscription-stream identifier carried by a
22: * `SubscriptionsListenResult`. All key naming rules from `MetaObject` apply.
23: *
24: * @see https://modelcontextprotocol.io/specification/2026-07-28/schema#subscriptionslistenresultmetaobject
25: */
26: final readonly class SubscriptionsListenResultMetaObject extends ResultMetaObject
27: {
28: public const string SUBSCRIPTION_ID_KEY = 'io.modelcontextprotocol/subscriptionId';
29:
30: /**
31: * @param array<string, mixed> $extras
32: */
33: public function __construct(
34: public RequestId $subscriptionId,
35: ?Implementation $serverInfo = null,
36: array $extras = [],
37: ) {
38: parent::__construct(serverInfo: $serverInfo, extras: $extras);
39: }
40:
41: #[\Override]
42: public static function fromArray(array $data): static
43: {
44: Assert::that($data)->hasOffset(
45: self::SUBSCRIPTION_ID_KEY,
46: \sprintf('"result._meta" is missing the required "%s" key.', self::SUBSCRIPTION_ID_KEY),
47: );
48: Assert::that($data[self::SUBSCRIPTION_ID_KEY])->isIntOrNonEmptyString(
49: \sprintf('"_meta.%s" must be an int or a non-empty string, {type} given.', self::SUBSCRIPTION_ID_KEY),
50: );
51:
52: $subscriptionId = new RequestId($data[self::SUBSCRIPTION_ID_KEY]);
53: unset($data[self::SUBSCRIPTION_ID_KEY]);
54:
55: [$serverInfo, $extras] = self::splitServerInfo($data);
56:
57: return new self(subscriptionId: $subscriptionId, serverInfo: $serverInfo, extras: $extras);
58: }
59:
60: #[\Override]
61: public function toArray(): array
62: {
63: return [self::SUBSCRIPTION_ID_KEY => $this->subscriptionId->id] + parent::toArray();
64: }
65: }
66: