Add RequestContext and logging (#176)
* Implemented MCP logging specification with auto-injection * Add RequestContext * fix tests and style * Better deprecation * fix: minor * Remove ClientAwareInterface * fix cs * fix docs --------- Co-authored-by: Adam Jamiu <jamiuadam120@gmail.com>
This commit is contained in:
parent
369932378f
commit
a1e0f61b6b
1 changed files with 578 additions and 162 deletions
49
src/Server/Handler/Request/SetLogLevelHandler.php
Normal file
49
src/Server/Handler/Request/SetLogLevelHandler.php
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the official PHP MCP SDK.
|
||||
*
|
||||
* A collaboration between Symfony and the PHP Foundation.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Mcp\Server\Handler\Request;
|
||||
|
||||
use Mcp\Schema\JsonRpc\Request;
|
||||
use Mcp\Schema\JsonRpc\Response;
|
||||
use Mcp\Schema\Request\SetLogLevelRequest;
|
||||
use Mcp\Schema\Result\EmptyResult;
|
||||
use Mcp\Server\Protocol;
|
||||
use Mcp\Server\Session\SessionInterface;
|
||||
|
||||
/**
|
||||
* Handler for the logging/setLevel request.
|
||||
*
|
||||
* Handles client requests to set the logging level for the server.
|
||||
* The server should send all logs at this level and higher (more severe) to the client.
|
||||
*
|
||||
* @implements RequestHandlerInterface<EmptyResult>
|
||||
*
|
||||
* @author Adam Jamiu <jamiuadam120@gmail.com>
|
||||
*/
|
||||
final class SetLogLevelHandler implements RequestHandlerInterface
|
||||
{
|
||||
public function supports(Request $request): bool
|
||||
{
|
||||
return $request instanceof SetLogLevelRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Response<EmptyResult>
|
||||
*/
|
||||
public function handle(Request $request, SessionInterface $session): Response
|
||||
{
|
||||
\assert($request instanceof SetLogLevelRequest);
|
||||
|
||||
$session->set(Protocol::SESSION_LOGGING_LEVEL, $request->level->value);
|
||||
|
||||
return new Response($request->getId(), new EmptyResult());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue