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