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\Message;
15:
16: use Nexus\Mcp\Schema\Notification\Notification;
17:
18: /**
19: * A notification which does not expect a response.
20: *
21: * @template T of array{
22: * jsonrpc: non-empty-string,
23: * method: non-empty-string,
24: * params?: array<string, mixed>,
25: * }
26: *
27: * @extends Notification<T>
28: */
29: abstract readonly class JsonRpcNotification extends Notification
30: {
31: /**
32: * @var non-empty-string
33: */
34: public string $jsonrpc;
35:
36: public function __construct(string $jsonrpc, string $method, ?array $params = null)
37: {
38: $this->validateJsonRpc($jsonrpc);
39: $this->jsonrpc = $jsonrpc;
40:
41: parent::__construct($method, $params);
42: }
43:
44: #[\Override]
45: public function toArray(): array
46: {
47: return array_filter([
48: 'jsonrpc' => $this->jsonrpc,
49: 'method' => $this->method,
50: 'params' => $this->params,
51: ], static fn(mixed $value): bool => null !== $value);
52: }
53: }
54: