* [Server] Serve an extension's methods under the modern lifecycle The modern dispatcher takes the method-to-extension map the builder collects, so a method belonging to an extension this server does not serve is answered -32601 naming the extension instead of a bare "no handler found". It is still an unknown method - the server genuinely does not implement it - but the caller can now act on the answer. * [Server] Reject two extensions claiming the same RPC method The message factory resolves a contested method to whichever class registered first, while extensionMethods kept the last one — so error messages could name the wrong extension. Also fixes a test that claimed to prove a method gets named by its extension while asserting the opposite; the case it meant to cover (an enabled extension with no handler for one of its methods) had no coverage at all.
42 lines
1,007 B
PHP
42 lines
1,007 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\Tests\Unit\Server\Extension;
|
|
|
|
use Mcp\Schema\Extension\ExtensionIdentifier;
|
|
use Mcp\Schema\Extension\ExtensionInterface;
|
|
|
|
/**
|
|
* An extension that declares a method it does not serve: {@see ThingListRequest}
|
|
* is registered so the method decodes, but no handler answers it.
|
|
*/
|
|
final class UnservedThingExtension implements ExtensionInterface
|
|
{
|
|
public function getId(): ExtensionIdentifier
|
|
{
|
|
return new ExtensionIdentifier('com.example/unserved-things');
|
|
}
|
|
|
|
public function getCapabilities(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public function getMessages(): array
|
|
{
|
|
return [ThingListRequest::class];
|
|
}
|
|
|
|
public function getRequestHandlers(): iterable
|
|
{
|
|
return [];
|
|
}
|
|
}
|