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(
36: public SubscriptionFilter $notifications,
37: RequestMetaObject $meta,
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: Assert::that($data)->hasOffset('_meta', '"params" is missing the required "_meta" key.');
53: Assert::that($data['_meta'])
54: ->isArray('"params._meta" must be an object, {type} given.')
55: ->not()->isNonEmptyList('"params._meta" must be a string-keyed object.')
56: ;
57: $meta = RequestMetaObject::fromArray($data['_meta']);
58:
59: return new self(notifications: $notifications, meta: $meta);
60: }
61:
62: #[\Override]
63: public function toArray(): array
64: {
65: return [
66: '_meta' => $this->meta->toArray(),
67: 'notifications' => $this->notifications->toArray(),
68: ];
69: }
70:
71: #[\Override]
72: public function jsonSerialize(): array
73: {
74: $data = parent::jsonSerialize();
75: $data['notifications'] = $this->notifications->jsonSerialize();
76:
77: return $data;
78: }
79: }
80: