Skip to content

Enforce required client capabilities in the modern server - #1283

Open
chemicL wants to merge 1 commit into
modern-collapse-find-callfrom
modern-required-capabilities
Open

chemicL wants to merge 1 commit into
modern-collapse-find-callfrom
modern-required-capabilities

Conversation

@chemicL

@chemicL chemicL commented Oct 26, 2026

Copy link
Copy Markdown
Member

Handlers had to check ctx.clientCapabilities() themselves before asking for elicitation, sampling or
roots. Nothing stopped one from sending an input request the client never declared.

  • Required capabilities: tools, prompts and resources declare what they can't work without via
    of(..., requiredCapabilities, handler) on McpAsync/SyncTool, McpAsync/SyncPrompt and
    McpAsync/SyncResource. The feature checks this before the handler runs. A client that lacks a
    capability gets -32021, listing only what's missing.
  • Optional input: handlers request it only when the client declares the capability, and the
    server enforces that. McpServer rejects any input request for an undeclared capability as an
    internal error, which covers extension methods too. URL-mode elicitation is checked separately
    from form mode.
  • Docs: the javadoc on the handler types, InputRequired, McpRequestContext and McpException
    says which strategy to use.

Handlers had to check ctx.clientCapabilities() themselves before asking
for elicitation, sampling or roots. Nothing stopped one from sending an
input request the client never declared.

Tools, prompts and resources can now declare the capabilities they
cannot work without, via of(..., requiredCapabilities, handler) on
McpAsync/SyncTool, McpAsync/SyncPrompt and McpAsync/SyncResource. The
feature checks them before the handler runs and answers a client that
lacks them with -32021, listing only what is missing.

Optional input is still requested only when the client declares it.
McpServer now rejects any input request for an undeclared capability as
an internal error, checking URL-mode elicitation separately. This covers
extension methods too.

The javadoc on the handler types, InputRequired, McpRequestContext and
McpException describes which strategy to use. The conformance servlet
declares its requirements instead of checking them by hand.

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 added enhancement New feature or request area/server labels Oct 26, 2026

This branch has not been deployed

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

Labels

area/server enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants