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\RequestParams;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\Enum\LoggingLevel;
18: use Nexus\Mcp\Core\Schema\RequestMetaObject;
19: use Nexus\Mcp\Core\Schema\RequestParams;
20: use Nexus\Mcp\Core\Validation\EnumValueValidator;
21:
22: /**
23: * Parameters for a `logging/setLevel` request.
24: *
25: * @see https://modelcontextprotocol.io/specification/2025-11-25/schema#setlevelrequestparams
26: */
27: final readonly class SetLevelRequestParams extends RequestParams
28: {
29: public function __construct(public LoggingLevel $level, RequestMetaObject $meta = new RequestMetaObject())
30: {
31: parent::__construct($meta);
32: }
33:
34: /**
35: * @param array<string, mixed> $data
36: */
37: #[\Override]
38: public static function fromArray(array $data): static
39: {
40: Assert::that($data)->hasOffset('level', 'missing the required "level" key.');
41: $level = EnumValueValidator::parse(LoggingLevel::class, $data['level'], '"params.level"');
42:
43: $meta = new RequestMetaObject();
44:
45: if (\array_key_exists('_meta', $data)) {
46: Assert::that($data['_meta'])
47: ->isArray('"params._meta" must be an object, {type} given.')
48: ->isMap('"params._meta" must be a string-keyed object.')
49: ;
50: $meta = RequestMetaObject::fromArray($data['_meta']);
51: }
52:
53: return new self($level, $meta);
54: }
55:
56: #[\Override]
57: public function toArray(): array
58: {
59: return [
60: ...parent::toArray(),
61: 'level' => $this->level->value,
62: ];
63: }
64:
65: #[\Override]
66: public function jsonSerialize(): array
67: {
68: return $this->toArray();
69: }
70: }
71: