Skip to content

[Schema][Server] Add top-level title to Tool#288

Merged
chr-hertel merged 6 commits intomodelcontextprotocol:mainfrom
e0ipso:feature/1--tool-title-spec-compliance
Apr 26, 2026
Merged

[Schema][Server] Add top-level title to Tool#288
chr-hertel merged 6 commits intomodelcontextprotocol:mainfrom
e0ipso:feature/1--tool-title-spec-compliance

Conversation

@e0ipso
Copy link
Copy Markdown
Contributor

@e0ipso e0ipso commented Apr 19, 2026

Summary

Test plan

  • vendor/bin/phpunit pass.
  • New unit coverage: ToolTest (construction, serialization key order, fromArray, round-trip) via data providers.
  • DiscovererToolTitleTest exercises #[McpTool(title: ...)] end-to-end against the shared DiscoverableToolHandler fixture.
  • ArrayLoaderToolTitleTest verifies the loader forwards title into the registered Tool.
  • McpToolTest covers the new attribute field and its default.

DDEV User added 5 commits April 19, 2026 17:44
Mirror PR modelcontextprotocol#278's Prompt change for Tool:

- Add optional ?string $title to Mcp\Schema\Tool between $name
  and $inputSchema. fromArray() now reads $data['title'];
  jsonSerialize() emits 'title' right after 'name'. The
  @phpstan-type ToolData gains title?: string.
- Add ?string $title to the #[McpTool] attribute between $name
  and $description.
- Note ToolAnnotations::$title as deprecated-for-display in
  favor of Tool::$title per MCP spec 2025-06-18 (PHPDoc only,
  field retained for BC).

Phase 1 of plan 01--tool-title-spec-compliance. Later phases
update Discoverer, Builder::addTool(), ArrayLoader, and the
conformance fixture to match the new signature.
- Discoverer::processMethod() now propagates McpTool::$title
  into every discovered Tool via named arguments.
- Builder::addTool() accepts ?string $title between $name and
  $description. [BC Break] positional callers passing the old
  $description as 3rd positional argument must switch to named
  arguments, matching the precedent set for addPrompt() in
  0.5.0.
- tests/Conformance/server.php migrated to named-argument form
  for every addTool() call.

Phase 2 of plan 01--tool-title-spec-compliance.
ArrayLoader now reads 'title' from each tool config entry and
passes it into the Tool constructor, completing the wiring
from Builder::addTool() through array-driven registration.

The $tools @param array-shape typedef gains title: ?string
between name and description.

Phase 3 of plan 01--tool-title-spec-compliance.
- New tests/Unit/Schema/ToolTest.php: constructor round-trip,
  jsonSerialize key-order when title set vs null, fromArray
  tolerance.
- New tests/Unit/Capability/Discovery/DiscovererToolTitleTest
  plus a TitleFixture class verifying McpTool(title: ...)
  propagates through discovery into the registered Tool.
- New tests/Unit/Capability/Registry/Loader/ArrayLoader...
  test verifying array-driven title propagation.
- Extend McpToolTest for title named-arg and default-null.
- Extend BuilderTest with addTool(title: 't') propagation.
- Update tests/Unit/.../RegistryTest, CallToolHandlerTest,
  ListToolsHandlerTest and examples/.../server.php
  new Tool(...) call sites to pass title (named args) so
  they match the new constructor signature.
- CHANGELOG 0.6.0 section: feature bullet + [BC Break]
  note for addTool() signature, mirroring 0.5.0 Prompt
  entries.
- docs/server-builder.md: addTool() row and prose now
  list title? between name and description.

Phase 4 of plan 01--tool-title-spec-compliance. All 730
phpunit tests pass; remaining phpstan warnings are
pre-existing and unrelated to Tool.title.
Move `title` to the end of the Tool, Builder::addTool, and McpTool
attribute constructors with a default of null. This preserves
positional-argument compatibility and removes the need for
`title: null` boilerplate at call sites. JSON serialization order
(name, title, inputSchema, ...) is unchanged.

Also tighten the new tests: parameterize ToolTest with data
providers, fold the Discoverer title fixture into the existing
DiscoverableToolHandler, and drop the reflection-heavy Builder
test that overlapped with ArrayLoaderToolTitleTest.
@e0ipso
Copy link
Copy Markdown
Contributor Author

e0ipso commented Apr 19, 2026

The, unrelated, CI failures are fixed in #289

Copy link
Copy Markdown
Member

@chr-hertel chr-hertel left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this @e0ipso - only small consistency issue and please add an entry to the changelog for 0.5 - thanks already! 🙏

Rebase will solve the CS issue - thanks to you :D

Comment thread src/Capability/Attribute/McpTool.php Outdated
Comment thread src/Schema/Tool.php Outdated
Comment thread src/Server/Builder.php Outdated
@chr-hertel chr-hertel changed the title feat(schema): add top-level title to Tool [Schema][Server] Add top-level title to Tool Apr 20, 2026
@chr-hertel chr-hertel added Server Issues & PRs related to the Server component Schema Issues & PRs related to the Schema component improves spec compliance Improves consistency with other SDKs such as TyepScript labels Apr 20, 2026
@chr-hertel chr-hertel added this to the 0.5.0 milestone Apr 20, 2026
@chr-hertel chr-hertel added the needs more work Not ready to be merged yet, needs additional follow-up from the author(s). label Apr 20, 2026
@e0ipso e0ipso requested a review from chr-hertel April 20, 2026 21:24
@chr-hertel chr-hertel removed the needs more work Not ready to be merged yet, needs additional follow-up from the author(s). label Apr 26, 2026
@chr-hertel chr-hertel merged commit fb2c8c2 into modelcontextprotocol:main Apr 26, 2026
17 checks passed
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 Server Issues & PRs related to the Server component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Server] Missing top-level title field in Tool schema

2 participants