php-sdk/src/Server/RequestHandler/ListPromptsHandler.php
Sule-Balogun Olanrewaju 325b4aaf9c
Add support for pagination on list requests (#55)
10 - Added the list resources handler with test class

10 - Update the ListPromptsHandler to use annotations

10 - Add the list resource handler, and it's test as well

10 - Added the registry logic

10 - Added the list tools handler logic

10 - Fix all php-cs-fixer related issues

10 - Resolved phpstan issues for ListPromptsHandlerTest

10 - Resolved phpstan issues for ListToolsHandlerTest

10 - Resolved phpstan issues for ListResourcesHandlerTest

10 - Resolved phpstan issues in registry class

10 - Resolved phpstan issues for the handler class

10 - Resolved php cs fixer issues

10 - Resolved all phpstan issues by generating the baseline again

10 - Remove the two loop operation and use foreach for optimization

10 - Removed unused code and resolved namespace

10 - Add signatures to interface and registry

10 - Add updated phpstan rule set

10 - Arranged according to property type

10 - Introduce reference page DTO, fix all failing test

10 - Resolve cs-fixer issues

10 - Resolve phpstan issues

10 - Resolve php cs fixer issues

10 - Created a reference directory for the Page DTO

10 - Remove manual loop for clean code readability

Co-authored-by: larry.sulebalogun <larry.sulebalogun@tillo.io>
2025-09-24 21:44:32 +02:00

53 lines
1.5 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\Server\RequestHandler;
use Mcp\Capability\Registry\ReferenceProviderInterface;
use Mcp\Exception\InvalidCursorException;
use Mcp\Schema\JsonRpc\HasMethodInterface;
use Mcp\Schema\JsonRpc\Response;
use Mcp\Schema\Request\ListPromptsRequest;
use Mcp\Schema\Result\ListPromptsResult;
use Mcp\Server\MethodHandlerInterface;
use Mcp\Server\Session\SessionInterface;
/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
final class ListPromptsHandler implements MethodHandlerInterface
{
public function __construct(
private readonly ReferenceProviderInterface $registry,
private readonly int $pageSize = 20,
) {
}
public function supports(HasMethodInterface $message): bool
{
return $message instanceof ListPromptsRequest;
}
/**
* @throws InvalidCursorException
*/
public function handle(ListPromptsRequest|HasMethodInterface $message, SessionInterface $session): Response
{
\assert($message instanceof ListPromptsRequest);
$page = $this->registry->getPrompts($this->pageSize, $message->cursor);
return new Response(
$message->getId(),
new ListPromptsResult($page->references, $page->nextCursor),
);
}
}