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\Schema\Notification;
15:
16: use Nexus\Mcp\Schema\Enum\LoggingLevel;
17: use Nexus\Mcp\Schema\Message\JsonRpcNotification;
18:
19: /**
20: * JSONRPCNotification of a log message passed from server to client. If no `logging/setLevel` request has
21: * been sent from the client, the server MAY decide which messages to send automatically.
22: *
23: * @extends JsonRpcNotification<array{
24: * jsonrpc: '2.0',
25: * method: 'notifications/message',
26: * params?: array{
27: * _meta?: array<string, mixed>,
28: * data: mixed,
29: * level: string,
30: * logger?: string,
31: * }
32: * }>
33: */
34: final readonly class LoggingMessageNotification extends JsonRpcNotification implements ServerNotification
35: {
36: /**
37: * @param mixed $data The data to be logged, such as a string message or an object.
38: * Any JSON serializable type is allowed here.
39: * @param LoggingLevel $level The severity of this log message.
40: * @param null|string $logger An optional name of the logger issuing this message.
41: * @param null|array<string, mixed> $meta Reserved by MCP to allow clients and servers to attach
42: * additional metadata to their interactions.
43: */
44: public function __construct(mixed $data, LoggingLevel $level, ?string $logger = null, ?array $meta = null)
45: {
46: parent::__construct(self::JSON_RPC_VERSION, 'notifications/message', array_filter([
47: '_meta' => $meta,
48: 'data' => \is_string($data) ? $data : json_encode($data),
49: 'level' => $level->value,
50: 'logger' => $logger,
51: ], static fn(mixed $value): bool => null !== $value));
52: }
53: }
54: