Skip to content

Commit 862396e

Browse files
committed
refactor: consolidate MCP server configuration properties into unified structure
Replace 4 separate configuration classes with unified McpServerProperties: - Consolidate all MCP server config under spring.ai.mcp.server prefix - Add nested classes for protocol-specific settings (SSE, Streamable, Stateless) - Update configuration paths and test cases accordingly - Follow Spring Boot ServerProperties pattern This eliminates configuration fragmentation and provides single entry point for users. Signed-off-by: yinh <[email protected]>
1 parent 1df5f5c commit 862396e

File tree

22 files changed

+435
-549
lines changed

22 files changed

+435
-549
lines changed

auto-configurations/mcp/spring-ai-autoconfigure-mcp-server-common/src/main/java/org/springframework/ai/mcp/server/common/autoconfigure/McpServerAutoConfiguration.java

Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,52 +16,35 @@
1616

1717
package org.springframework.ai.mcp.server.common.autoconfigure;
1818

19-
import java.util.ArrayList;
20-
import java.util.List;
21-
import java.util.function.BiConsumer;
22-
import java.util.function.BiFunction;
23-
24-
import org.springframework.ai.mcp.server.common.autoconfigure.properties.McpServerChangeNotificationProperties;
19+
import io.modelcontextprotocol.server.*;
20+
import io.modelcontextprotocol.server.McpServer.AsyncSpecification;
21+
import io.modelcontextprotocol.server.McpServer.SyncSpecification;
22+
import io.modelcontextprotocol.server.McpServerFeatures.*;
23+
import io.modelcontextprotocol.server.transport.StdioServerTransportProvider;
24+
import io.modelcontextprotocol.spec.McpSchema;
25+
import io.modelcontextprotocol.spec.McpSchema.Implementation;
26+
import io.modelcontextprotocol.spec.McpServerTransportProvider;
27+
import io.modelcontextprotocol.spec.McpServerTransportProviderBase;
28+
import io.modelcontextprotocol.spec.McpStreamableServerTransportProvider;
2529
import org.springframework.ai.mcp.server.common.autoconfigure.properties.McpServerProperties;
2630
import org.springframework.beans.factory.ObjectProvider;
2731
import org.springframework.boot.autoconfigure.AutoConfiguration;
2832
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
29-
import org.springframework.boot.autoconfigure.condition.AllNestedConditions;
30-
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
31-
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
32-
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
33-
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
33+
import org.springframework.boot.autoconfigure.condition.*;
3434
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3535
import org.springframework.context.annotation.Bean;
3636
import org.springframework.context.annotation.Conditional;
3737
import org.springframework.core.env.Environment;
3838
import org.springframework.core.log.LogAccessor;
3939
import org.springframework.util.CollectionUtils;
4040
import org.springframework.web.context.support.StandardServletEnvironment;
41-
42-
import io.modelcontextprotocol.server.McpAsyncServer;
43-
import io.modelcontextprotocol.server.McpAsyncServerExchange;
44-
import io.modelcontextprotocol.server.McpServer;
45-
import io.modelcontextprotocol.server.McpServer.AsyncSpecification;
46-
import io.modelcontextprotocol.server.McpServer.SyncSpecification;
47-
import io.modelcontextprotocol.server.McpServerFeatures.AsyncCompletionSpecification;
48-
import io.modelcontextprotocol.server.McpServerFeatures.AsyncPromptSpecification;
49-
import io.modelcontextprotocol.server.McpServerFeatures.AsyncResourceSpecification;
50-
import io.modelcontextprotocol.server.McpServerFeatures.AsyncToolSpecification;
51-
import io.modelcontextprotocol.server.McpServerFeatures.SyncCompletionSpecification;
52-
import io.modelcontextprotocol.server.McpServerFeatures.SyncPromptSpecification;
53-
import io.modelcontextprotocol.server.McpServerFeatures.SyncResourceSpecification;
54-
import io.modelcontextprotocol.server.McpServerFeatures.SyncToolSpecification;
55-
import io.modelcontextprotocol.server.McpSyncServer;
56-
import io.modelcontextprotocol.server.McpSyncServerExchange;
57-
import io.modelcontextprotocol.server.transport.StdioServerTransportProvider;
58-
import io.modelcontextprotocol.spec.McpSchema;
59-
import io.modelcontextprotocol.spec.McpSchema.Implementation;
60-
import io.modelcontextprotocol.spec.McpServerTransportProvider;
61-
import io.modelcontextprotocol.spec.McpServerTransportProviderBase;
62-
import io.modelcontextprotocol.spec.McpStreamableServerTransportProvider;
6341
import reactor.core.publisher.Mono;
6442

43+
import java.util.ArrayList;
44+
import java.util.List;
45+
import java.util.function.BiConsumer;
46+
import java.util.function.BiFunction;
47+
6548
/**
6649
* {@link EnableAutoConfiguration Auto-configuration} for the Model Context Protocol (MCP)
6750
* Server.
@@ -78,7 +61,7 @@
7861
"org.springframework.ai.mcp.server.autoconfigure.McpServerStreamableHttpWebMvcAutoConfiguration",
7962
"org.springframework.ai.mcp.server.autoconfigure.McpServerStreamableHttpWebFluxAutoConfiguration" })
8063
@ConditionalOnClass({ McpSchema.class })
81-
@EnableConfigurationProperties({ McpServerProperties.class, McpServerChangeNotificationProperties.class })
64+
@EnableConfigurationProperties({ McpServerProperties.class })
8265
@ConditionalOnProperty(prefix = McpServerProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true",
8366
matchIfMissing = true)
8467
@Conditional(McpServerAutoConfiguration.NonStatlessServerCondition.class)
@@ -163,7 +146,6 @@ public McpSchema.ServerCapabilities.Builder capabilitiesBuilder() {
163146
matchIfMissing = true)
164147
public McpSyncServer mcpSyncServer(McpServerTransportProviderBase transportProvider,
165148
McpSchema.ServerCapabilities.Builder capabilitiesBuilder, McpServerProperties serverProperties,
166-
McpServerChangeNotificationProperties changeNotificationProperties,
167149
ObjectProvider<List<SyncToolSpecification>> tools,
168150
ObjectProvider<List<SyncResourceSpecification>> resources,
169151
ObjectProvider<List<SyncPromptSpecification>> prompts,
@@ -187,8 +169,8 @@ public McpSyncServer mcpSyncServer(McpServerTransportProviderBase transportProvi
187169
// Tools
188170
if (serverProperties.getCapabilities().isTool()) {
189171
logger.info("Enable tools capabilities, notification: "
190-
+ changeNotificationProperties.isToolChangeNotification());
191-
capabilitiesBuilder.tools(changeNotificationProperties.isToolChangeNotification());
172+
+ serverProperties.getToolChangeNotification().isToolChangeNotification());
173+
capabilitiesBuilder.tools(serverProperties.getToolChangeNotification().isToolChangeNotification());
192174

193175
List<SyncToolSpecification> toolSpecifications = new ArrayList<>(
194176
tools.stream().flatMap(List::stream).toList());
@@ -202,8 +184,9 @@ public McpSyncServer mcpSyncServer(McpServerTransportProviderBase transportProvi
202184
// Resources
203185
if (serverProperties.getCapabilities().isResource()) {
204186
logger.info("Enable resources capabilities, notification: "
205-
+ changeNotificationProperties.isResourceChangeNotification());
206-
capabilitiesBuilder.resources(false, changeNotificationProperties.isResourceChangeNotification());
187+
+ serverProperties.getToolChangeNotification().isResourceChangeNotification());
188+
capabilitiesBuilder.resources(false,
189+
serverProperties.getToolChangeNotification().isResourceChangeNotification());
207190

208191
List<SyncResourceSpecification> resourceSpecifications = resources.stream().flatMap(List::stream).toList();
209192
if (!CollectionUtils.isEmpty(resourceSpecifications)) {
@@ -215,8 +198,8 @@ public McpSyncServer mcpSyncServer(McpServerTransportProviderBase transportProvi
215198
// Prompts
216199
if (serverProperties.getCapabilities().isPrompt()) {
217200
logger.info("Enable prompts capabilities, notification: "
218-
+ changeNotificationProperties.isPromptChangeNotification());
219-
capabilitiesBuilder.prompts(changeNotificationProperties.isPromptChangeNotification());
201+
+ serverProperties.getToolChangeNotification().isPromptChangeNotification());
202+
capabilitiesBuilder.prompts(serverProperties.getToolChangeNotification().isPromptChangeNotification());
220203

221204
List<SyncPromptSpecification> promptSpecifications = prompts.stream().flatMap(List::stream).toList();
222205
if (!CollectionUtils.isEmpty(promptSpecifications)) {
@@ -262,7 +245,6 @@ public McpSyncServer mcpSyncServer(McpServerTransportProviderBase transportProvi
262245
@ConditionalOnProperty(prefix = McpServerProperties.CONFIG_PREFIX, name = "type", havingValue = "ASYNC")
263246
public McpAsyncServer mcpAsyncServer(McpServerTransportProviderBase transportProvider,
264247
McpSchema.ServerCapabilities.Builder capabilitiesBuilder, McpServerProperties serverProperties,
265-
McpServerChangeNotificationProperties changeNotificationProperties,
266248
ObjectProvider<List<AsyncToolSpecification>> tools,
267249
ObjectProvider<List<AsyncResourceSpecification>> resources,
268250
ObjectProvider<List<AsyncPromptSpecification>> prompts,
@@ -288,8 +270,8 @@ public McpAsyncServer mcpAsyncServer(McpServerTransportProviderBase transportPro
288270
tools.stream().flatMap(List::stream).toList());
289271

290272
logger.info("Enable tools capabilities, notification: "
291-
+ changeNotificationProperties.isToolChangeNotification());
292-
capabilitiesBuilder.tools(changeNotificationProperties.isToolChangeNotification());
273+
+ serverProperties.getToolChangeNotification().isToolChangeNotification());
274+
capabilitiesBuilder.tools(serverProperties.getToolChangeNotification().isToolChangeNotification());
293275

294276
if (!CollectionUtils.isEmpty(toolSpecifications)) {
295277
serverBuilder.tools(toolSpecifications);
@@ -300,8 +282,9 @@ public McpAsyncServer mcpAsyncServer(McpServerTransportProviderBase transportPro
300282
// Resources
301283
if (serverProperties.getCapabilities().isResource()) {
302284
logger.info("Enable resources capabilities, notification: "
303-
+ changeNotificationProperties.isResourceChangeNotification());
304-
capabilitiesBuilder.resources(false, changeNotificationProperties.isResourceChangeNotification());
285+
+ serverProperties.getToolChangeNotification().isResourceChangeNotification());
286+
capabilitiesBuilder.resources(false,
287+
serverProperties.getToolChangeNotification().isResourceChangeNotification());
305288

306289
List<AsyncResourceSpecification> resourceSpecifications = resources.stream().flatMap(List::stream).toList();
307290
if (!CollectionUtils.isEmpty(resourceSpecifications)) {
@@ -313,8 +296,8 @@ public McpAsyncServer mcpAsyncServer(McpServerTransportProviderBase transportPro
313296
// Prompts
314297
if (serverProperties.getCapabilities().isPrompt()) {
315298
logger.info("Enable prompts capabilities, notification: "
316-
+ changeNotificationProperties.isPromptChangeNotification());
317-
capabilitiesBuilder.prompts(changeNotificationProperties.isPromptChangeNotification());
299+
+ serverProperties.getToolChangeNotification().isPromptChangeNotification());
300+
capabilitiesBuilder.prompts(serverProperties.getToolChangeNotification().isPromptChangeNotification());
318301
List<AsyncPromptSpecification> promptSpecifications = prompts.stream().flatMap(List::stream).toList();
319302

320303
if (!CollectionUtils.isEmpty(promptSpecifications)) {

auto-configurations/mcp/spring-ai-autoconfigure-mcp-server-common/src/main/java/org/springframework/ai/mcp/server/common/autoconfigure/properties/McpServerChangeNotificationProperties.java

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)