Add title field to Resource and ResourceTemplate (#301)
The MCP specification (2025-11-25) defines an optional title field for Resource and ResourceTemplate as a human-readable display label, distinct from name (a short identifier). Tool and Prompt already implement this field; Resource and ResourceTemplate were missing it. Changes: - Add title parameter to Resource and ResourceTemplate constructors - Add title to fromArray(), jsonSerialize(), and PHPStan type arrays - Add title to McpResource and McpResourceTemplate attributes - Pass title through Discoverer when constructing schema objects - Add tests for deserialization, serialization, and null omission Fixes #296
This commit is contained in:
parent
967c5cda4d
commit
a820497b62
1 changed files with 110 additions and 21 deletions
|
|
@ -77,10 +77,45 @@ class ResourceTest extends TestCase
|
|||
$this->assertInstanceOf(Resource::class, $resource);
|
||||
$this->assertSame(self::VALID_URI, $resource->uri);
|
||||
$this->assertSame('list-books', $resource->name);
|
||||
$this->assertNull($resource->title);
|
||||
$this->assertNull($resource->description);
|
||||
$this->assertNull($resource->meta);
|
||||
}
|
||||
|
||||
public function testTitleFromArray(): void
|
||||
{
|
||||
$resource = Resource::fromArray([
|
||||
'uri' => self::VALID_URI,
|
||||
'name' => 'list-books',
|
||||
'title' => 'Book Listing',
|
||||
]);
|
||||
|
||||
$this->assertSame('Book Listing', $resource->title);
|
||||
}
|
||||
|
||||
public function testTitleSerialization(): void
|
||||
{
|
||||
$resource = new Resource(
|
||||
uri: self::VALID_URI,
|
||||
name: 'list-books',
|
||||
title: 'Book Listing',
|
||||
);
|
||||
|
||||
$data = $resource->jsonSerialize();
|
||||
$this->assertSame('Book Listing', $data['title']);
|
||||
}
|
||||
|
||||
public function testTitleOmittedWhenNull(): void
|
||||
{
|
||||
$resource = new Resource(
|
||||
uri: self::VALID_URI,
|
||||
name: 'list-books',
|
||||
);
|
||||
|
||||
$data = $resource->jsonSerialize();
|
||||
$this->assertArrayNotHasKey('title', $data);
|
||||
}
|
||||
|
||||
#[DataProvider('provideInvalidResources')]
|
||||
public function testFromArrayInvalid(array $input, string $expectedExceptionMessage): void
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue