php-sdk/src/Server/RequestHandler/PingHandler.php
2025-08-29 11:12:23 +02:00

36 lines
944 B
PHP

<?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\RequestHandler;
use Mcp\Schema\JsonRpc\HasMethodInterface;
use Mcp\Schema\JsonRpc\Response;
use Mcp\Schema\Request\PingRequest;
use Mcp\Schema\Result\EmptyResult;
use Mcp\Server\MethodHandlerInterface;
/**
* @author Christopher Hertel <mail@christopher-hertel.de>
*/
final class PingHandler implements MethodHandlerInterface
{
public function supports(HasMethodInterface $message): bool
{
return $message instanceof PingRequest;
}
public function handle(PingRequest|HasMethodInterface $message): Response
{
\assert($message instanceof PingRequest);
return new Response($message->getId(), new EmptyResult());
}
}