Skip to content

Commit 81137ca

Browse files
ThomasVitaletzolov
authored andcommitted
MCP ToolCallbackProvider autoconfig should use concrete class
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 <ThomasVitale@users.noreply.github.com>
1 parent 14972f9 commit 81137ca

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/McpToolCallbackAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ public class McpToolCallbackAutoConfiguration {
5252
@Bean
5353
@ConditionalOnProperty(prefix = McpClientCommonProperties.CONFIG_PREFIX, name = "type", havingValue = "SYNC",
5454
matchIfMissing = true)
55-
public ToolCallbackProvider mcpToolCallbacks(ObjectProvider<List<McpSyncClient>> syncMcpClients) {
55+
public SyncMcpToolCallbackProvider mcpToolCallbacks(ObjectProvider<List<McpSyncClient>> syncMcpClients) {
5656
List<McpSyncClient> mcpClients = syncMcpClients.stream().flatMap(List::stream).toList();
5757
return new SyncMcpToolCallbackProvider(mcpClients);
5858
}
5959

6060
@Bean
6161
@ConditionalOnProperty(prefix = McpClientCommonProperties.CONFIG_PREFIX, name = "type", havingValue = "ASYNC")
62-
public ToolCallbackProvider mcpAsyncToolCallbacks(ObjectProvider<List<McpAsyncClient>> mcpClientsProvider) {
62+
public AsyncMcpToolCallbackProvider mcpAsyncToolCallbacks(ObjectProvider<List<McpAsyncClient>> mcpClientsProvider) {
6363
List<McpAsyncClient> mcpClients = mcpClientsProvider.stream().flatMap(List::stream).toList();
6464
return new AsyncMcpToolCallbackProvider(mcpClients);
6565
}

0 commit comments

Comments
 (0)