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\Client\Handler\Notification;
15:
16: use Nexus\Mcp\Core\Handler\NotificationHandlerInterface;
17: use Nexus\Mcp\Core\Schema\JsonRpc\JsonRpcNotification;
18: use Nexus\Mcp\Core\Schema\Notification\LoggingMessageNotification;
19:
20: /**
21: * Adapts a closure into a `notifications/message` handler, so consumers can
22: * register a callback instead of an interface implementation.
23: *
24: * @implements NotificationHandlerInterface<'notifications/message'>
25: */
26: final readonly class LoggingMessageNotificationHandler implements NotificationHandlerInterface
27: {
28: /**
29: * @param \Closure(LoggingMessageNotification): void $listener
30: */
31: public function __construct(private \Closure $listener)
32: {
33: }
34:
35: #[\Override]
36: public function handle(JsonRpcNotification $notification): void
37: {
38: \assert($notification instanceof LoggingMessageNotification);
39:
40: ($this->listener)($notification);
41: }
42: }
43: