Add title parameter to Builder::addResource() and addResourceTemplate() (#310)

#301 added the `title` field to the `Resource`/`ResourceTemplate` schema
classes and the `McpResource`/`McpResourceTemplate` attributes, but the
manual registration methods on `Builder` were never updated — so manual
registration could not set a resource title, unlike tools and prompts.

Add a `$title` parameter between `$name` and `$description` (matching
`addTool()`/`addPrompt()`) and propagate it through `ArrayLoader` when
constructing the `Resource`/`ResourceTemplate` objects.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Christopher Hertel 2026-05-18 20:02:01 +02:00 • committed by GitHub
commit 1300d2ee7d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -56,6 +56,7 @@ final class ArrayLoader implements LoaderInterface
* handler: Handler,
* uri: string,
* name: ?string,
* title: ?string,
* description: ?string,
* mimeType: ?string,
* size: int|null,
@ -67,6 +68,7 @@ final class ArrayLoader implements LoaderInterface
* handler: Handler,
* uriTemplate: string,
* name: ?string,
* title: ?string,
* description: ?string,
* mimeType: ?string,
* annotations: ?Annotations,
@ -157,6 +159,7 @@ final class ArrayLoader implements LoaderInterface
$resource = new Resource(
uri: $data['uri'],
name: $name,
title: $data['title'] ?? null,
description: $description,
mimeType: $data['mimeType'] ?? null,
annotations: $data['annotations'] ?? null,
@ -197,6 +200,7 @@ final class ArrayLoader implements LoaderInterface
$template = new ResourceTemplate(
uriTemplate: $data['uriTemplate'],
name: $name,
title: $data['title'] ?? null,
description: $description,
mimeType: $data['mimeType'] ?? null,
annotations: $data['annotations'] ?? null,