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\NotificationParams;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\Arrayable;
18: use Nexus\Mcp\Core\Schema\MetaObject;
19: use Nexus\Mcp\Core\Schema\NotificationParams;
20:
21: /**
22: * Default notification params for methods that carry no typed fields beyond `_meta`.
23: *
24: * @extends NotificationParams<array{
25: * _meta?: template-type<MetaObject, Arrayable, 'T'>,
26: * }>
27: *
28: * @see https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/schema/draft/schema.ts
29: */
30: final readonly class EmptyNotificationParams extends NotificationParams
31: {
32: #[\Override]
33: public static function fromArray(array $data): static
34: {
35: $meta = new MetaObject();
36:
37: if (\array_key_exists('_meta', $data)) {
38: Assert::that($data['_meta'])
39: ->isArray('"params._meta" must be an object, {type} given.')
40: ->isMap('"params._meta" must be a string-keyed object.')
41: ;
42: $meta = MetaObject::fromArray($data['_meta']);
43: }
44:
45: return new self(meta: $meta);
46: }
47:
48: #[\Override]
49: public function toArray(): array
50: {
51: $meta = $this->meta->toArray();
52:
53: return [] !== $meta ? ['_meta' => $meta] : [];
54: }
55: }
56: