[Server] Serve an extension's methods under the modern lifecycle (#454)
* [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.
This commit is contained in:
parent
7e38c94954
commit
b97389325f
1 changed files with 165 additions and 4 deletions
42
tests/Unit/Server/Extension/UnservedThingExtension.php
Normal file
42
tests/Unit/Server/Extension/UnservedThingExtension.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?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 [];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue