From 81c5833c0de9f1066631bbb0242af2d64626b43a Mon Sep 17 00:00:00 2001 From: Thomas Vitale Date: Sun, 18 May 2025 19:34:28 +0200 Subject: [PATCH] MCP ToolCallbackProvider autoconfig should use concrete class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, the MCP Tool autoconfiguration defines the SyncMcpToolCallbackProvider and AsyncMcpToolCallbackProvider beans returning the ToolCallbackProvider interface. That generates autowiring warnings in IDEs when trying to inject the specific class. The Spring Boot project recommends being specific. 'When declaring a @Bean method, provide as much type information as possible in the method’s return type. For example, if your bean’s concrete class implements an interface the bean method’s return type should be the concrete class and not the interface. Providing as much type information as possible in @Bean methods is particularly important when using bean conditions as their evaluation can only rely upon to type information that is available in the method signature.' See https://docs.spring.io/spring-boot/reference/features/developing-auto-configuration.html#features.developing-auto-configuration.condition-annotations.bean-conditions This PR ensures concrete classes are used. Signed-off-by: Thomas Vitale --- .../autoconfigure/McpToolCallbackAutoConfiguration.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/McpToolCallbackAutoConfiguration.java b/auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/McpToolCallbackAutoConfiguration.java index e61a696af6b..4206fcbe8c4 100644 --- a/auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/McpToolCallbackAutoConfiguration.java +++ b/auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/McpToolCallbackAutoConfiguration.java @@ -52,14 +52,14 @@ public class McpToolCallbackAutoConfiguration { @Bean @ConditionalOnProperty(prefix = McpClientCommonProperties.CONFIG_PREFIX, name = "type", havingValue = "SYNC", matchIfMissing = true) - public ToolCallbackProvider mcpToolCallbacks(ObjectProvider> syncMcpClients) { + public SyncMcpToolCallbackProvider mcpToolCallbacks(ObjectProvider> syncMcpClients) { List mcpClients = syncMcpClients.stream().flatMap(List::stream).toList(); return new SyncMcpToolCallbackProvider(mcpClients); } @Bean @ConditionalOnProperty(prefix = McpClientCommonProperties.CONFIG_PREFIX, name = "type", havingValue = "ASYNC") - public ToolCallbackProvider mcpAsyncToolCallbacks(ObjectProvider> mcpClientsProvider) { + public AsyncMcpToolCallbackProvider mcpAsyncToolCallbacks(ObjectProvider> mcpClientsProvider) { List mcpClients = mcpClientsProvider.stream().flatMap(List::stream).toList(); return new AsyncMcpToolCallbackProvider(mcpClients); }