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\EmptyNotificationParams;
20:
21: /**
22: * An optional notification from the server to the client, informing it that the list of tools
23: * it offers has changed. This is only delivered on a `subscriptions/listen` stream when the
24: * client requested it via the `toolsListChanged` filter field.
25: *
26: * @property-read EmptyNotificationParams $params
27: *
28: * @extends JsonRpcNotification<'notifications/tools/list_changed', array{
29: * jsonrpc: '2.0',
30: * method: 'notifications/tools/list_changed',
31: * params?: template-type<EmptyNotificationParams, NotificationParams, 'T'>,
32: * }>
33: *
34: * @see https://modelcontextprotocol.io/specification/draft/schema#toollistchangednotification
35: */
36: final readonly class ToolListChangedNotification extends JsonRpcNotification implements ServerNotification
37: {
38: #[\Override]
39: public static function getMethod(): string
40: {
41: return 'notifications/tools/list_changed';
42: }
43:
44: #[\Override]
45: public static function fromArray(array $data): static
46: {
47: $params = new EmptyNotificationParams();
48:
49: if (\array_key_exists('params', $data)) {
50: Assert::that($data['params'])
51: ->isArray('"params" must be an object, {type} given.')
52: ->isMap('"params" must be a string-keyed object.')
53: ;
54: $params = EmptyNotificationParams::fromArray($data['params']);
55: }
56:
57: return new self(params: $params);
58: }
59:
60: #[\Override]
61: public function toArray(): array
62: {
63: $envelope = [
64: 'jsonrpc' => self::JSONRPC_VERSION,
65: 'method' => static::getMethod(),
66: ];
67:
68: $params = $this->params->toArray();
69:
70: if ([] !== $params) {
71: $envelope['params'] = $params;
72: }
73:
74: return $envelope;
75: }
76: }
77: