php-sdk/examples/custom-method-handlers/ListToolsRequestHandler.php
Kyrian Obikwelu f1b471a219
[Server] Add Bidirectional Client Communication Support (#109)
* feat(server): add bidirectional client communication support

* fix(server): use correct session ID string conversion method

* fix: clean up docblocks for request handler methods in Builder

* fix: merge artifacts
2025-10-26 22:48:17 +01:00

46 lines
1.2 KiB
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\Example\CustomMethodHandlers;
use Mcp\Schema\JsonRpc\Request;
use Mcp\Schema\JsonRpc\Response;
use Mcp\Schema\Request\ListToolsRequest;
use Mcp\Schema\Result\ListToolsResult;
use Mcp\Schema\Tool;
use Mcp\Server\Handler\Request\RequestHandlerInterface;
use Mcp\Server\Session\SessionInterface;
/** @implements RequestHandlerInterface<ListToolsResult> */
class ListToolsRequestHandler implements RequestHandlerInterface
{
/**
* @param array<string, Tool> $toolDefinitions
*/
public function __construct(private array $toolDefinitions)
{
}
public function supports(Request $request): bool
{
return $request instanceof ListToolsRequest;
}
/**
* @return Response<ListToolsResult>
*/
public function handle(Request $request, SessionInterface $session): Response
{
\assert($request instanceof ListToolsRequest);
return new Response($request->getId(), new ListToolsResult(array_values($this->toolDefinitions), null));
}
}