Skip to content

[Schema] Add title field to Resource and ResourceTemplate#301

Open
blackwell-systems wants to merge 1 commit into
modelcontextprotocol:mainfrom
blackwell-systems:feat/resource-title-field
Open

[Schema] Add title field to Resource and ResourceTemplate#301
blackwell-systems wants to merge 1 commit into
modelcontextprotocol:mainfrom
blackwell-systems:feat/resource-title-field

Conversation

@blackwell-systems
Copy link
Copy Markdown
Contributor

Summary

  • Add the optional title field to Resource and ResourceTemplate, matching
    the MCP specification (2025-11-25) and the existing Tool/Prompt implementations
  • Add title to McpResource and McpResourceTemplate attributes and wire it
    through Discoverer
  • Add tests for deserialization, serialization, and null omission

Context

The spec defines title as an optional human-readable display label for all four
server capability types. Tool and Prompt already have it; Resource and
ResourceTemplate were the only two missing.

Type Machine identifier title
Tool name implemented
Prompt name implemented
Resource uri added in this PR
ResourceTemplate uriTemplate added in this PR

The $name docblocks are updated to say "short identifier" instead of
"human-readable name", matching the spec's distinction between name and title.

Backward compatible: $title defaults to null, serialization omits it when null,
and all callers use named arguments.

Fixes #296

Test plan

  • ResourceTest::testTitleFromArray verifies deserialization
  • ResourceTest::testTitleSerialization verifies output
  • ResourceTest::testTitleOmittedWhenNull verifies null omission
  • Same three tests for ResourceTemplateTest
  • Full suite: 744 tests, 2422 assertions, 0 failures

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
@chr-hertel chr-hertel added improves spec compliance Improves consistency with other SDKs such as TyepScript Schema Issues & PRs related to the Schema component labels May 11, 2026
@chr-hertel chr-hertel changed the title Add title field to Resource and ResourceTemplate [Schema] Add title field to Resource and ResourceTemplate May 11, 2026
Copy link
Copy Markdown
Contributor

@soyuka soyuka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why all the changes, can't you just add the title?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improves spec compliance Improves consistency with other SDKs such as TyepScript Schema Issues & PRs related to the Schema component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resource and ResourceTemplate are missing the title field

3 participants