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\Server\Handler\Request;
15:
16: use Nexus\Mcp\Core\Handler\AbstractContext;
17: use Nexus\Mcp\Core\Handler\RequestHandlerInterface;
18: use Nexus\Mcp\Core\Schema\JsonRpc\JsonRpcRequest;
19: use Nexus\Mcp\Core\Schema\Request\SetLevelRequest;
20: use Nexus\Mcp\Core\Schema\Result\EmptyResult;
21: use Nexus\Mcp\Server\Logging\LoggingLevelGate;
22: use Nexus\Mcp\Server\ServerContext;
23:
24: /**
25: * Handles the `logging/setLevel` request by updating the server's minimum log
26: * level so subsequent `ServerContext::log()` calls below the threshold are
27: * dropped before reaching the transport.
28: *
29: * @implements RequestHandlerInterface<'logging/setLevel', EmptyResult, ServerContext>
30: */
31: final readonly class SetLevelRequestHandler implements RequestHandlerInterface
32: {
33: public function __construct(private LoggingLevelGate $gate)
34: {
35: }
36:
37: #[\Override]
38: public function handle(JsonRpcRequest $request, AbstractContext $context): EmptyResult
39: {
40: \assert($request instanceof SetLevelRequest);
41:
42: $this->gate->setLevel($request->params->level);
43:
44: return new EmptyResult();
45: }
46: }
47: