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\JsonRpc;
15:
16: use Nexus\Mcp\Core\Schema\Arrayable;
17: use Nexus\Mcp\Core\Schema\Notification;
18:
19: /**
20: * A notification which does not expect a response.
21: *
22: * @template-covariant TMethod of non-empty-string
23: * @template-covariant TEnvelope of array<string, mixed> = array<string, mixed>
24: *
25: * @extends Notification<TMethod>
26: * @implements Arrayable<TEnvelope>
27: *
28: * @see https://modelcontextprotocol.io/specification/draft/schema#jsonrpcnotification
29: */
30: abstract readonly class JsonRpcNotification extends Notification implements Arrayable, JsonRpcMessage
31: {
32: #[\Override]
33: public function jsonSerialize(): array
34: {
35: $envelope = [
36: 'jsonrpc' => self::JSONRPC_VERSION,
37: 'method' => static::getMethod(),
38: ];
39:
40: $params = $this->params->jsonSerialize();
41:
42: if ([] !== $params) {
43: $envelope['params'] = $params;
44: }
45:
46: return $envelope;
47: }
48: }
49: