diff --git a/auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/pom.xml b/auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/pom.xml
index f8d1d3509b5..ad5c54b933d 100644
--- a/auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/pom.xml
+++ b/auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/pom.xml
@@ -68,7 +68,11 @@
+ * This configuration class sets up the HttpServlet-specific Streamable transport + * components for the MCP server, providing HTTP streaming communication through standard + * Java Servlet API. It is activated when: + *
+ * The configuration provides: + *
+ * This configuration has the lowest priority and will only be activated if no WebFlux or + * WebMVC streamable transports are available. + *
+ * Required dependencies:
{@code
+ *
+ * io.modelcontextprotocol.sdk
+ * mcp-server-http-servlet
+ *
+ * }
+ *
+ * @author yinh
+ * @since 1.0.1
+ * @see McpServerProperties
+ * @see HttpServletStreamableServerTransportProvider
+ */
+@AutoConfiguration(
+ after = { McpWebFluxStreamableServerAutoConfiguration.class, McpWebMvcStreamableServerAutoConfiguration.class })
+@ConditionalOnClass({ HttpServletStreamableServerTransportProvider.class })
+@ConditionalOnMissingBean(McpServerTransportProvider.class)
+@Conditional(McpServerStreamableTransportCondition.class)
+public class McpHttpServletStreamableServerAutoConfiguration {
+
+ @Bean
+ @ConditionalOnMissingBean
+ public HttpServletStreamableServerTransportProvider httpServletStreamableTransport(
+ ObjectProvider+ * Supported transport types: + *
@@ -170,6 +182,23 @@ public enum ServerType { } + /** + * Transport types supported by the MCP server for web communication. + */ + public enum TransportType { + + /** + * Server-Sent Events transport + */ + SSE, + + /** + * Streamable HTTP transport + */ + STREAMABLE + + } + /** * (Optional) response MIME type per tool name. */ diff --git a/auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/main/java/org/springframework/ai/mcp/server/autoconfigure/McpServerStreamableTransportCondition.java b/auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/main/java/org/springframework/ai/mcp/server/autoconfigure/McpServerStreamableTransportCondition.java new file mode 100644 index 00000000000..c5c52b4658c --- /dev/null +++ b/auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/main/java/org/springframework/ai/mcp/server/autoconfigure/McpServerStreamableTransportCondition.java @@ -0,0 +1,37 @@ +package org.springframework.ai.mcp.server.autoconfigure; + +import org.springframework.boot.autoconfigure.condition.AllNestedConditions; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; + +/** + * This class defines a condition met when the MCP server is enabled, STDIO transport is + * disabled, and STREAMABLE transport type is selected. + * + * @since 1.1.0 + * @author yinh + */ +public class McpServerStreamableTransportCondition extends AllNestedConditions { + + public McpServerStreamableTransportCondition() { + super(ConfigurationPhase.PARSE_CONFIGURATION); + } + + @ConditionalOnProperty(prefix = McpServerProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true", + matchIfMissing = true) + static class McpServerEnabledCondition { + + } + + @ConditionalOnProperty(prefix = McpServerProperties.CONFIG_PREFIX, name = "stdio", havingValue = "false", + matchIfMissing = true) + static class StdioDisabledCondition { + + } + + @ConditionalOnProperty(prefix = McpServerProperties.CONFIG_PREFIX, name = "transport-type", + havingValue = "STREAMABLE") + static class StreamableTransportCondition { + + } + +} diff --git a/auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/main/java/org/springframework/ai/mcp/server/autoconfigure/McpWebFluxStreamableServerAutoConfiguration.java b/auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/main/java/org/springframework/ai/mcp/server/autoconfigure/McpWebFluxStreamableServerAutoConfiguration.java new file mode 100644 index 00000000000..800d526432c --- /dev/null +++ b/auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/main/java/org/springframework/ai/mcp/server/autoconfigure/McpWebFluxStreamableServerAutoConfiguration.java @@ -0,0 +1,97 @@ +/* + * Copyright 2025-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.ai.mcp.server.autoconfigure; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.modelcontextprotocol.server.transport.WebFluxStreamableServerTransportProvider; +import io.modelcontextprotocol.spec.McpServerTransportProvider; +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.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.web.reactive.function.server.RouterFunction; + +/** + * {@link AutoConfiguration Auto-configuration} for MCP WebFlux Streamable Server + * Transport. + *
+ * This configuration class sets up the WebFlux-specific Streamable transport components + * for the MCP server, providing reactive HTTP streaming communication through Spring + * WebFlux. It is activated when: + *
+ * The configuration provides: + *
+ * Required dependencies:
{@code
+ *
+ * io.modelcontextprotocol.sdk
+ * mcp-spring-webflux
+ *
+ *
+ * org.springframework.boot
+ * spring-boot-starter-webflux
+ *
+ * }
+ *
+ * @author yinh
+ * @since 1.0.1
+ * @see McpServerProperties
+ * @see WebFluxStreamableServerTransportProvider
+ */
+@AutoConfiguration
+@ConditionalOnClass({ WebFluxStreamableServerTransportProvider.class, RouterFunction.class })
+@ConditionalOnMissingBean(McpServerTransportProvider.class)
+@Conditional(McpServerStreamableTransportCondition.class)
+public class McpWebFluxStreamableServerAutoConfiguration {
+
+ @Bean
+ @ConditionalOnMissingBean
+ public WebFluxStreamableServerTransportProvider webFluxStreamableTransport(
+ ObjectProvider+ * This configuration class sets up the WebMvc-specific Streamable transport components + * for the MCP server, providing HTTP streaming communication through Spring MVC. It is + * activated when: + *
+ * The configuration provides: + *
+ * Required dependencies:
{@code
+ *
+ * io.modelcontextprotocol.sdk
+ * mcp-spring-webmvc
+ *
+ *
+ * org.springframework.boot
+ * spring-boot-starter-web
+ *
+ * }
+ *
+ * @author yinh
+ * @since 1.1.0
+ * @see McpServerProperties
+ * @see WebMvcStreamableServerTransportProvider
+ */
+@AutoConfiguration
+@ConditionalOnClass({ WebMvcStreamableServerTransportProvider.class, RouterFunction.class })
+@ConditionalOnMissingBean(McpServerTransportProvider.class)
+@Conditional(McpServerStreamableTransportCondition.class)
+public class McpWebMvcStreamableServerAutoConfiguration {
+
+ @Bean
+ @ConditionalOnMissingBean
+ public WebMvcStreamableServerTransportProvider webMvcStreamableTransport(
+ ObjectProvider