Class ModernClientHandlerSupport

java.lang.Object
org.springframework.ai.mcp.annotation.common.ModernClientHandlerSupport

public final class ModernClientHandlerSupport extends Object
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 elicitationId and 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 _meta and a modern one has not, so the _meta is 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 Type
    Method
    Description
    static @Nullable Class<?>
    The type of the elicitation request that a reactive @McpElicitation method takes.
    static boolean
    Whether an @McpElicitation method stands for the form elicitation requests of the clients it names, of whichever protocol: its parameter takes a form request of either schema.
    static boolean
    Whether an @McpElicitation method stands for the URL elicitation requests of the clients it names: its parameter takes a URL request of either schema.
    static @Nullable Class<?>
    The type of the elicitation request that a synchronous @McpElicitation method takes.
    static boolean
    Whether a synchronous @McpElicitation method can answer elicitation requests of a legacy connection.
    static boolean
    Whether a synchronous @McpElicitation method can answer the form elicitation requests of a modern connection.
    static boolean
    Whether a reactive @McpElicitation method can answer the form elicitation requests of a modern connection: its parameter takes a form request, of either schema.
    static boolean
    Whether a synchronous @McpElicitation method can answer the URL elicitation requests of a modern connection.
    static boolean
    Whether a reactive @McpElicitation method can answer the URL elicitation requests of a modern connection.
    static boolean
    Whether the type is an elicitation request of the modern schema.
    static boolean
    Whether the type is an elicitation result of the modern schema.
    static boolean
    Whether the type is the ToolContext that a handler method may take.
    static boolean
    Whether a reactive @McpProgress method can be called: it returns a Mono<Void>.
    static boolean
    Whether the method takes one elicitation request of either schema and nothing else but, optionally, a ToolContext, whatever it returns.
    static boolean
    Whether the method takes a ToolContext.
    static io.modelcontextprotocol.spec.McpSchema.ElicitRequest
    toLegacyElicitRequest(io.modelcontextprotocol.modern.McpSchema.ElicitRequest request)
    Converts a modern form elicitation request to the legacy type.
    static io.modelcontextprotocol.spec.McpSchema.ElicitResult
    toLegacyElicitResult(io.modelcontextprotocol.modern.McpSchema.ElicitResult result)
    Converts a modern elicitation result to the legacy type.
    static io.modelcontextprotocol.spec.McpSchema.ProgressNotification
    toLegacyProgress(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.ElicitRequest
    toModernElicitRequest(io.modelcontextprotocol.spec.McpSchema.ElicitRequest request)
    Converts a legacy elicitation request to the modern type.
    static io.modelcontextprotocol.modern.McpSchema.ElicitResult
    toModernElicitResult(io.modelcontextprotocol.spec.McpSchema.ElicitResult result)
    Converts a legacy elicitation result to the modern type.
    static io.modelcontextprotocol.modern.McpSchema.ProgressParams
    toModernProgress(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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isModernElicitRequestType

      public static boolean isModernElicitRequestType(Class<?> type)
      Whether the type is an elicitation request of the modern schema.
      Parameters:
      type - the type to check
      Returns:
      true for the modern ElicitRequest and its two modes
    • isModernElicitResultType

      public static boolean isModernElicitResultType(Class<?> type)
      Whether the type is an elicitation result of the modern schema.
      Parameters:
      type - the type to check
      Returns:
      true for the modern ElicitResult
    • handlesModernFormElicitation

      public static boolean handlesModernFormElicitation(Method method)
      Whether a synchronous @McpElicitation method 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:
      true if the method handles modern form requests
    • handlesModernFormElicitationAsync

      public static boolean handlesModernFormElicitationAsync(Method method)
      Whether a reactive @McpElicitation method 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:
      true if the method handles modern form requests
    • handlesModernUrlElicitationAsync

      public static boolean handlesModernUrlElicitationAsync(Method method)
      Whether a reactive @McpElicitation method 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 an elicitationId.
      Parameters:
      method - the annotated method
      Returns:
      true if the method handles modern URL requests
    • handlesModernUrlElicitation

      public static boolean handlesModernUrlElicitation(Method method)
      Whether a synchronous @McpElicitation method 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 an elicitationId.
      Parameters:
      method - the annotated method
      Returns:
      true if the method handles modern URL requests
    • handlesLegacyElicitation

      public static boolean handlesLegacyElicitation(Method method)
      Whether a synchronous @McpElicitation method 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:
      true if the method handles legacy requests
    • claimsFormElicitation

      public static boolean claimsFormElicitation(Method method)
      Whether an @McpElicitation method 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:
      true if no other method may answer form requests for the same client
    • claimsUrlElicitation

      public static boolean claimsUrlElicitation(Method method)
      Whether an @McpElicitation method 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:
      true if no other method may answer URL requests for the same client
    • elicitRequestParameterType

      public static @Nullable Class<?> elicitRequestParameterType(Method method)
      The type of the elicitation request that a synchronous @McpElicitation method takes. Such a method takes one elicitation request of either schema and, optionally, a ToolContext, and it returns an elicitation result of either schema or a StructuredElicitResult.
      Parameters:
      method - the annotated method
      Returns:
      the type of its request parameter, or null if the method is not a synchronous elicitation handler
    • asyncElicitRequestParameterType

      public static @Nullable Class<?> asyncElicitRequestParameterType(Method method)
      The type of the elicitation request that a reactive @McpElicitation method takes. Such a method takes one elicitation request of either schema and, optionally, a ToolContext, and it returns a Mono of an elicitation result of either schema or of a StructuredElicitResult.
      Parameters:
      method - the annotated method
      Returns:
      the type of its request parameter, or null if the method is not a reactive elicitation handler
    • takesElicitRequest

      public static boolean takesElicitRequest(Method method)
      Whether the method takes one elicitation request of either schema and nothing else but, optionally, a ToolContext, whatever it returns.
      Parameters:
      method - the annotated method
      Returns:
      true if the parameters are those of an elicitation handler
    • returnsMonoOfVoid

      public static boolean returnsMonoOfVoid(Method method)
      Whether a reactive @McpProgress method can be called: it returns a Mono<Void>.
      Parameters:
      method - the annotated method
      Returns:
      true if the method returns Mono<Void>
    • isToolContextType

      public static boolean isToolContextType(Class<?> type)
      Whether the type is the ToolContext that a handler method may take.
      Parameters:
      type - the type to check
      Returns:
      true for ToolContext
    • takesToolContext

      public static boolean takesToolContext(Method method)
      Whether the method takes a ToolContext.
      Parameters:
      method - the method to check
      Returns:
      true if one of its parameters is a ToolContext
    • toModernElicitRequest

      public static io.modelcontextprotocol.modern.McpSchema.ElicitRequest toModernElicitRequest(io.modelcontextprotocol.spec.McpSchema.ElicitRequest request)
      Converts a legacy elicitation request to the modern type. The elicitationId of 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 no elicitationId
    • 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 _meta of 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