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/2026-07-28/schema#toollistchangednotification
35: */
36: final readonly class ToolListChangedNotification extends JsonRpcNotification implements ServerNotification
37: {
38: public function __construct(EmptyNotificationParams $params = new EmptyNotificationParams())
39: {
40: parent::__construct(params: $params);
41: }
42:
43: #[\Override]
44: public static function getMethod(): string
45: {
46: return 'notifications/tools/list_changed';
47: }
48:
49: #[\Override]
50: public static function fromArray(array $data): static
51: {
52: $params = new EmptyNotificationParams();
53:
54: if (\array_key_exists('params', $data)) {
55: Assert::that($data['params'])
56: ->isArray('"params" must be an object, {type} given.')
57: ->isMap('"params" must be a string-keyed object.')
58: ;
59: $params = EmptyNotificationParams::fromArray($data['params']);
60: }
61:
62: return new self(params: $params);
63: }
64:
65: #[\Override]
66: public function toArray(): array
67: {
68: $envelope = [
69: 'jsonrpc' => self::JSONRPC_VERSION,
70: 'method' => self::getMethod(),
71: ];
72:
73: $params = $this->params->toArray();
74:
75: if ([] !== $params) {
76: $envelope['params'] = $params;
77: }
78:
79: return $envelope;
80: }
81: }
82: