[Server] Refactor protocol pipeline to separate request and notification handling (#106)
This commit is contained in:
parent
9ff6516e5b
commit
54a5d1495c
1 changed files with 1843 additions and 719 deletions
|
|
@ -12,38 +12,37 @@
|
|||
namespace Mcp\Server\Handler\Request;
|
||||
|
||||
use Mcp\Schema\Implementation;
|
||||
use Mcp\Schema\JsonRpc\HasMethodInterface;
|
||||
use Mcp\Schema\JsonRpc\Request;
|
||||
use Mcp\Schema\JsonRpc\Response;
|
||||
use Mcp\Schema\Request\InitializeRequest;
|
||||
use Mcp\Schema\Result\InitializeResult;
|
||||
use Mcp\Schema\ServerCapabilities;
|
||||
use Mcp\Server\Configuration;
|
||||
use Mcp\Server\Handler\MethodHandlerInterface;
|
||||
use Mcp\Server\Session\SessionInterface;
|
||||
|
||||
/**
|
||||
* @author Christopher Hertel <mail@christopher-hertel.de>
|
||||
*/
|
||||
final class InitializeHandler implements MethodHandlerInterface
|
||||
final class InitializeHandler implements RequestHandlerInterface
|
||||
{
|
||||
public function __construct(
|
||||
public readonly ?Configuration $configuration = null,
|
||||
) {
|
||||
}
|
||||
|
||||
public function supports(HasMethodInterface $message): bool
|
||||
public function supports(Request $request): bool
|
||||
{
|
||||
return $message instanceof InitializeRequest;
|
||||
return $request instanceof InitializeRequest;
|
||||
}
|
||||
|
||||
public function handle(InitializeRequest|HasMethodInterface $message, SessionInterface $session): Response
|
||||
public function handle(Request $request, SessionInterface $session): Response
|
||||
{
|
||||
\assert($message instanceof InitializeRequest);
|
||||
\assert($request instanceof InitializeRequest);
|
||||
|
||||
$session->set('client_info', $message->clientInfo->jsonSerialize());
|
||||
$session->set('client_info', $request->clientInfo->jsonSerialize());
|
||||
|
||||
return new Response(
|
||||
$message->getId(),
|
||||
$request->getId(),
|
||||
new InitializeResult(
|
||||
$this->configuration->capabilities ?? new ServerCapabilities(),
|
||||
$this->configuration->serverInfo ?? new Implementation(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue