[Schema] Add title field to Resource and ResourceTemplate#301
Merged
chr-hertel merged 1 commit intoMay 17, 2026
Merged
Conversation
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 modelcontextprotocol#296
soyuka
approved these changes
May 12, 2026
Contributor
soyuka
left a comment
There was a problem hiding this comment.
Except my small nitpicking comment lgtm
| * @param ?array<string, mixed> $meta Optional metadata | ||
| * @param ?Annotations $annotations optional annotations describing the resource | ||
| * @param ?Icon[] $icons optional icons representing the resource | ||
| * @param ?array<string, mixed> $meta optional metadata |
Contributor
There was a problem hiding this comment.
not sure why all the changes, can't you just add the title?
Contributor
Author
There was a problem hiding this comment.
The docblock changes align $name with the spec distinction between name (machine identifier) and title (display label). The old docblock said "human-readable name" which is now what $title is for. The other adjustments are just consistency: lowercase param descriptions and Annotations|null -> ?Annotations to match the type declaration. Happy to revert the style changes to a separate commit if you prefer a minimal diff.
6 tasks
chr-hertel
approved these changes
May 17, 2026
This was referenced May 17, 2026
chr-hertel
added a commit
that referenced
this pull request
May 18, 2026
…() (#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>
chr-hertel
added a commit
that referenced
this pull request
May 18, 2026
Wrap-up for the v0.6.0 release: capture features/BC breaks merged since v0.5.0 that were missing from documentation. - CHANGELOG: add the `title` field on `Resource`/`ResourceTemplate` (#301), a feature plus three positional-argument BC breaks. - mcp-elements.md: add the missing `title` parameter to the McpTool, McpResource, McpResourceTemplate and McpPrompt attribute reference sections; fix a missing closing paren in an `#[McpPrompt]` example. - server-builder.md: add `title?` to the `addPrompt()` row of the method reference table (stale since v0.5.0). - client.md: bump the protocol-version example to `V2025_11_25` to match the new default. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
titlefield toResourceandResourceTemplate, matchingthe MCP specification (2025-11-25) and the existing
Tool/PromptimplementationstitletoMcpResourceandMcpResourceTemplateattributes and wire itthrough
DiscovererContext
The spec defines
titleas an optional human-readable display label for all fourserver capability types.
ToolandPromptalready have it;ResourceandResourceTemplatewere the only two missing.titleToolnamePromptnameResourceuriResourceTemplateuriTemplateThe
$namedocblocks are updated to say "short identifier" instead of"human-readable name", matching the spec's distinction between
nameandtitle.Backward compatible:
$titledefaults tonull, serialization omits it when null,and all callers use named arguments.
Fixes #296
Test plan
ResourceTest::testTitleFromArrayverifies deserializationResourceTest::testTitleSerializationverifies outputResourceTest::testTitleOmittedWhenNullverifies null omissionResourceTemplateTest