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