Skip to content

Commit 55b1281

Browse files
committed
feat(mcp): refactor MCP transport configuration to use dedicated starters
- Add dedicated spring-ai-starter-mcp-webmvc and spring-ai-starter-mcp-webflux starters - Remove transport property-based configuration in favor of auto-configuration - Update WebMvc/WebFlux configuration to use ConditionalOnMissingBean Signed-off-by: Christian Tzolov <[email protected]>
1 parent 171b758 commit 55b1281

File tree

9 files changed

+156
-56
lines changed

9 files changed

+156
-56
lines changed

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@
128128
<module>spring-ai-spring-boot-starters/spring-ai-starter-moonshot</module>
129129

130130
<module>spring-ai-spring-boot-starters/spring-ai-starter-mcp</module>
131+
<module>spring-ai-spring-boot-starters/spring-ai-starter-mcp-webmvc</module>
132+
<module>spring-ai-spring-boot-starters/spring-ai-starter-mcp-webflux</module>
131133

132134
<module>spring-ai-integration-tests</module>
133135

spring-ai-bom/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,19 @@
593593
<version>${project.version}</version>
594594
</dependency>
595595

596+
<dependency>
597+
<groupId>org.springframework.ai</groupId>
598+
<artifactId>spring-ai-mcp-webflux-spring-boot-starter</artifactId>
599+
<version>${project.version}</version>
600+
</dependency>
601+
602+
<dependency>
603+
<groupId>org.springframework.ai</groupId>
604+
<artifactId>spring-ai-mcp-webmvc-spring-boot-starter</artifactId>
605+
<version>${project.version}</version>
606+
</dependency>
607+
608+
596609
</dependencies>
597610
</dependencyManagement>
598611

spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/mcp/server/McpServerProperties.java

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,6 @@ public class McpServerProperties {
8888
*/
8989
private boolean promptChangeNotification = true;
9090

91-
/**
92-
* The transport type to use for MCP server communication.
93-
* <p>
94-
* Supported types are:
95-
* <ul>
96-
* <li>STDIO - Standard input/output transport (default)</li>
97-
* <li>WEBMVC - Spring MVC Server-Sent Events transport</li>
98-
* <li>WEBFLUX - Spring WebFlux Server-Sent Events transport</li>
99-
* </ul>
100-
*/
101-
private Transport transport = Transport.STDIO;
102-
10391
/**
10492
* The endpoint path for Server-Sent Events (SSE) when using web transports.
10593
* <p>
@@ -118,31 +106,6 @@ public class McpServerProperties {
118106
*/
119107
private ServerType type = ServerType.SYNC;
120108

121-
/**
122-
* Transport types supported by the MCP server.
123-
*/
124-
public enum Transport {
125-
126-
/**
127-
* Standard input/output transport, suitable for command-line tools and local
128-
* development.
129-
*/
130-
STDIO,
131-
132-
/**
133-
* Spring MVC Server-Sent Events transport, requires spring-boot-starter-web and
134-
* mcp-spring-webmvc.
135-
*/
136-
WEBMVC,
137-
138-
/**
139-
* Spring WebFlux Server-Sent Events transport, requires
140-
* spring-boot-starter-webflux and mcp-spring-webflux.
141-
*/
142-
WEBFLUX
143-
144-
}
145-
146109
/**
147110
* Server types supported by the MCP server.
148111
*/
@@ -210,15 +173,6 @@ public void setPromptChangeNotification(boolean promptChangeNotification) {
210173
this.promptChangeNotification = promptChangeNotification;
211174
}
212175

213-
public Transport getTransport() {
214-
return this.transport;
215-
}
216-
217-
public void setTransport(Transport transport) {
218-
Assert.notNull(transport, "Transport must not be null");
219-
this.transport = transport;
220-
}
221-
222176
public String getSseMessageEndpoint() {
223177
return this.sseMessageEndpoint;
224178
}

spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/mcp/server/MpcServerAutoConfiguration.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@
2020
import java.util.function.Consumer;
2121
import java.util.function.Function;
2222

23+
import io.modelcontextprotocol.server.McpAsyncServer;
2324
import io.modelcontextprotocol.server.McpServer;
24-
import reactor.core.publisher.Mono;
25-
import io.modelcontextprotocol.server.McpServer.SyncSpec;
2625
import io.modelcontextprotocol.server.McpServer.AsyncSpec;
26+
import io.modelcontextprotocol.server.McpServer.SyncSpec;
2727
import io.modelcontextprotocol.server.McpServerFeatures;
28-
import io.modelcontextprotocol.server.McpServerFeatures.SyncToolRegistration;
2928
import io.modelcontextprotocol.server.McpServerFeatures.AsyncToolRegistration;
29+
import io.modelcontextprotocol.server.McpServerFeatures.SyncToolRegistration;
3030
import io.modelcontextprotocol.server.McpSyncServer;
31-
import io.modelcontextprotocol.server.McpAsyncServer;
3231
import io.modelcontextprotocol.server.transport.StdioServerTransport;
3332
import io.modelcontextprotocol.spec.McpSchema;
3433
import io.modelcontextprotocol.spec.McpSchema.Implementation;
3534
import io.modelcontextprotocol.spec.ServerMcpTransport;
35+
import reactor.core.publisher.Mono;
3636

3737
import org.springframework.ai.mcp.McpToolUtils;
3838
import org.springframework.ai.tool.ToolCallback;
@@ -94,7 +94,7 @@
9494
* @see MpcWebMvcServerAutoConfiguration
9595
* @see org.springframework.ai.mcp.ToolCallback
9696
*/
97-
@AutoConfiguration
97+
@AutoConfiguration(after = { MpcWebMvcServerAutoConfiguration.class, MpcWebFluxServerAutoConfiguration.class })
9898
@ConditionalOnClass({ McpSchema.class, McpSyncServer.class })
9999
@EnableConfigurationProperties(McpServerProperties.class)
100100
@ConditionalOnProperty(prefix = McpServerProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true")
@@ -104,8 +104,6 @@ public class MpcServerAutoConfiguration {
104104

105105
@Bean
106106
@ConditionalOnMissingBean
107-
@ConditionalOnProperty(prefix = McpServerProperties.CONFIG_PREFIX, name = "transport", havingValue = "STDIO",
108-
matchIfMissing = true)
109107
public ServerMcpTransport stdioServerTransport() {
110108
return new StdioServerTransport();
111109
}

spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/mcp/server/MpcWebFluxServerAutoConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.fasterxml.jackson.databind.ObjectMapper;
2020
import io.modelcontextprotocol.server.transport.WebFluxSseServerTransport;
21+
import io.modelcontextprotocol.spec.ServerMcpTransport;
2122

2223
import org.springframework.boot.autoconfigure.AutoConfiguration;
2324
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -64,7 +65,7 @@
6465
*/
6566
@AutoConfiguration
6667
@ConditionalOnClass({ WebFluxSseServerTransport.class })
67-
@ConditionalOnProperty(prefix = McpServerProperties.CONFIG_PREFIX, name = "transport", havingValue = "WEBFLUX")
68+
@ConditionalOnMissingBean(ServerMcpTransport.class)
6869
public class MpcWebFluxServerAutoConfiguration {
6970

7071
@Bean

spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/mcp/server/MpcWebMvcServerAutoConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.fasterxml.jackson.databind.ObjectMapper;
2020
import io.modelcontextprotocol.server.transport.WebMvcSseServerTransport;
21+
import io.modelcontextprotocol.spec.ServerMcpTransport;
2122

2223
import org.springframework.boot.autoconfigure.AutoConfiguration;
2324
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -64,7 +65,7 @@
6465
*/
6566
@AutoConfiguration
6667
@ConditionalOnClass({ WebMvcSseServerTransport.class })
67-
@ConditionalOnProperty(prefix = McpServerProperties.CONFIG_PREFIX, name = "transport", havingValue = "WEBMVC")
68+
@ConditionalOnMissingBean(ServerMcpTransport.class)
6869
public class MpcWebMvcServerAutoConfiguration {
6970

7071
@Bean

spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mcp/server/McpServerAutoConfigurationIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ void defaultConfiguration() {
4343
McpServerProperties properties = context.getBean(McpServerProperties.class);
4444
assertThat(properties.getName()).isEqualTo("mcp-server");
4545
assertThat(properties.getVersion()).isEqualTo("1.0.0");
46-
assertThat(properties.getTransport()).isEqualTo(McpServerProperties.Transport.STDIO);
4746
assertThat(properties.getType()).isEqualTo(McpServerProperties.ServerType.SYNC);
4847
assertThat(properties.isToolChangeNotification()).isTrue();
4948
assertThat(properties.isResourceChangeNotification()).isTrue();
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+
<!--
3+
~ Copyright 2023-2024 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ https://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
<parent>
23+
<groupId>org.springframework.ai</groupId>
24+
<artifactId>spring-ai</artifactId>
25+
<version>1.0.0-SNAPSHOT</version>
26+
<relativePath>../../pom.xml</relativePath>
27+
</parent>
28+
<artifactId>spring-ai-mcp-webflux-spring-boot-starter</artifactId>
29+
<packaging>jar</packaging>
30+
<name>Spring AI Starter - MCP Webflux</name>
31+
<description>Spring AI MCP WebFlux Auto Configuration</description>
32+
<url>https://github.com/spring-projects/spring-ai</url>
33+
34+
<scm>
35+
<url>https://github.com/spring-projects/spring-ai</url>
36+
<connection>git://github.com/spring-projects/spring-ai.git</connection>
37+
<developerConnection>[email protected]:spring-projects/spring-ai.git</developerConnection>
38+
</scm>
39+
40+
<dependencies>
41+
42+
<dependency>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-starter</artifactId>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>org.springframework.ai</groupId>
49+
<artifactId>spring-ai-spring-boot-autoconfigure</artifactId>
50+
<version>${project.parent.version}</version>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>org.springframework.ai</groupId>
55+
<artifactId>spring-ai-mcp</artifactId>
56+
<version>${project.parent.version}</version>
57+
</dependency>
58+
59+
<dependency>
60+
<groupId>io.modelcontextprotocol.sdk</groupId>
61+
<artifactId>mcp-spring-webflux</artifactId>
62+
</dependency>
63+
64+
</dependencies>
65+
66+
</project>
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+
<!--
3+
~ Copyright 2023-2024 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ https://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
<parent>
23+
<groupId>org.springframework.ai</groupId>
24+
<artifactId>spring-ai</artifactId>
25+
<version>1.0.0-SNAPSHOT</version>
26+
<relativePath>../../pom.xml</relativePath>
27+
</parent>
28+
<artifactId>spring-ai-mcp-webmvc-spring-boot-starter</artifactId>
29+
<packaging>jar</packaging>
30+
<name>Spring AI Starter - MCP WEBMVC</name>
31+
<description>Spring AI MCP WebMvc Auto Configuration</description>
32+
<url>https://github.com/spring-projects/spring-ai</url>
33+
34+
<scm>
35+
<url>https://github.com/spring-projects/spring-ai</url>
36+
<connection>git://github.com/spring-projects/spring-ai.git</connection>
37+
<developerConnection>[email protected]:spring-projects/spring-ai.git</developerConnection>
38+
</scm>
39+
40+
<dependencies>
41+
42+
<dependency>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-starter</artifactId>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>org.springframework.ai</groupId>
49+
<artifactId>spring-ai-spring-boot-autoconfigure</artifactId>
50+
<version>${project.parent.version}</version>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>org.springframework.ai</groupId>
55+
<artifactId>spring-ai-mcp</artifactId>
56+
<version>${project.parent.version}</version>
57+
</dependency>
58+
59+
<dependency>
60+
<groupId>io.modelcontextprotocol.sdk</groupId>
61+
<artifactId>mcp-spring-webmvc</artifactId>
62+
</dependency>
63+
64+
</dependencies>
65+
66+
</project>

0 commit comments

Comments
 (0)