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:
-
McpSamplingMcpElicitationMcpLoggingMcpProgressMcpToolListChangedMcpPromptListChangedMcpResourceListChanged
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.springframework.beans.factory.config.ConfigurableListableBeanFactory -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected Map<Class<? extends Annotation>,Set<Object>> io.modelcontextprotocol.spec.McpSchema.ClientCapabilitiesgetCapabilities(String clientName) Obtain the MCP capabilities declared for a given MCP client.io.modelcontextprotocol.spec.McpSchema.ElicitResulthandleElicitation(String name, io.modelcontextprotocol.spec.McpSchema.ElicitRequest elicitationRequest) Invoke the elicitation handler for a given MCP client.voidhandleLogging(String name, io.modelcontextprotocol.spec.McpSchema.LoggingMessageNotification loggingMessageNotification) Invoke all elicitation handlers for a given MCP client, sequentially.voidhandleProgress(String name, io.modelcontextprotocol.spec.McpSchema.ProgressNotification progressNotification) Invoke all progress handlers for a given MCP client, sequentially.voidhandlePromptListChanged(String name, List<io.modelcontextprotocol.spec.McpSchema.Prompt> updatedPrompts) Invoke all prompt list changed handlers for a given MCP client, sequentially.voidhandleResourceListChanged(String name, List<io.modelcontextprotocol.spec.McpSchema.Resource> updatedResources) Invoke all resource list changed handlers for a given MCP client, sequentially.io.modelcontextprotocol.spec.McpSchema.CreateMessageResulthandleSampling(String name, io.modelcontextprotocol.spec.McpSchema.CreateMessageRequest samplingRequest) Invoke the sampling handler for a given MCP client.voidhandleToolListChanged(String name, List<io.modelcontextprotocol.spec.McpSchema.Tool> updatedTools) Invoke all tool list changed handlers for a given MCP client, sequentially.voidpostProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) protected List<Annotation>
-
Field Details
-
capabilitiesPerClient
-
beanFactory
protected org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory -
allAnnotatedBeans
-
-
Constructor Details
-
ClientMcpSyncHandlersRegistry
public ClientMcpSyncHandlersRegistry()
-
-
Method Details
-
getCapabilities
Obtain the MCP capabilities declared for a given MCP client. Capabilities are registered with theMcpSamplingandMcpElicitationannotations. -
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:
afterSingletonsInstantiatedin interfaceorg.springframework.beans.factory.SmartInitializingSingleton
-
postProcessBeanFactory
public void postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) throws org.springframework.beans.BeansException - Specified by:
postProcessBeanFactoryin interfaceorg.springframework.beans.factory.config.BeanFactoryPostProcessor- Throws:
org.springframework.beans.BeansException
-
scan
-
getBeansByAnnotationType
-