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