Skip to content

Commit 9b0ac0c

Browse files
committed
Merge branch 'main' into enhance-MCP-server-auto-configuration
# Conflicts: # auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/main/java/org/springframework/ai/mcp/server/autoconfigure/McpWebFluxServerAutoConfiguration.java # auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/main/java/org/springframework/ai/mcp/server/autoconfigure/McpWebMvcServerAutoConfiguration.java # auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/test/java/org/springframework/ai/mcp/server/autoconfigure/McpWebFluxServerAutoConfigurationIT.java # auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/test/java/org/springframework/ai/mcp/server/autoconfigure/McpWebMvcServerAutoConfigurationTest.java
2 parents 4aa82f0 + e8d4957 commit 9b0ac0c

File tree

679 files changed

+16382
-4707
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

679 files changed

+16382
-4707
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ One way to run integration tests on part of the code is to first do a quick comp
101101
```shell
102102
./mvnw clean install -DskipTests -Dmaven.javadoc.skip=true
103103
```
104-
Then run the integration test for a specifi module using the `-pl` option
104+
Then run the integration test for a specific module using the `-pl` option
105105
```shell
106-
./mvnw verify -Pintegration-tests -pl spring-ai-spring-boot-autoconfigure
106+
./mvnw verify -Pintegration-tests -pl spring-ai-spring-boot-testcontainers
107107
```
108108

109109
### Documentation
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>org.springframework.ai</groupId>
8+
<artifactId>spring-ai</artifactId>
9+
<version>1.0.0-SNAPSHOT</version>
10+
<relativePath>../../../pom.xml</relativePath>
11+
</parent>
12+
<artifactId>spring-ai-autoconfigure-retry</artifactId>
13+
<packaging>jar</packaging>
14+
<name>Spring AI Retry Auto Configuration</name>
15+
<description>Spring AI Retry Auto Configuration</description>
16+
<url>https://github.com/spring-projects/spring-ai</url>
17+
18+
<scm>
19+
<url>https://github.com/spring-projects/spring-ai</url>
20+
<connection>git://github.com/spring-projects/spring-ai.git</connection>
21+
<developerConnection>[email protected]:spring-projects/spring-ai.git</developerConnection>
22+
</scm>
23+
24+
25+
<dependencies>
26+
27+
<dependency>
28+
<groupId>org.springframework.ai</groupId>
29+
<artifactId>spring-ai-retry</artifactId>
30+
<version>${parent.version}</version>
31+
</dependency>
32+
33+
<!-- Boot dependencies -->
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter</artifactId>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-configuration-processor</artifactId>
42+
<optional>true</optional>
43+
</dependency>
44+
45+
<!-- Test dependencies -->
46+
<dependency>
47+
<groupId>org.springframework.ai</groupId>
48+
<artifactId>spring-ai-test</artifactId>
49+
<version>${project.parent.version}</version>
50+
<scope>test</scope>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>org.springframework.boot</groupId>
55+
<artifactId>spring-boot-starter-test</artifactId>
56+
<scope>test</scope>
57+
</dependency>
58+
59+
<dependency>
60+
<groupId>org.mockito</groupId>
61+
<artifactId>mockito-core</artifactId>
62+
<scope>test</scope>
63+
</dependency>
64+
</dependencies>
65+
66+
</project>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.ai.autoconfigure.retry;
17+
package org.springframework.ai.retry.autoconfigure;
1818

1919
import java.io.IOException;
2020
import java.nio.charset.StandardCharsets;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.ai.autoconfigure.retry;
17+
package org.springframework.ai.retry.autoconfigure;
1818

1919
import java.time.Duration;
2020
import java.util.ArrayList;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Copyright 2025-2025 the original author or authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
org.springframework.ai.retry.autoconfigure.SpringAiRetryAutoConfiguration
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.ai.autoconfigure.retry;
17+
package org.springframework.ai.retry.autoconfigure;
1818

1919
import org.junit.jupiter.api.Test;
2020

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.ai.autoconfigure.retry;
17+
package org.springframework.ai.retry.autoconfigure;
1818

1919
import org.junit.jupiter.api.Test;
2020

auto-configurations/spring-ai-mcp-client/pom.xml renamed to auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<groupId>org.springframework.ai</groupId>
88
<artifactId>spring-ai</artifactId>
99
<version>1.0.0-SNAPSHOT</version>
10-
<relativePath>../../pom.xml</relativePath>
10+
<relativePath>../../../pom.xml</relativePath>
1111
</parent>
12-
<artifactId>spring-ai-mcp-client-spring-boot-autoconfigure</artifactId>
12+
<artifactId>spring-ai-autoconfigure-mcp-client</artifactId>
1313
<packaging>jar</packaging>
1414
<name>Spring AI MCP Client Auto Configuration</name>
1515
<description>Spring AI MCP Client Auto Configuration</description>
Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.ai.autoconfigure.mcp.client;
17+
package org.springframework.ai.mcp.client.autoconfigure;
1818

1919
import java.util.ArrayList;
2020
import java.util.List;
@@ -24,15 +24,11 @@
2424
import io.modelcontextprotocol.client.McpSyncClient;
2525
import io.modelcontextprotocol.spec.McpSchema;
2626

27-
import org.springframework.ai.autoconfigure.mcp.client.configurer.McpAsyncClientConfigurer;
28-
import org.springframework.ai.autoconfigure.mcp.client.configurer.McpSyncClientConfigurer;
29-
import org.springframework.ai.autoconfigure.mcp.client.properties.McpClientCommonProperties;
30-
import org.springframework.ai.mcp.AsyncMcpToolCallbackProvider;
31-
import org.springframework.ai.mcp.SyncMcpToolCallbackProvider;
27+
import org.springframework.ai.mcp.client.autoconfigure.configurer.McpAsyncClientConfigurer;
28+
import org.springframework.ai.mcp.client.autoconfigure.configurer.McpSyncClientConfigurer;
29+
import org.springframework.ai.mcp.client.autoconfigure.properties.McpClientCommonProperties;
3230
import org.springframework.ai.mcp.customizer.McpAsyncClientCustomizer;
3331
import org.springframework.ai.mcp.customizer.McpSyncClientCustomizer;
34-
import org.springframework.ai.tool.ToolCallback;
35-
import org.springframework.ai.tool.ToolCallbackProvider;
3632
import org.springframework.beans.factory.ObjectProvider;
3733
import org.springframework.boot.autoconfigure.AutoConfiguration;
3834
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -179,36 +175,6 @@ public List<McpSyncClient> mcpSyncClients(McpSyncClientConfigurer mcpSyncClientC
179175
return mcpSyncClients;
180176
}
181177

182-
/**
183-
* Creates tool callbacks for all configured MCP clients.
184-
*
185-
* <p>
186-
* These callbacks enable integration with Spring AI's tool execution framework,
187-
* allowing MCP tools to be used as part of AI interactions.
188-
* @param mcpClientsProvider provider of MCP sync clients
189-
* @return list of tool callbacks for MCP integration
190-
*/
191-
@Bean
192-
@ConditionalOnProperty(prefix = McpClientCommonProperties.CONFIG_PREFIX, name = "type", havingValue = "SYNC",
193-
matchIfMissing = true)
194-
public ToolCallbackProvider toolCallbacks(ObjectProvider<List<McpSyncClient>> mcpClientsProvider) {
195-
List<McpSyncClient> mcpClients = mcpClientsProvider.stream().flatMap(List::stream).toList();
196-
return new SyncMcpToolCallbackProvider(mcpClients);
197-
}
198-
199-
/**
200-
* @deprecated replaced by {@link #toolCallbacks(ObjectProvider)} that returns a
201-
* {@link ToolCallbackProvider} instead of a list of {@link ToolCallback}
202-
*/
203-
@Deprecated
204-
@Bean
205-
@ConditionalOnProperty(prefix = McpClientCommonProperties.CONFIG_PREFIX, name = "type", havingValue = "SYNC",
206-
matchIfMissing = true)
207-
public List<ToolCallback> toolCallbacksDeprecated(ObjectProvider<List<McpSyncClient>> mcpClientsProvider) {
208-
List<McpSyncClient> mcpClients = mcpClientsProvider.stream().flatMap(List::stream).toList();
209-
return List.of(new SyncMcpToolCallbackProvider(mcpClients).getToolCallbacks());
210-
}
211-
212178
/**
213179
* Record class that implements {@link AutoCloseable} to ensure proper cleanup of MCP
214180
* clients.
@@ -292,25 +258,6 @@ public List<McpAsyncClient> mcpAsyncClients(McpAsyncClientConfigurer mcpSyncClie
292258
return mcpSyncClients;
293259
}
294260

295-
/**
296-
* @deprecated replaced by {@link #asyncToolCallbacks(ObjectProvider)} that returns a
297-
* {@link ToolCallbackProvider} instead of a list of {@link ToolCallback}
298-
*/
299-
@Deprecated
300-
@Bean
301-
@ConditionalOnProperty(prefix = McpClientCommonProperties.CONFIG_PREFIX, name = "type", havingValue = "ASYNC")
302-
public List<ToolCallback> asyncToolCallbacksDeprecated(ObjectProvider<List<McpAsyncClient>> mcpClientsProvider) {
303-
List<McpAsyncClient> mcpClients = mcpClientsProvider.stream().flatMap(List::stream).toList();
304-
return List.of(new AsyncMcpToolCallbackProvider(mcpClients).getToolCallbacks());
305-
}
306-
307-
@Bean
308-
@ConditionalOnProperty(prefix = McpClientCommonProperties.CONFIG_PREFIX, name = "type", havingValue = "ASYNC")
309-
public ToolCallbackProvider asyncToolCallbacks(ObjectProvider<List<McpAsyncClient>> mcpClientsProvider) {
310-
List<McpAsyncClient> mcpClients = mcpClientsProvider.stream().flatMap(List::stream).toList();
311-
return new AsyncMcpToolCallbackProvider(mcpClients);
312-
}
313-
314261
public record CloseableMcpAsyncClients(List<McpAsyncClient> clients) implements AutoCloseable {
315262
@Override
316263
public void close() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright 2025-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ai.mcp.client.autoconfigure;
18+
19+
import java.util.List;
20+
21+
import io.modelcontextprotocol.client.McpAsyncClient;
22+
import io.modelcontextprotocol.client.McpSyncClient;
23+
24+
import org.springframework.ai.mcp.AsyncMcpToolCallbackProvider;
25+
import org.springframework.ai.mcp.SyncMcpToolCallbackProvider;
26+
import org.springframework.ai.mcp.client.autoconfigure.properties.McpClientCommonProperties;
27+
import org.springframework.ai.tool.ToolCallbackProvider;
28+
import org.springframework.beans.factory.ObjectProvider;
29+
import org.springframework.boot.autoconfigure.AutoConfiguration;
30+
import org.springframework.boot.autoconfigure.condition.AllNestedConditions;
31+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
32+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
33+
import org.springframework.context.annotation.Bean;
34+
import org.springframework.context.annotation.Conditional;
35+
36+
/**
37+
*/
38+
@AutoConfiguration(after = { McpClientAutoConfiguration.class })
39+
@EnableConfigurationProperties(McpClientCommonProperties.class)
40+
@Conditional(McpToolCallbackAutoConfiguration.McpToolCallbackAutoconfigurationCondition.class)
41+
public class McpToolCallbackAutoConfiguration {
42+
43+
public static class McpToolCallbackAutoconfigurationCondition extends AllNestedConditions {
44+
45+
public McpToolCallbackAutoconfigurationCondition() {
46+
super(ConfigurationPhase.PARSE_CONFIGURATION);
47+
}
48+
49+
@ConditionalOnProperty(prefix = McpClientCommonProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true",
50+
matchIfMissing = true)
51+
static class McpAutoConfigEnabled {
52+
53+
}
54+
55+
@ConditionalOnProperty(prefix = McpClientCommonProperties.CONFIG_PREFIX + ".toolcallback", name = "enabled",
56+
havingValue = "true", matchIfMissing = false)
57+
static class ToolCallbackProviderEnabled {
58+
59+
}
60+
61+
}
62+
63+
/**
64+
* Creates tool callbacks for all configured MCP clients.
65+
*
66+
* <p>
67+
* These callbacks enable integration with Spring AI's tool execution framework,
68+
* allowing MCP tools to be used as part of AI interactions.
69+
* @param syncMcpClients provider of MCP sync clients
70+
* @return list of tool callbacks for MCP integration
71+
*/
72+
@Bean
73+
@ConditionalOnProperty(prefix = McpClientCommonProperties.CONFIG_PREFIX, name = "type", havingValue = "SYNC",
74+
matchIfMissing = true)
75+
public ToolCallbackProvider mcpToolCallbacks(ObjectProvider<List<McpSyncClient>> syncMcpClients) {
76+
List<McpSyncClient> mcpClients = syncMcpClients.stream().flatMap(List::stream).toList();
77+
return new SyncMcpToolCallbackProvider(mcpClients);
78+
}
79+
80+
@Bean
81+
@ConditionalOnProperty(prefix = McpClientCommonProperties.CONFIG_PREFIX, name = "type", havingValue = "ASYNC")
82+
public ToolCallbackProvider mcpAsyncToolCallbacks(ObjectProvider<List<McpAsyncClient>> mcpClientsProvider) {
83+
List<McpAsyncClient> mcpClients = mcpClientsProvider.stream().flatMap(List::stream).toList();
84+
return new AsyncMcpToolCallbackProvider(mcpClients);
85+
}
86+
87+
}

0 commit comments

Comments
 (0)