Class ModernClientHandlerSupport
java.lang.Object
org.springframework.ai.mcp.annotation.common.ModernClientHandlerSupport
Lets a client-side handler method serve MCP connections of both protocols, whichever
schema types it is written against: those of the legacy protocol
(
io.modelcontextprotocol.spec.McpSchema, referred to as McpSchema in
this class) or those of the 2026-07-28 ("modern") revision
(io.modelcontextprotocol.modern.McpSchema).
The two families carry the same data, with two exceptions:
- A legacy URL elicitation request has an
elicitationIdand a modern one has not. A modern URL request can therefore not be handed to a method that takes the legacy types. - A legacy elicitation result has a
_metaand a modern one has not, so the_metais left out when a result is converted to the modern type.
A handler method may also take the ToolContext of the tool call that it serves.
It is passed for the tool calls of a modern connection, where the handlers are set for
each call. It is null for a legacy connection, whose requests are not tied to a
tool call, and for a modern client that is used directly.
- Since:
- 2.1.0
- Author:
- Christian Tzolov
-
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable Class<?>The type of the elicitation request that a reactive@McpElicitationmethod takes.static booleanclaimsFormElicitation(Method method) Whether an@McpElicitationmethod stands for the form elicitation requests of the clients it names, of whichever protocol: its parameter takes a form request of either schema.static booleanclaimsUrlElicitation(Method method) Whether an@McpElicitationmethod stands for the URL elicitation requests of the clients it names: its parameter takes a URL request of either schema.static @Nullable Class<?>elicitRequestParameterType(Method method) The type of the elicitation request that a synchronous@McpElicitationmethod takes.static booleanhandlesLegacyElicitation(Method method) Whether a synchronous@McpElicitationmethod can answer elicitation requests of a legacy connection.static booleanhandlesModernFormElicitation(Method method) Whether a synchronous@McpElicitationmethod can answer the form elicitation requests of a modern connection.static booleanWhether a reactive@McpElicitationmethod can answer the form elicitation requests of a modern connection: its parameter takes a form request, of either schema.static booleanhandlesModernUrlElicitation(Method method) Whether a synchronous@McpElicitationmethod can answer the URL elicitation requests of a modern connection.static booleanWhether a reactive@McpElicitationmethod can answer the URL elicitation requests of a modern connection.static booleanisModernElicitRequestType(Class<?> type) Whether the type is an elicitation request of the modern schema.static booleanisModernElicitResultType(Class<?> type) Whether the type is an elicitation result of the modern schema.static booleanisToolContextType(Class<?> type) Whether the type is theToolContextthat a handler method may take.static booleanreturnsMonoOfVoid(Method method) Whether a reactive@McpProgressmethod can be called: it returns aMono<Void>.static booleantakesElicitRequest(Method method) Whether the method takes one elicitation request of either schema and nothing else but, optionally, aToolContext, whatever it returns.static booleantakesToolContext(Method method) Whether the method takes aToolContext.static io.modelcontextprotocol.spec.McpSchema.ElicitRequesttoLegacyElicitRequest(io.modelcontextprotocol.modern.McpSchema.ElicitRequest request) Converts a modern form elicitation request to the legacy type.static io.modelcontextprotocol.spec.McpSchema.ElicitResulttoLegacyElicitResult(io.modelcontextprotocol.modern.McpSchema.ElicitResult result) Converts a modern elicitation result to the legacy type.static io.modelcontextprotocol.spec.McpSchema.ProgressNotificationtoLegacyProgress(io.modelcontextprotocol.modern.McpSchema.ProgressParams progress) Converts a modern progress to the legacy notification type.static List<io.modelcontextprotocol.spec.McpSchema.Prompt>toLegacyPrompts(List<io.modelcontextprotocol.modern.McpSchema.Prompt> prompts) Converts the prompts of the modern schema to those of the legacy schema.static List<io.modelcontextprotocol.spec.McpSchema.Resource>toLegacyResources(List<io.modelcontextprotocol.modern.McpSchema.Resource> resources) Converts the resources of the modern schema to those of the legacy schema.static List<io.modelcontextprotocol.spec.McpSchema.Tool>toLegacyTools(List<io.modelcontextprotocol.modern.McpSchema.Tool> tools) Converts the tools of the modern schema to those of the legacy schema.static io.modelcontextprotocol.modern.McpSchema.ElicitRequesttoModernElicitRequest(io.modelcontextprotocol.spec.McpSchema.ElicitRequest request) Converts a legacy elicitation request to the modern type.static io.modelcontextprotocol.modern.McpSchema.ElicitResulttoModernElicitResult(io.modelcontextprotocol.spec.McpSchema.ElicitResult result) Converts a legacy elicitation result to the modern type.static io.modelcontextprotocol.modern.McpSchema.ProgressParamstoModernProgress(io.modelcontextprotocol.spec.McpSchema.ProgressNotification notification) Converts a legacy progress notification to the modern type.static List<io.modelcontextprotocol.modern.McpSchema.Prompt>toModernPrompts(List<io.modelcontextprotocol.spec.McpSchema.Prompt> prompts) Converts the prompts of the legacy schema to those of the modern schema.static List<io.modelcontextprotocol.modern.McpSchema.Resource>toModernResources(List<io.modelcontextprotocol.spec.McpSchema.Resource> resources) Converts the resources of the legacy schema to those of the modern schema.static List<io.modelcontextprotocol.modern.McpSchema.Tool>toModernTools(List<io.modelcontextprotocol.spec.McpSchema.Tool> tools) Converts the tools of the legacy schema to those of the modern schema.
-
Method Details
-
isModernElicitRequestType
Whether the type is an elicitation request of the modern schema.- Parameters:
type- the type to check- Returns:
truefor the modernElicitRequestand its two modes
-
isModernElicitResultType
Whether the type is an elicitation result of the modern schema.- Parameters:
type- the type to check- Returns:
truefor the modernElicitResult
-
handlesModernFormElicitation
Whether a synchronous@McpElicitationmethod can answer the form elicitation requests of a modern connection. It can when its parameter takes a form request of either schema.- Parameters:
method- the annotated method- Returns:
trueif the method handles modern form requests
-
handlesModernFormElicitationAsync
Whether a reactive@McpElicitationmethod can answer the form elicitation requests of a modern connection: its parameter takes a form request, of either schema.- Parameters:
method- the annotated method- Returns:
trueif the method handles modern form requests
-
handlesModernUrlElicitationAsync
Whether a reactive@McpElicitationmethod can answer the URL elicitation requests of a modern connection. It can only when its parameter takes a URL request of the modern schema, because the legacy one requires anelicitationId.- Parameters:
method- the annotated method- Returns:
trueif the method handles modern URL requests
-
handlesModernUrlElicitation
Whether a synchronous@McpElicitationmethod can answer the URL elicitation requests of a modern connection. It can only when its parameter takes a URL request of the modern schema, because the legacy one requires anelicitationId.- Parameters:
method- the annotated method- Returns:
trueif the method handles modern URL requests
-
handlesLegacyElicitation
Whether a synchronous@McpElicitationmethod can answer elicitation requests of a legacy connection. Every synchronous elicitation method can: one that takes a form request answers the form requests, and one that takes a URL request, of either schema, answers the URL requests of a client that declares them.- Parameters:
method- the annotated method- Returns:
trueif the method handles legacy requests
-
claimsFormElicitation
Whether an@McpElicitationmethod stands for the form elicitation requests of the clients it names, of whichever protocol: its parameter takes a form request of either schema. A method that is not a synchronous elicitation handler, such as a reactive one, counts as standing for them.- Parameters:
method- the annotated method- Returns:
trueif no other method may answer form requests for the same client
-
claimsUrlElicitation
Whether an@McpElicitationmethod stands for the URL elicitation requests of the clients it names: its parameter takes a URL request of either schema. A method that is not a synchronous elicitation handler counts as standing for them.- Parameters:
method- the annotated method- Returns:
trueif no other method may answer URL requests for the same client
-
elicitRequestParameterType
The type of the elicitation request that a synchronous@McpElicitationmethod takes. Such a method takes one elicitation request of either schema and, optionally, aToolContext, and it returns an elicitation result of either schema or aStructuredElicitResult.- Parameters:
method- the annotated method- Returns:
- the type of its request parameter, or
nullif the method is not a synchronous elicitation handler
-
asyncElicitRequestParameterType
The type of the elicitation request that a reactive@McpElicitationmethod takes. Such a method takes one elicitation request of either schema and, optionally, aToolContext, and it returns aMonoof an elicitation result of either schema or of aStructuredElicitResult.- Parameters:
method- the annotated method- Returns:
- the type of its request parameter, or
nullif the method is not a reactive elicitation handler
-
takesElicitRequest
Whether the method takes one elicitation request of either schema and nothing else but, optionally, aToolContext, whatever it returns.- Parameters:
method- the annotated method- Returns:
trueif the parameters are those of an elicitation handler
-
returnsMonoOfVoid
Whether a reactive@McpProgressmethod can be called: it returns aMono<Void>.- Parameters:
method- the annotated method- Returns:
trueif the method returnsMono<Void>
-
isToolContextType
Whether the type is theToolContextthat a handler method may take.- Parameters:
type- the type to check- Returns:
trueforToolContext
-
takesToolContext
Whether the method takes aToolContext.- Parameters:
method- the method to check- Returns:
trueif one of its parameters is aToolContext
-
toModernElicitRequest
public static io.modelcontextprotocol.modern.McpSchema.ElicitRequest toModernElicitRequest(io.modelcontextprotocol.spec.McpSchema.ElicitRequest request) Converts a legacy elicitation request to the modern type. TheelicitationIdof a URL request is left out.- Parameters:
request- the legacy request- Returns:
- the modern request
-
toLegacyElicitRequest
public static io.modelcontextprotocol.spec.McpSchema.ElicitRequest toLegacyElicitRequest(io.modelcontextprotocol.modern.McpSchema.ElicitRequest request) Converts a modern form elicitation request to the legacy type.- Parameters:
request- the modern request- Returns:
- the legacy request
- Throws:
IllegalArgumentException- for a URL request, which has noelicitationId
-
toModernElicitResult
public static io.modelcontextprotocol.modern.McpSchema.ElicitResult toModernElicitResult(io.modelcontextprotocol.spec.McpSchema.ElicitResult result) Converts a legacy elicitation result to the modern type. The_metaof the result is left out.- Parameters:
result- the legacy result- Returns:
- the modern result
-
toLegacyElicitResult
public static io.modelcontextprotocol.spec.McpSchema.ElicitResult toLegacyElicitResult(io.modelcontextprotocol.modern.McpSchema.ElicitResult result) Converts a modern elicitation result to the legacy type.- Parameters:
result- the modern result- Returns:
- the legacy result
-
toModernProgress
public static io.modelcontextprotocol.modern.McpSchema.ProgressParams toModernProgress(io.modelcontextprotocol.spec.McpSchema.ProgressNotification notification) Converts a legacy progress notification to the modern type.- Parameters:
notification- the legacy notification- Returns:
- the modern progress
-
toLegacyProgress
public static io.modelcontextprotocol.spec.McpSchema.ProgressNotification toLegacyProgress(io.modelcontextprotocol.modern.McpSchema.ProgressParams progress) Converts a modern progress to the legacy notification type.- Parameters:
progress- the modern progress- Returns:
- the legacy notification
-
toModernTools
public static List<io.modelcontextprotocol.modern.McpSchema.Tool> toModernTools(List<io.modelcontextprotocol.spec.McpSchema.Tool> tools) Converts the tools of the legacy schema to those of the modern schema.- Parameters:
tools- the legacy tools- Returns:
- the modern tools
-
toLegacyTools
public static List<io.modelcontextprotocol.spec.McpSchema.Tool> toLegacyTools(List<io.modelcontextprotocol.modern.McpSchema.Tool> tools) Converts the tools of the modern schema to those of the legacy schema.- Parameters:
tools- the modern tools- Returns:
- the legacy tools
-
toModernPrompts
public static List<io.modelcontextprotocol.modern.McpSchema.Prompt> toModernPrompts(List<io.modelcontextprotocol.spec.McpSchema.Prompt> prompts) Converts the prompts of the legacy schema to those of the modern schema.- Parameters:
prompts- the legacy prompts- Returns:
- the modern prompts
-
toLegacyPrompts
public static List<io.modelcontextprotocol.spec.McpSchema.Prompt> toLegacyPrompts(List<io.modelcontextprotocol.modern.McpSchema.Prompt> prompts) Converts the prompts of the modern schema to those of the legacy schema.- Parameters:
prompts- the modern prompts- Returns:
- the legacy prompts
-
toModernResources
public static List<io.modelcontextprotocol.modern.McpSchema.Resource> toModernResources(List<io.modelcontextprotocol.spec.McpSchema.Resource> resources) Converts the resources of the legacy schema to those of the modern schema.- Parameters:
resources- the legacy resources- Returns:
- the modern resources
-
toLegacyResources
public static List<io.modelcontextprotocol.spec.McpSchema.Resource> toLegacyResources(List<io.modelcontextprotocol.modern.McpSchema.Resource> resources) Converts the resources of the modern schema to those of the legacy schema.- Parameters:
resources- the modern resources- Returns:
- the legacy resources
-