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\NotificationParams;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\Arrayable;
18: use Nexus\Mcp\Core\Schema\MetaObject;
19: use Nexus\Mcp\Core\Schema\MetaObject\NotificationMetaObject;
20: use Nexus\Mcp\Core\Schema\NotificationParams;
21: use Nexus\Mcp\Core\Schema\SubscriptionFilter;
22:
23: /**
24: * Parameters for a `notifications/subscriptions/acknowledged` notification.
25: *
26: * @extends NotificationParams<array{
27: * _meta?: template-type<NotificationMetaObject, MetaObject, 'T'>,
28: * notifications: template-type<SubscriptionFilter, Arrayable, 'T'>,
29: * }>
30: *
31: * @see https://modelcontextprotocol.io/specification/2026-07-28/schema#subscriptionsacknowledgednotificationparams
32: */
33: final readonly class SubscriptionsAcknowledgedNotificationParams extends NotificationParams
34: {
35: public function __construct(
36: public SubscriptionFilter $notifications,
37: NotificationMetaObject $meta = new NotificationMetaObject(),
38: ) {
39: parent::__construct(meta: $meta);
40: }
41:
42: #[\Override]
43: public static function fromArray(array $data): static
44: {
45: Assert::that($data)->hasOffset('notifications', '"params" is missing the required "notifications" key.');
46: Assert::that($data['notifications'])
47: ->isArray('"params.notifications" must be an object, {type} given.')
48: ->isMap('"params.notifications" must be a string-keyed object.')
49: ;
50: $notifications = SubscriptionFilter::fromArray($data['notifications']);
51:
52: $meta = new NotificationMetaObject();
53:
54: if (\array_key_exists('_meta', $data)) {
55: Assert::that($data['_meta'])
56: ->isArray('"params._meta" must be an object, {type} given.')
57: ->not()->isNonEmptyList('"params._meta" must be a string-keyed object.')
58: ;
59: $meta = NotificationMetaObject::fromArray($data['_meta']);
60: }
61:
62: return new self(notifications: $notifications, meta: $meta);
63: }
64:
65: #[\Override]
66: public function toArray(): array
67: {
68: $data = [];
69: $meta = $this->meta->toArray();
70:
71: if ([] !== $meta) {
72: $data['_meta'] = $meta;
73: }
74:
75: $data['notifications'] = $this->notifications->toArray();
76:
77: return $data;
78: }
79:
80: #[\Override]
81: public function jsonSerialize(): array
82: {
83: $data = $this->toArray();
84: $data['notifications'] = $this->notifications->jsonSerialize();
85:
86: return $data;
87: }
88: }
89: