1616
1717package 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 ;
2529import org .springframework .ai .mcp .server .common .autoconfigure .properties .McpServerProperties ;
2630import org .springframework .beans .factory .ObjectProvider ;
2731import org .springframework .boot .autoconfigure .AutoConfiguration ;
2832import 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 .*;
3434import org .springframework .boot .context .properties .EnableConfigurationProperties ;
3535import org .springframework .context .annotation .Bean ;
3636import org .springframework .context .annotation .Conditional ;
3737import org .springframework .core .env .Environment ;
3838import org .springframework .core .log .LogAccessor ;
3939import org .springframework .util .CollectionUtils ;
4040import 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 ;
6341import 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.
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 )) {
0 commit comments