1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | /** |
6: | * This file is part of the Nexus MCP SDK package. |
7: | * |
8: | * (c) 2025 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\Server\Message\Notification; |
15: | |
16: | use Nexus\Mcp\Enum\LoggingLevel; |
17: | use Nexus\Mcp\Message\Notification; |
18: | |
19: | /** |
20: | * Notification of a log message passed from server to client. If no `logging/setLevel` request has been sent |
21: | * from the client, the server MAY decide which messages to send automatically. |
22: | */ |
23: | final readonly class LoggingMessageNotification extends Notification implements ServerNotification |
24: | { |
25: | /** |
26: | * @param non-empty-string $jsonrpc JSON-RPC version. Must be 2.0. |
27: | * @param mixed $data The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here. |
28: | * @param LoggingLevel $level The severity of this log message. |
29: | * @param null|string $logger An optional name of the logger issuing this message. |
30: | */ |
31: | public function __construct( |
32: | string $jsonrpc, |
33: | public mixed $data, |
34: | public LoggingLevel $level, |
35: | public ?string $logger = null, |
36: | ) { |
37: | parent::__construct($jsonrpc, 'notifications/message', array_filter([ |
38: | 'data' => \is_string($data) ? $data : json_encode($data), |
39: | 'level' => $level->value, |
40: | 'logger' => $logger, |
41: | ], static fn(mixed $value): bool => null !== $value)); |
42: | } |
43: | } |
44: |