Skip to content

Return a handler from find in modern server repositories - #1282

Merged
chemicL merged 2 commits into
mainfrom
modern-collapse-find-call
Oct 27, 2026
Merged

chemicL merged 2 commits into
mainfrom
modern-collapse-find-call

Conversation

@chemicL

@chemicL chemicL commented Oct 26, 2026

Copy link
Copy Markdown
Member

Closes #1268

Tool and prompt repositories had separate find and call/get methods, so every call looked the
primitive up twice. That's two round trips for repositories backed by a database or other external storage.

find now returns the definition together with its handler:

  • McpAsync/SyncToolRepository.find → McpAsync/SyncTool; call is removed
  • McpAsync/SyncPromptRepository.find → McpAsync/SyncPrompt; get is removed
  • McpAsync/SyncResourceRepository.find(uri) → McpAsync/SyncResource, replacing read

The features validate against the definition they found, then call its handler. ResourcesFeature
now answers an unknown URI itself (-32602 with {"uri": ...}).

Breaking: this changes the modern server's repository SPI, which shipped in 2.2.0-M1.

The tool and prompt repositories had separate find and call/get methods,
so every tools/call and prompts/get looked the primitive up twice. That
means two round trips for repositories backed by a database or remote
definitions.

find now returns McpAsyncTool/McpSyncTool or McpAsyncPrompt/McpSyncPrompt,
which carry the definition and its handler. The call/get methods are
removed from the repositories. ToolsFeature and PromptsFeature validate
against the definition and invoke the handler they found.

Closes #1268

Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Align the resource repositories with the tool and prompt ones: find(ctx,
uri) returns McpAsyncResource/McpSyncResource, carrying the read handler,
in place of read(ctx, request). ResourcesFeature now answers an unknown
URI with the -32602 error carrying {"uri": ...} itself, so repositories
no longer build it.

See #1268

Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
@chemicL chemicL added this to the 2.2.0-M2 milestone Oct 26, 2026
@chemicL
chemicL added this pull request to stack #1284 October 26, 2026 17:03
@chemicL
chemicL merged commit 5133786 into main Oct 27, 2026
25 checks passed
@chemicL
chemicL deleted the modern-collapse-find-call branch October 27, 2026 11:18
prathamgoyal787 added a commit to prathamgoyal787/java-sdk that referenced this pull request Oct 27, 2026
Adapt to find returning the tool with its handler (modelcontextprotocol#1282): validate the
Mcp-Param headers against the found tool's definition, after the
required-capabilities check and before inputSchema validation, and port
the tests to McpAsyncTool.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Combine find and call/get methods in modern server repositories

2 participants