Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.ai.autoconfigure.mcp.client.properties.McpClientCommonProperties;
import org.springframework.ai.autoconfigure.mcp.client.properties.McpSseClientProperties;
import org.springframework.ai.autoconfigure.mcp.client.properties.McpSseClientProperties.SseParameters;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand Down Expand Up @@ -80,12 +81,15 @@ public class SseHttpClientTransportAutoConfiguration {
* <li>ObjectMapper for JSON processing
* </ul>
* @param sseProperties the SSE client properties containing server configurations
* @param objectMapper the ObjectMapper for JSON serialization/deserialization
* @param objectMapperProvider the provider for ObjectMapper or a new instance if not
* available
* @return list of named MCP transports
*/
@Bean
public List<NamedClientMcpTransport> mcpHttpClientTransports(McpSseClientProperties sseProperties,
ObjectMapper objectMapper) {
ObjectProvider<ObjectMapper> objectMapperProvider) {

ObjectMapper objectMapper = objectMapperProvider.getIfAvailable(ObjectMapper::new);

List<NamedClientMcpTransport> sseTransports = new ArrayList<>();

Expand All @@ -99,18 +103,4 @@ public List<NamedClientMcpTransport> mcpHttpClientTransports(McpSseClientPropert
return sseTransports;
}

/**
* Creates the default ObjectMapper if none is provided.
*
* <p>
* This ObjectMapper is used for JSON serialization and deserialization in the SSE
* transport implementation.
* @return the configured ObjectMapper instance
*/
@Bean
@ConditionalOnMissingBean
public ObjectMapper objectMapper() {
return new ObjectMapper();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import org.springframework.ai.autoconfigure.mcp.client.properties.McpClientCommonProperties;
import org.springframework.ai.autoconfigure.mcp.client.properties.McpSseClientProperties;
import org.springframework.ai.autoconfigure.mcp.client.properties.McpSseClientProperties.SseParameters;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -73,17 +73,21 @@ public class SseWebFluxTransportAutoConfiguration {
* <li>Server connection parameters from properties
* </ul>
* @param sseProperties the SSE client properties containing server configurations
* @param webClientBuilderTemplate the template WebClient.Builder to clone for each
* connection
* @param objectMapper the ObjectMapper for JSON serialization/deserialization
* @param webClientBuilderProvider the provider for WebClient.Builder
* @param objectMapperProvider the provider for ObjectMapper or a new instance if not
* available
* @return list of named MCP transports
*/
@Bean
public List<NamedClientMcpTransport> webFluxClientTransports(McpSseClientProperties sseProperties,
WebClient.Builder webClientBuilderTemplate, ObjectMapper objectMapper) {
ObjectProvider<WebClient.Builder> webClientBuilderProvider,
ObjectProvider<ObjectMapper> objectMapperProvider) {

List<NamedClientMcpTransport> sseTransports = new ArrayList<>();

var webClientBuilderTemplate = webClientBuilderProvider.getIfAvailable(WebClient::builder);
var objectMapper = objectMapperProvider.getIfAvailable(ObjectMapper::new);

for (Map.Entry<String, SseParameters> serverParameters : sseProperties.getConnections().entrySet()) {
var webClientBuilder = webClientBuilderTemplate.clone().baseUrl(serverParameters.getValue().url());
var transport = new WebFluxSseClientTransport(webClientBuilder, objectMapper);
Expand All @@ -93,32 +97,4 @@ public List<NamedClientMcpTransport> webFluxClientTransports(McpSseClientPropert
return sseTransports;
}

/**
* Creates the default WebClient.Builder if none is provided.
*
* <p>
* This builder serves as a template for creating server-specific WebClient instances
* used in SSE transport implementation.
* @return the configured WebClient.Builder instance
*/
@Bean
@ConditionalOnMissingBean
public WebClient.Builder webClientBuilder() {
return WebClient.builder();
}

/**
* Creates the default ObjectMapper if none is provided.
*
* <p>
* This ObjectMapper is used for JSON serialization and deserialization in the SSE
* transport implementation.
* @return the configured ObjectMapper instance
*/
@Bean
@ConditionalOnMissingBean
public ObjectMapper objectMapper() {
return new ObjectMapper();
}

}