Introduce Capability Registry & Discovery
This commit is contained in:
parent
09707b4798
commit
da0d5a87a0
6 changed files with 7063 additions and 8 deletions
30
tests/Capability/Attribute/CompletionProviderFixture.php
Normal file
30
tests/Capability/Attribute/CompletionProviderFixture.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?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\Capability\Attribute;
|
||||
|
||||
use Mcp\Capability\Prompt\Completion\ProviderInterface;
|
||||
|
||||
class CompletionProviderFixture implements ProviderInterface
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public static array $completions = ['alpha', 'beta', 'gamma'];
|
||||
public static string $lastCurrentValue = '';
|
||||
|
||||
public function getCompletions(string $currentValue): array
|
||||
{
|
||||
self::$lastCurrentValue = $currentValue;
|
||||
|
||||
return array_filter(self::$completions, fn ($item) => str_starts_with($item, $currentValue));
|
||||
}
|
||||
}
|
||||
85
tests/Capability/Attribute/CompletionProviderTest.php
Normal file
85
tests/Capability/Attribute/CompletionProviderTest.php
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
<?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\Capability\Attribute;
|
||||
|
||||
use Mcp\Capability\Attribute\CompletionProvider;
|
||||
use Mcp\Tests\Fixtures\Enum\StatusEnum;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CompletionProviderTest extends TestCase
|
||||
{
|
||||
public function testCanBeConstructedWithProviderClass(): void
|
||||
{
|
||||
$attribute = new CompletionProvider(provider: CompletionProviderFixture::class);
|
||||
|
||||
$this->assertSame(CompletionProviderFixture::class, $attribute->provider);
|
||||
$this->assertNull($attribute->values);
|
||||
$this->assertNull($attribute->enum);
|
||||
}
|
||||
|
||||
public function testCanBeConstructedWithProviderInstance(): void
|
||||
{
|
||||
$instance = new CompletionProviderFixture();
|
||||
$attribute = new CompletionProvider(provider: $instance);
|
||||
|
||||
$this->assertSame($instance, $attribute->provider);
|
||||
$this->assertNull($attribute->values);
|
||||
$this->assertNull($attribute->enum);
|
||||
}
|
||||
|
||||
public function testCanBeConstructedWithValuesArray(): void
|
||||
{
|
||||
$values = ['draft', 'published', 'archived'];
|
||||
$attribute = new CompletionProvider(values: $values);
|
||||
|
||||
$this->assertNull($attribute->provider);
|
||||
$this->assertSame($values, $attribute->values);
|
||||
$this->assertNull($attribute->enum);
|
||||
}
|
||||
|
||||
public function testCanBeConstructedWithEnumClass(): void
|
||||
{
|
||||
$attribute = new CompletionProvider(enum: StatusEnum::class);
|
||||
|
||||
$this->assertNull($attribute->provider);
|
||||
$this->assertNull($attribute->values);
|
||||
$this->assertSame(StatusEnum::class, $attribute->enum);
|
||||
}
|
||||
|
||||
public function testThrowsExceptionWhenNoParametersProvided(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Only one of provider, values, or enum can be set');
|
||||
new CompletionProvider();
|
||||
}
|
||||
|
||||
public function testThrowsExceptionWhenMultipleParametersProvided(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Only one of provider, values, or enum can be set');
|
||||
new CompletionProvider(
|
||||
provider: CompletionProviderFixture::class,
|
||||
values: ['test']
|
||||
);
|
||||
}
|
||||
|
||||
public function testThrowsExceptionWhenAllParametersProvided(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Only one of provider, values, or enum can be set');
|
||||
new CompletionProvider(
|
||||
provider: CompletionProviderFixture::class,
|
||||
values: ['test'],
|
||||
enum: StatusEnum::class
|
||||
);
|
||||
}
|
||||
}
|
||||
52
tests/Capability/Attribute/McpPromptTest.php
Normal file
52
tests/Capability/Attribute/McpPromptTest.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?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\Capability\Attribute;
|
||||
|
||||
use Mcp\Capability\Attribute\McpPrompt;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class McpPromptTest extends TestCase
|
||||
{
|
||||
public function testInstantiatesWithNameAndDescription(): void
|
||||
{
|
||||
// Arrange
|
||||
$name = 'test-prompt-name';
|
||||
$description = 'This is a test prompt description.';
|
||||
|
||||
// Act
|
||||
$attribute = new McpPrompt(name: $name, description: $description);
|
||||
|
||||
// Assert
|
||||
$this->assertSame($name, $attribute->name);
|
||||
$this->assertSame($description, $attribute->description);
|
||||
}
|
||||
|
||||
public function testInstantiatesWithNullValuesForNameAndDescription(): void
|
||||
{
|
||||
// Arrange & Act
|
||||
$attribute = new McpPrompt(name: null, description: null);
|
||||
|
||||
// Assert
|
||||
$this->assertNull($attribute->name);
|
||||
$this->assertNull($attribute->description);
|
||||
}
|
||||
|
||||
public function testInstantiatesWithMissingOptionalArguments(): void
|
||||
{
|
||||
// Arrange & Act
|
||||
$attribute = new McpPrompt(); // Use default constructor values
|
||||
|
||||
// Assert
|
||||
$this->assertNull($attribute->name);
|
||||
$this->assertNull($attribute->description);
|
||||
}
|
||||
}
|
||||
71
tests/Capability/Attribute/McpResourceTemplateTest.php
Normal file
71
tests/Capability/Attribute/McpResourceTemplateTest.php
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<?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\Capability\Attribute;
|
||||
|
||||
use Mcp\Capability\Attribute\McpResourceTemplate;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class McpResourceTemplateTest extends TestCase
|
||||
{
|
||||
public function testInstantiatesWithCorrectProperties(): void
|
||||
{
|
||||
// Arrange
|
||||
$uriTemplate = 'file:///{path}/data';
|
||||
$name = 'test-template-name';
|
||||
$description = 'This is a test template description.';
|
||||
$mimeType = 'application/json';
|
||||
|
||||
// Act
|
||||
$attribute = new McpResourceTemplate(
|
||||
uriTemplate: $uriTemplate,
|
||||
name: $name,
|
||||
description: $description,
|
||||
mimeType: $mimeType,
|
||||
);
|
||||
|
||||
// Assert
|
||||
$this->assertSame($uriTemplate, $attribute->uriTemplate);
|
||||
$this->assertSame($name, $attribute->name);
|
||||
$this->assertSame($description, $attribute->description);
|
||||
$this->assertSame($mimeType, $attribute->mimeType);
|
||||
}
|
||||
|
||||
public function testInstantiatesWithNullValuesForNameAndDescription(): void
|
||||
{
|
||||
// Arrange & Act
|
||||
$attribute = new McpResourceTemplate(
|
||||
uriTemplate: 'test://{id}', // uriTemplate is required
|
||||
name: null,
|
||||
description: null,
|
||||
mimeType: null,
|
||||
);
|
||||
|
||||
// Assert
|
||||
$this->assertSame('test://{id}', $attribute->uriTemplate);
|
||||
$this->assertNull($attribute->name);
|
||||
$this->assertNull($attribute->description);
|
||||
$this->assertNull($attribute->mimeType);
|
||||
}
|
||||
|
||||
public function testInstantiatesWithMissingOptionalArguments(): void
|
||||
{
|
||||
// Arrange & Act
|
||||
$uriTemplate = 'tmpl://{key}';
|
||||
$attribute = new McpResourceTemplate(uriTemplate: $uriTemplate);
|
||||
|
||||
// Assert
|
||||
$this->assertSame($uriTemplate, $attribute->uriTemplate);
|
||||
$this->assertNull($attribute->name);
|
||||
$this->assertNull($attribute->description);
|
||||
$this->assertNull($attribute->mimeType);
|
||||
}
|
||||
}
|
||||
77
tests/Capability/Attribute/McpResourceTest.php
Normal file
77
tests/Capability/Attribute/McpResourceTest.php
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<?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\Capability\Attribute;
|
||||
|
||||
use Mcp\Capability\Attribute\McpResource;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class McpResourceTest extends TestCase
|
||||
{
|
||||
public function testInstantiatesWithCorrectProperties(): void
|
||||
{
|
||||
// Arrange
|
||||
$uri = 'file:///test/resource';
|
||||
$name = 'test-resource-name';
|
||||
$description = 'This is a test resource description.';
|
||||
$mimeType = 'text/plain';
|
||||
$size = 1024;
|
||||
|
||||
// Act
|
||||
$attribute = new McpResource(
|
||||
uri: $uri,
|
||||
name: $name,
|
||||
description: $description,
|
||||
mimeType: $mimeType,
|
||||
size: $size,
|
||||
);
|
||||
|
||||
// Assert
|
||||
$this->assertSame($uri, $attribute->uri);
|
||||
$this->assertSame($name, $attribute->name);
|
||||
$this->assertSame($description, $attribute->description);
|
||||
$this->assertSame($mimeType, $attribute->mimeType);
|
||||
$this->assertSame($size, $attribute->size);
|
||||
}
|
||||
|
||||
public function testInstantiatesWithNullValuesForNameAndDescription(): void
|
||||
{
|
||||
// Arrange & Act
|
||||
$attribute = new McpResource(
|
||||
uri: 'file:///test', // URI is required
|
||||
name: null,
|
||||
description: null,
|
||||
mimeType: null,
|
||||
size: null,
|
||||
);
|
||||
|
||||
// Assert
|
||||
$this->assertSame('file:///test', $attribute->uri);
|
||||
$this->assertNull($attribute->name);
|
||||
$this->assertNull($attribute->description);
|
||||
$this->assertNull($attribute->mimeType);
|
||||
$this->assertNull($attribute->size);
|
||||
}
|
||||
|
||||
public function testInstantiatesWithMissingOptionalArguments(): void
|
||||
{
|
||||
// Arrange & Act
|
||||
$uri = 'file:///only-uri';
|
||||
$attribute = new McpResource(uri: $uri);
|
||||
|
||||
// Assert
|
||||
$this->assertSame($uri, $attribute->uri);
|
||||
$this->assertNull($attribute->name);
|
||||
$this->assertNull($attribute->description);
|
||||
$this->assertNull($attribute->mimeType);
|
||||
$this->assertNull($attribute->size);
|
||||
}
|
||||
}
|
||||
52
tests/Capability/Attribute/McpToolTest.php
Normal file
52
tests/Capability/Attribute/McpToolTest.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?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\Capability\Attribute;
|
||||
|
||||
use Mcp\Capability\Attribute\McpTool;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class McpToolTest extends TestCase
|
||||
{
|
||||
public function testInstantiatesWithCorrectProperties(): void
|
||||
{
|
||||
// Arrange
|
||||
$name = 'test-tool-name';
|
||||
$description = 'This is a test description.';
|
||||
|
||||
// Act
|
||||
$attribute = new McpTool(name: $name, description: $description);
|
||||
|
||||
// Assert
|
||||
$this->assertSame($name, $attribute->name);
|
||||
$this->assertSame($description, $attribute->description);
|
||||
}
|
||||
|
||||
public function testInstantiatesWithNullValuesForNameAndDescription(): void
|
||||
{
|
||||
// Arrange & Act
|
||||
$attribute = new McpTool(name: null, description: null);
|
||||
|
||||
// Assert
|
||||
$this->assertNull($attribute->name);
|
||||
$this->assertNull($attribute->description);
|
||||
}
|
||||
|
||||
public function testInstantiatesWithMissingOptionalArguments(): void
|
||||
{
|
||||
// Arrange & Act
|
||||
$attribute = new McpTool(); // Use default constructor values
|
||||
|
||||
// Assert
|
||||
$this->assertNull($attribute->name);
|
||||
$this->assertNull($attribute->description);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue