Skip to content

Commit 17e8f6a

Browse files
committed
feat(mcp): Add integration tests and improve documentation
- Add test dependencies and comprehensive integration tests for McpClientAutoConfiguration - Reorganize code by moving properties and configurer classes into dedicated packages - Add root change notification property to common properties - Add extensive documentation for MCP client/server starters and common utilities - Improve code documentation with detailed Javadoc comments - Update navigation to include new MCP documentation sections Signed-off-by: Christian Tzolov <[email protected]>
1 parent bec5885 commit 17e8f6a

30 files changed

+2785
-46
lines changed

auto-configurations/spring-ai-mcp-client/pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@
5050
<optional>true</optional>
5151
</dependency> -->
5252

53+
<!-- Test dependencies -->
54+
<dependency>
55+
<groupId>org.springframework.ai</groupId>
56+
<artifactId>spring-ai-test</artifactId>
57+
<version>${project.parent.version}</version>
58+
<scope>test</scope>
59+
</dependency>
60+
61+
<dependency>
62+
<groupId>org.springframework.boot</groupId>
63+
<artifactId>spring-boot-starter-test</artifactId>
64+
<scope>test</scope>
65+
</dependency>
66+
67+
<dependency>
68+
<groupId>org.mockito</groupId>
69+
<artifactId>mockito-core</artifactId>
70+
<scope>test</scope>
71+
</dependency>
5372
</dependencies>
5473

5574
</project>

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
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;
2730
import org.springframework.ai.mcp.McpToolUtils;
2831
import org.springframework.ai.mcp.customizer.McpAsyncClientCustomizer;
2932
import org.springframework.ai.mcp.customizer.McpSyncClientCustomizer;
@@ -220,9 +223,7 @@ public ClosebleMcpSyncClients makeSyncClientsClosable(List<McpSyncClient> client
220223
@ConditionalOnProperty(prefix = McpClientCommonProperties.CONFIG_PREFIX, name = "type", havingValue = "SYNC",
221224
matchIfMissing = true)
222225
McpSyncClientConfigurer mcpSyncClientConfigurer(ObjectProvider<McpSyncClientCustomizer> customizerProvider) {
223-
McpSyncClientConfigurer configurer = new McpSyncClientConfigurer();
224-
configurer.setCustomizers(customizerProvider.orderedStream().toList());
225-
return configurer;
226+
return new McpSyncClientConfigurer(customizerProvider.orderedStream().toList());
226227
}
227228

228229
// Async client configuration
@@ -286,9 +287,7 @@ public ClosebleMcpAsyncClients makeAsynClientsClosable(List<McpAsyncClient> clie
286287
@ConditionalOnMissingBean
287288
@ConditionalOnProperty(prefix = McpClientCommonProperties.CONFIG_PREFIX, name = "type", havingValue = "ASYNC")
288289
McpAsyncClientConfigurer mcpAsyncClientConfigurer(ObjectProvider<McpAsyncClientCustomizer> customizerProvider) {
289-
McpAsyncClientConfigurer configurer = new McpAsyncClientConfigurer();
290-
configurer.setCustomizers(customizerProvider.orderedStream().toList());
291-
return configurer;
290+
return new McpAsyncClientConfigurer(customizerProvider.orderedStream().toList());
292291
}
293292

294293
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
import io.modelcontextprotocol.spec.ClientMcpTransport;
1919

2020
/**
21-
* A named MCP client transport.
21+
* A named MCP client transport. Usually created by the transport auto-configurations, but
22+
* you can also create them manually. Expose the list castom NamedClientMcpTransport
23+
* as @Bean.
2224
*
2325
* @param name the name of the transport. Usually the name of the server connection.
2426
* @param transport the MCP client transport.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport;
2727
import io.modelcontextprotocol.spec.McpSchema;
2828

29-
import org.springframework.ai.autoconfigure.mcp.client.McpSseClientProperties.SseParameters;
29+
import org.springframework.ai.autoconfigure.mcp.client.properties.McpClientCommonProperties;
30+
import org.springframework.ai.autoconfigure.mcp.client.properties.McpSseClientProperties;
31+
import org.springframework.ai.autoconfigure.mcp.client.properties.McpSseClientProperties.SseParameters;
3032
import org.springframework.boot.autoconfigure.AutoConfiguration;
3133
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
3234
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import com.fasterxml.jackson.databind.ObjectMapper;
2424
import io.modelcontextprotocol.client.transport.WebFluxSseClientTransport;
2525

26-
import org.springframework.ai.autoconfigure.mcp.client.McpSseClientProperties.SseParameters;
26+
import org.springframework.ai.autoconfigure.mcp.client.properties.McpClientCommonProperties;
27+
import org.springframework.ai.autoconfigure.mcp.client.properties.McpSseClientProperties;
28+
import org.springframework.ai.autoconfigure.mcp.client.properties.McpSseClientProperties.SseParameters;
2729
import org.springframework.boot.autoconfigure.AutoConfiguration;
2830
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2931
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@
2020
import java.util.List;
2121
import java.util.Map;
2222

23-
import com.fasterxml.jackson.databind.ObjectMapper;
24-
import io.modelcontextprotocol.client.McpSyncClient;
2523
import io.modelcontextprotocol.client.transport.ServerParameters;
2624
import io.modelcontextprotocol.client.transport.StdioClientTransport;
2725
import io.modelcontextprotocol.spec.McpSchema;
2826

27+
import org.springframework.ai.autoconfigure.mcp.client.properties.McpClientCommonProperties;
28+
import org.springframework.ai.autoconfigure.mcp.client.properties.McpStdioClientProperties;
2929
import org.springframework.boot.autoconfigure.AutoConfiguration;
3030
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
31-
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
3231
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
3332
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3433
import org.springframework.context.annotation.Bean;
Lines changed: 2 additions & 2 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.autoconfigure.mcp.client.configurer;
1818

1919
import java.util.List;
2020

@@ -26,7 +26,7 @@ public class McpAsyncClientConfigurer {
2626

2727
private List<McpAsyncClientCustomizer> customizers;
2828

29-
void setCustomizers(List<McpAsyncClientCustomizer> customizers) {
29+
public McpAsyncClientConfigurer(List<McpAsyncClientCustomizer> customizers) {
3030
this.customizers = customizers;
3131
}
3232

Lines changed: 2 additions & 6 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.autoconfigure.mcp.client.configurer;
1818

1919
import java.util.List;
2020

@@ -41,11 +41,7 @@ public class McpSyncClientConfigurer {
4141

4242
private List<McpSyncClientCustomizer> customizers;
4343

44-
/**
45-
* Sets the list of customizers to be applied to MCP sync clients.
46-
* @param customizers the list of customizers to apply
47-
*/
48-
void setCustomizers(List<McpSyncClientCustomizer> customizers) {
44+
public McpSyncClientConfigurer(List<McpSyncClientCustomizer> customizers) {
4945
this.customizers = customizers;
5046
}
5147

Lines changed: 17 additions & 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.mcp.client;
17+
package org.springframework.ai.autoconfigure.mcp.client.properties;
1818

1919
import java.time.Duration;
2020

@@ -93,6 +93,14 @@ public enum ClientType {
9393

9494
}
9595

96+
/**
97+
* Flag to enable/disable root change notifications.
98+
* <p>
99+
* When enabled, the client will be notified of changes to the root configuration.
100+
* Defaults to true.
101+
*/
102+
private boolean rootChangeNotification = true;
103+
96104
public boolean isEnabled() {
97105
return this.enabled;
98106
}
@@ -141,4 +149,12 @@ public void setType(ClientType type) {
141149
this.type = type;
142150
}
143151

152+
public boolean isRootChangeNotification() {
153+
return this.rootChangeNotification;
154+
}
155+
156+
public void setRootChangeNotification(boolean rootChangeNotification) {
157+
this.rootChangeNotification = rootChangeNotification;
158+
}
159+
144160
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.ai.autoconfigure.mcp.client;
16+
package org.springframework.ai.autoconfigure.mcp.client.properties;
1717

1818
import java.util.HashMap;
1919
import java.util.Map;

0 commit comments

Comments
 (0)