[Schema] Add title field to Resource and ResourceTemplate#301
Open
blackwell-systems wants to merge 1 commit into
Open
[Schema] Add title field to Resource and ResourceTemplate#301blackwell-systems wants to merge 1 commit into
blackwell-systems wants to merge 1 commit into
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.
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