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\Notification;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\JsonRpc\JsonRpcNotification;
18: use Nexus\Mcp\Core\Schema\NotificationParams;
19: use Nexus\Mcp\Core\Schema\NotificationParams\ResourceUpdatedNotificationParams;
20:
21: /**
22: * A notification from the server to the client, informing it that a resource has changed and
23: * may need to be read again. This is only sent for resources the client opted in to via the
24: * `resourceSubscriptions` field of a `subscriptions/listen` request.
25: *
26: * @property-read ResourceUpdatedNotificationParams $params
27: *
28: * @extends JsonRpcNotification<'notifications/resources/updated', array{
29: * jsonrpc: '2.0',
30: * method: 'notifications/resources/updated',
31: * params: template-type<ResourceUpdatedNotificationParams, NotificationParams, 'T'>,
32: * }>
33: *
34: * @see https://modelcontextprotocol.io/specification/draft/schema#resourceupdatednotification
35: */
36: final readonly class ResourceUpdatedNotification extends JsonRpcNotification implements ServerNotification
37: {
38: public function __construct(ResourceUpdatedNotificationParams $params)
39: {
40: parent::__construct(params: $params);
41: }
42:
43: #[\Override]
44: public static function getMethod(): string
45: {
46: return 'notifications/resources/updated';
47: }
48:
49: #[\Override]
50: public static function fromArray(array $data): static
51: {
52: Assert::that($data)->hasOffset('params', 'missing the required "params" key.');
53: Assert::that($data['params'])
54: ->isArray('"params" must be an object, {type} given.')
55: ->isMap('"params" must be a string-keyed object.')
56: ;
57:
58: return new self(params: ResourceUpdatedNotificationParams::fromArray($data['params']));
59: }
60:
61: #[\Override]
62: public function toArray(): array
63: {
64: return [
65: 'jsonrpc' => self::JSONRPC_VERSION,
66: 'method' => static::getMethod(),
67: 'params' => $this->params->toArray(),
68: ];
69: }
70: }
71: