Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Client/Handler/Request/RequestHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* Interface for handling requests from the server.
*
* @template TResult
* @template-covariant TResult
*
* @author Kyrian Obikwelu <koshnawaza@gmail.com>
*/
Expand Down
19 changes: 19 additions & 0 deletions tests/Unit/Client/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
use Mcp\Client\Client;
use Mcp\Client\Configuration;
use Mcp\Client\Exception\LogicException;
use Mcp\Client\Handler\Request\ElicitationCallbackInterface;
use Mcp\Client\Handler\Request\ElicitationRequestHandler;
use Mcp\Client\Handler\Request\ListRootsRequestHandler;
use Mcp\Client\Handler\Request\RootsCallbackInterface;
use Mcp\Client\Handler\Request\SamplingCallbackInterface;
use Mcp\Client\Handler\Request\SamplingRequestHandler;
use Mcp\Schema\ClientCapabilities;
use Mcp\Schema\Extension\Apps\McpApps;
use PHPUnit\Framework\Attributes\TestDox;
Expand Down Expand Up @@ -81,6 +87,19 @@ public function testEnableExtensionRejectsDuplicate(): void
Client::builder()->enableExtension(new McpApps(), new McpApps());
}

#[TestDox('addRequestHandler() accepts handlers with concrete result types')]
public function testAddRequestHandlerAcceptsConcreteResultTypes(): void
{
$builder = Client::builder();
$elicitation = new ElicitationRequestHandler($this->createMock(ElicitationCallbackInterface::class));
$sampling = new SamplingRequestHandler($this->createMock(SamplingCallbackInterface::class));
$roots = new ListRootsRequestHandler($this->createMock(RootsCallbackInterface::class));

$this->assertSame($builder, $builder->addRequestHandler($elicitation));
$this->assertSame($builder, $builder->addRequestHandler($sampling));
$this->assertSame($builder, $builder->addRequestHandler($roots));
}

private function extractConfiguration(Client $client): Configuration
{
$config = (new \ReflectionClass($client))->getProperty('config')->getValue($client);
Expand Down