[Schema][Server] feat: support sampling with tools (#409)
* feat: support sampling with tools * address sampling tools review feedback * tighten sampling tools spec compliance * drop SamplingStopReason enum in favor of open string The spec leaves stopReason open for provider-specific values, so upcasting the four known ones to enum cases makes every future enum addition a silent BC break for string comparisons. --------- Co-authored-by: Christopher Hertel <mail@christopher-hertel.de>
This commit is contained in:
parent
d8cc21a345
commit
82aac972c1
1 changed files with 682 additions and 27 deletions
45
tests/Unit/Schema/ClientCapabilitiesSamplingTest.php
Normal file
45
tests/Unit/Schema/ClientCapabilitiesSamplingTest.php
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<?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\Schema;
|
||||
|
||||
use Mcp\Schema\ClientCapabilities;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class ClientCapabilitiesSamplingTest extends TestCase
|
||||
{
|
||||
public function testSamplingSubCapabilitiesRoundTrip(): void
|
||||
{
|
||||
$capabilities = new ClientCapabilities(sampling: true, samplingContext: true, samplingTools: true);
|
||||
$serialized = $capabilities->jsonSerialize();
|
||||
|
||||
$this->assertObjectHasProperty('context', $serialized['sampling']);
|
||||
$this->assertObjectHasProperty('tools', $serialized['sampling']);
|
||||
|
||||
$hydrated = ClientCapabilities::fromArray(json_decode(json_encode($serialized, \JSON_THROW_ON_ERROR), true, flags: \JSON_THROW_ON_ERROR));
|
||||
$this->assertTrue($hydrated->sampling);
|
||||
$this->assertTrue($hydrated->samplingContext);
|
||||
$this->assertTrue($hydrated->samplingTools);
|
||||
}
|
||||
|
||||
public function testSamplingSubCapabilitiesAreHydratedFromObject(): void
|
||||
{
|
||||
$sampling = new \stdClass();
|
||||
$sampling->context = new \stdClass();
|
||||
$sampling->tools = new \stdClass();
|
||||
|
||||
$capabilities = ClientCapabilities::fromArray(['sampling' => $sampling]);
|
||||
|
||||
$this->assertTrue($capabilities->sampling);
|
||||
$this->assertTrue($capabilities->samplingContext);
|
||||
$this->assertTrue($capabilities->samplingTools);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue