Class ClientMcpSyncHandlersRegistry

java.lang.Object
org.springframework.ai.mcp.annotation.spring.ClientMcpSyncHandlersRegistry
All Implemented Interfaces:
org.springframework.beans.factory.config.BeanFactoryPostProcessor, org.springframework.beans.factory.SmartInitializingSingleton

public class ClientMcpSyncHandlersRegistry extends Object implements org.springframework.beans.factory.SmartInitializingSingleton
Registry of methods annotated with MCP Client annotations (sampling, logging, etc.). All beans in the application context are scanned to find these methods automatically. They are then exposed by the registry by client name.

The scanning happens in two phases:

First, once bean definitions are available, all bean types are scanned for the presence of MCP annotations. In particular, this is used to prepare the result getCapabilities(String), which is then used by MCP client auto-configurations to configure the client capabilities without needing to instantiate the beans.

Second, after all singleton beans have been instantiated, all annotated beans are scanned again, MCP handlers are created to match the annotations, and stored by client.

Since:
1.1.0
Author:
Daniel Garnier-Moiroux
See Also:
  • McpSampling
  • McpElicitation
  • McpLogging
  • McpProgress
  • McpToolListChanged
  • McpPromptListChanged
  • McpResourceListChanged
  • Field Details

    • capabilitiesPerClient

      protected Map<String,io.modelcontextprotocol.spec.McpSchema.ClientCapabilities> capabilitiesPerClient
    • beanFactory

      protected org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory
    • allAnnotatedBeans

      protected final Set<String> allAnnotatedBeans
  • Constructor Details

    • ClientMcpSyncHandlersRegistry

      public ClientMcpSyncHandlersRegistry()
  • Method Details

    • getCapabilities

      public io.modelcontextprotocol.spec.McpSchema.ClientCapabilities getCapabilities(String clientName)
      Obtain the MCP capabilities declared for a given MCP client. Capabilities are registered with the McpSampling and McpElicitation annotations.
    • handleSampling

      public io.modelcontextprotocol.spec.McpSchema.CreateMessageResult handleSampling(String name, io.modelcontextprotocol.spec.McpSchema.CreateMessageRequest samplingRequest)
      Invoke the sampling handler for a given MCP client.
      See Also:
      • McpSampling
    • handleElicitation

      public io.modelcontextprotocol.spec.McpSchema.ElicitResult handleElicitation(String name, io.modelcontextprotocol.spec.McpSchema.ElicitRequest elicitationRequest)
      Invoke the elicitation handler for a given MCP client.
      See Also:
      • McpElicitation
    • handleLogging

      public void handleLogging(String name, io.modelcontextprotocol.spec.McpSchema.LoggingMessageNotification loggingMessageNotification)
      Invoke all elicitation handlers for a given MCP client, sequentially.
      See Also:
      • McpLogging
    • handleProgress

      public void handleProgress(String name, io.modelcontextprotocol.spec.McpSchema.ProgressNotification progressNotification)
      Invoke all progress handlers for a given MCP client, sequentially.
      See Also:
      • McpProgress
    • handleToolListChanged

      public void handleToolListChanged(String name, List<io.modelcontextprotocol.spec.McpSchema.Tool> updatedTools)
      Invoke all tool list changed handlers for a given MCP client, sequentially.
      See Also:
      • McpToolListChanged
    • handlePromptListChanged

      public void handlePromptListChanged(String name, List<io.modelcontextprotocol.spec.McpSchema.Prompt> updatedPrompts)
      Invoke all prompt list changed handlers for a given MCP client, sequentially.
      See Also:
      • McpPromptListChanged
    • handleResourceListChanged

      public void handleResourceListChanged(String name, List<io.modelcontextprotocol.spec.McpSchema.Resource> updatedResources)
      Invoke all resource list changed handlers for a given MCP client, sequentially.
      See Also:
      • McpResourceListChanged
    • afterSingletonsInstantiated

      public void afterSingletonsInstantiated()
      Specified by:
      afterSingletonsInstantiated in interface org.springframework.beans.factory.SmartInitializingSingleton
    • postProcessBeanFactory

      public void postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) throws org.springframework.beans.BeansException
      Specified by:
      postProcessBeanFactory in interface org.springframework.beans.factory.config.BeanFactoryPostProcessor
      Throws:
      org.springframework.beans.BeansException
    • scan

      protected List<Annotation> scan(Class<?> beanClass)
    • getBeansByAnnotationType

      protected Map<Class<? extends Annotation>,Set<Object>> getBeansByAnnotationType()