Skip to content

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

Merged
chr-hertel merged 1 commit into
modelcontextprotocol:mainfrom
blackwell-systems:feat/resource-title-field
May 17, 2026
Merged

[Schema] Add title field to Resource and ResourceTemplate#301
chr-hertel merged 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.

@chr-hertel chr-hertel merged commit a820497 into modelcontextprotocol:main May 17, 2026
18 checks passed
@chr-hertel chr-hertel added this to the 0.6.0 milestone 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>
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