Propagate @McpResource title to generated resources - #6787
Open
alpin87 wants to merge 1 commit into
Open
Conversation
The resource providers built McpSchema.Resource and ResourceTemplate without ever reading McpResource#title, so a title declared on the annotation never reached the client and clients fell back to the resource name, which defaults to the Java method name. McpTool and McpPrompt already propagate their title, and ResourceAdapter reads it correctly, but no production code calls that adapter. Set the title in all four resource providers instead, and only when it has text so that resources without a title keep serializing without one. Signed-off-by: seungmin <qortmdals94@naver.com>
This was referenced Aug 16, 2026
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.
Fixes #6786
Background —
@McpResource(title = "...")never reached the client. MCP clients then fall back toname, which defaults to the Java method name, so a server author who sets a title sees no effect and no error.Cause — The four resource providers build
McpSchema.Resource/ResourceTemplatewithout ever readingMcpResource#title:These are the runtime path —
SyncMcpAnnotationProvidersandAsyncMcpAnnotationProvidersdelegate to them.ResourceAdapter#asResourcedoes set the title, but nothing in production calls that adapter.@McpTooland@McpPromptboth propagate their title, so resources were the only family dropping it.Fix — Set the title in all four providers, for both the resource and the resource-template paths (8 sites). It is applied only when it has text, so resources without a title keep serializing exactly as before rather than gaining an empty
title: "".I deliberately kept this narrow. Routing the providers through
ResourceAdapterwould fix #6749 at the same time, but that pulls in thelastModifieddesign question raised there which has no maintainer answer yet. Happy to do it that way instead if you prefer — just say so.Validation
Added three tests to each of the four provider test classes: title propagated on a resource, title propagated on a resource template, and title absent when unset.
Verified they actually catch the bug by reverting the main-code change and re-running — 8 failures, 2 per provider:
With the fix applied:
Checkstyle passes. The commit is signed off per the DCO.