From 453aa59223de10b1d4c256bf697aed265f2ecc17 Mon Sep 17 00:00:00 2001 From: lambochen Date: Sun, 13 Apr 2025 22:47:12 +0800 Subject: [PATCH 1/3] mcp-client: support sseEndpoint config Signed-off-by: lambochen --- .../SseHttpClientTransportAutoConfiguration.java | 7 +++++-- .../SseWebFluxTransportAutoConfiguration.java | 3 ++- .../autoconfigure/properties/McpSseClientProperties.java | 6 +++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/SseHttpClientTransportAutoConfiguration.java b/auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/SseHttpClientTransportAutoConfiguration.java index 00c8e44d7ed..6ffb53293e1 100644 --- a/auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/SseHttpClientTransportAutoConfiguration.java +++ b/auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/SseHttpClientTransportAutoConfiguration.java @@ -94,8 +94,11 @@ public List mcpHttpClientTransports(McpSseClientPropert for (Map.Entry serverParameters : sseProperties.getConnections().entrySet()) { - var transport = new HttpClientSseClientTransport(HttpClient.newBuilder(), serverParameters.getValue().url(), - objectMapper); + var transport = HttpClientSseClientTransport.builder(serverParameters.getValue().url()) + .sseEndpoint(serverParameters.getValue().sseEndpoint()) + .clientBuilder(HttpClient.newBuilder()) + .objectMapper(objectMapper) + .build(); sseTransports.add(new NamedClientMcpTransport(serverParameters.getKey(), transport)); } diff --git a/auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/SseWebFluxTransportAutoConfiguration.java b/auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/SseWebFluxTransportAutoConfiguration.java index b49ceb552cb..a725b652e0d 100644 --- a/auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/SseWebFluxTransportAutoConfiguration.java +++ b/auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/SseWebFluxTransportAutoConfiguration.java @@ -90,7 +90,8 @@ public List webFluxClientTransports(McpSseClientPropert for (Map.Entry serverParameters : sseProperties.getConnections().entrySet()) { var webClientBuilder = webClientBuilderTemplate.clone().baseUrl(serverParameters.getValue().url()); - var transport = new WebFluxSseClientTransport(webClientBuilder, objectMapper); + var transport = new WebFluxSseClientTransport(webClientBuilder, objectMapper, + serverParameters.getValue().sseEndpoint()); sseTransports.add(new NamedClientMcpTransport(serverParameters.getKey(), transport)); } diff --git a/auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/properties/McpSseClientProperties.java b/auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/properties/McpSseClientProperties.java index 22c655c1bbc..498606206d8 100644 --- a/auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/properties/McpSseClientProperties.java +++ b/auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/properties/McpSseClientProperties.java @@ -50,8 +50,12 @@ public class McpSseClientProperties { * Parameters for configuring an SSE connection to an MCP server. * * @param url the URL endpoint for SSE communication with the MCP server + * @param sseEndpoint the SSE endpoint for SSE communication with the MCP server */ - public record SseParameters(String url) { + public record SseParameters(String url, String sseEndpoint) { + public SseParameters(String url) { + this(url, "/sse"); + } } /** From 7367e22fa482d499b8644e2264a551c21a45b205 Mon Sep 17 00:00:00 2001 From: lambochen Date: Mon, 14 Apr 2025 19:35:30 +0800 Subject: [PATCH 2/3] mcp: server(webmvc/webflux) support baseUrl,sseEndpoint config Signed-off-by: lambochen --- .../autoconfigure/McpWebFluxServerAutoConfiguration.java | 3 ++- .../server/autoconfigure/McpWebMvcServerAutoConfiguration.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/main/java/org/springframework/ai/mcp/server/autoconfigure/McpWebFluxServerAutoConfiguration.java b/auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/main/java/org/springframework/ai/mcp/server/autoconfigure/McpWebFluxServerAutoConfiguration.java index 563fafe9e18..bde016bbaa0 100644 --- a/auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/main/java/org/springframework/ai/mcp/server/autoconfigure/McpWebFluxServerAutoConfiguration.java +++ b/auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/main/java/org/springframework/ai/mcp/server/autoconfigure/McpWebFluxServerAutoConfiguration.java @@ -77,7 +77,8 @@ public class McpWebFluxServerAutoConfiguration { public WebFluxSseServerTransportProvider webFluxTransport(ObjectProvider objectMapperProvider, McpServerProperties serverProperties) { ObjectMapper objectMapper = objectMapperProvider.getIfAvailable(ObjectMapper::new); - return new WebFluxSseServerTransportProvider(objectMapper, serverProperties.getSseMessageEndpoint()); + return new WebFluxSseServerTransportProvider(objectMapper, serverProperties.getBaseUrl(), + serverProperties.getSseMessageEndpoint(), serverProperties.getSseEndpoint()); } // Router function for SSE transport used by Spring WebFlux to start an HTTP server. diff --git a/auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/main/java/org/springframework/ai/mcp/server/autoconfigure/McpWebMvcServerAutoConfiguration.java b/auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/main/java/org/springframework/ai/mcp/server/autoconfigure/McpWebMvcServerAutoConfiguration.java index 259fc3b37a2..42ac7a451ab 100644 --- a/auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/main/java/org/springframework/ai/mcp/server/autoconfigure/McpWebMvcServerAutoConfiguration.java +++ b/auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/main/java/org/springframework/ai/mcp/server/autoconfigure/McpWebMvcServerAutoConfiguration.java @@ -72,7 +72,8 @@ public class McpWebMvcServerAutoConfiguration { public WebMvcSseServerTransportProvider webMvcSseServerTransportProvider( ObjectProvider objectMapperProvider, McpServerProperties serverProperties) { ObjectMapper objectMapper = objectMapperProvider.getIfAvailable(ObjectMapper::new); - return new WebMvcSseServerTransportProvider(objectMapper, serverProperties.getSseMessageEndpoint()); + return new WebMvcSseServerTransportProvider(objectMapper, serverProperties.getBaseUrl(), + serverProperties.getSseMessageEndpoint(), serverProperties.getSseEndpoint()); } @Bean From 4c8b1474f90e765a289d6ea9bf770ead2f2369de Mon Sep 17 00:00:00 2001 From: lambochen Date: Tue, 15 Apr 2025 00:11:01 +0800 Subject: [PATCH 3/3] fix: record class for Spring properties Signed-off-by: lambochen --- .../properties/McpSseClientProperties.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/properties/McpSseClientProperties.java b/auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/properties/McpSseClientProperties.java index 498606206d8..7fd5037af63 100644 --- a/auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/properties/McpSseClientProperties.java +++ b/auto-configurations/mcp/spring-ai-autoconfigure-mcp-client/src/main/java/org/springframework/ai/mcp/client/autoconfigure/properties/McpSseClientProperties.java @@ -18,7 +18,10 @@ import java.util.HashMap; import java.util.Map; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.bind.DefaultValue; /** * Configuration properties for Server-Sent Events (SSE) based MCP client connections. @@ -52,10 +55,9 @@ public class McpSseClientProperties { * @param url the URL endpoint for SSE communication with the MCP server * @param sseEndpoint the SSE endpoint for SSE communication with the MCP server */ - public record SseParameters(String url, String sseEndpoint) { - public SseParameters(String url) { - this(url, "/sse"); - } + @JsonInclude(JsonInclude.Include.NON_ABSENT) + public record SseParameters(@JsonProperty("url") String url, + @JsonProperty("sse-endpoint") @DefaultValue("/sse") String sseEndpoint) { } /**