Add request handler for resource templates (#89)
This commit is contained in:
parent
41486bfaa4
commit
cecfa0c3c6
2 changed files with 285 additions and 1 deletions
|
|
@ -86,6 +86,7 @@ class JsonRpcHandler
|
|||
new Handler\Request\GetPromptHandler($promptGetter),
|
||||
new Handler\Request\ListResourcesHandler($referenceProvider, $paginationLimit),
|
||||
new Handler\Request\ReadResourceHandler($resourceReader),
|
||||
new Handler\Request\ListResourceTemplatesHandler($referenceProvider, $paginationLimit),
|
||||
new Handler\Request\CallToolHandler($toolCaller, $logger),
|
||||
new Handler\Request\ListToolsHandler($referenceProvider, $paginationLimit),
|
||||
],
|
||||
|
|
|
|||
53
src/Server/Handler/Request/ListResourceTemplatesHandler.php
Normal file
53
src/Server/Handler/Request/ListResourceTemplatesHandler.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?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\Capability\Registry\ReferenceProviderInterface;
|
||||
use Mcp\Exception\InvalidCursorException;
|
||||
use Mcp\Schema\JsonRpc\HasMethodInterface;
|
||||
use Mcp\Schema\JsonRpc\Response;
|
||||
use Mcp\Schema\Request\ListResourceTemplatesRequest;
|
||||
use Mcp\Schema\Result\ListResourceTemplatesResult;
|
||||
use Mcp\Server\Handler\MethodHandlerInterface;
|
||||
use Mcp\Server\Session\SessionInterface;
|
||||
|
||||
/**
|
||||
* @author Christopher Hertel <mail@christopher-hertel.de>
|
||||
*/
|
||||
final class ListResourceTemplatesHandler implements MethodHandlerInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ReferenceProviderInterface $registry,
|
||||
private readonly int $pageSize = 20,
|
||||
) {
|
||||
}
|
||||
|
||||
public function supports(HasMethodInterface $message): bool
|
||||
{
|
||||
return $message instanceof ListResourceTemplatesRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidCursorException
|
||||
*/
|
||||
public function handle(ListResourceTemplatesRequest|HasMethodInterface $message, SessionInterface $session): Response
|
||||
{
|
||||
\assert($message instanceof ListResourceTemplatesRequest);
|
||||
|
||||
$page = $this->registry->getResourceTemplates($this->pageSize, $message->cursor);
|
||||
|
||||
return new Response(
|
||||
$message->getId(),
|
||||
new ListResourceTemplatesResult($page->references, $page->nextCursor),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue