16
16
17
17
package org .springframework .ai .mcp .server .common .autoconfigure ;
18
18
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 ;
25
29
import org .springframework .ai .mcp .server .common .autoconfigure .properties .McpServerProperties ;
26
30
import org .springframework .beans .factory .ObjectProvider ;
27
31
import org .springframework .boot .autoconfigure .AutoConfiguration ;
28
32
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 .*;
34
34
import org .springframework .boot .context .properties .EnableConfigurationProperties ;
35
35
import org .springframework .context .annotation .Bean ;
36
36
import org .springframework .context .annotation .Conditional ;
37
37
import org .springframework .core .env .Environment ;
38
38
import org .springframework .core .log .LogAccessor ;
39
39
import org .springframework .util .CollectionUtils ;
40
40
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 ;
63
41
import reactor .core .publisher .Mono ;
64
42
43
+ import java .util .ArrayList ;
44
+ import java .util .List ;
45
+ import java .util .function .BiConsumer ;
46
+ import java .util .function .BiFunction ;
47
+
65
48
/**
66
49
* {@link EnableAutoConfiguration Auto-configuration} for the Model Context Protocol (MCP)
67
50
* Server.
78
61
"org.springframework.ai.mcp.server.autoconfigure.McpServerStreamableHttpWebMvcAutoConfiguration" ,
79
62
"org.springframework.ai.mcp.server.autoconfigure.McpServerStreamableHttpWebFluxAutoConfiguration" })
80
63
@ ConditionalOnClass ({ McpSchema .class })
81
- @ EnableConfigurationProperties ({ McpServerProperties .class , McpServerChangeNotificationProperties . class })
64
+ @ EnableConfigurationProperties ({ McpServerProperties .class })
82
65
@ ConditionalOnProperty (prefix = McpServerProperties .CONFIG_PREFIX , name = "enabled" , havingValue = "true" ,
83
66
matchIfMissing = true )
84
67
@ Conditional (McpServerAutoConfiguration .NonStatlessServerCondition .class )
@@ -163,7 +146,6 @@ public McpSchema.ServerCapabilities.Builder capabilitiesBuilder() {
163
146
matchIfMissing = true )
164
147
public McpSyncServer mcpSyncServer (McpServerTransportProviderBase transportProvider ,
165
148
McpSchema .ServerCapabilities .Builder capabilitiesBuilder , McpServerProperties serverProperties ,
166
- McpServerChangeNotificationProperties changeNotificationProperties ,
167
149
ObjectProvider <List <SyncToolSpecification >> tools ,
168
150
ObjectProvider <List <SyncResourceSpecification >> resources ,
169
151
ObjectProvider <List <SyncPromptSpecification >> prompts ,
@@ -187,8 +169,8 @@ public McpSyncServer mcpSyncServer(McpServerTransportProviderBase transportProvi
187
169
// Tools
188
170
if (serverProperties .getCapabilities ().isTool ()) {
189
171
logger .info ("Enable tools capabilities, notification: "
190
- + changeNotificationProperties .isToolChangeNotification ());
191
- capabilitiesBuilder .tools (changeNotificationProperties .isToolChangeNotification ());
172
+ + serverProperties . getToolChangeNotification () .isToolChangeNotification ());
173
+ capabilitiesBuilder .tools (serverProperties . getToolChangeNotification () .isToolChangeNotification ());
192
174
193
175
List <SyncToolSpecification > toolSpecifications = new ArrayList <>(
194
176
tools .stream ().flatMap (List ::stream ).toList ());
@@ -202,8 +184,9 @@ public McpSyncServer mcpSyncServer(McpServerTransportProviderBase transportProvi
202
184
// Resources
203
185
if (serverProperties .getCapabilities ().isResource ()) {
204
186
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 ());
207
190
208
191
List <SyncResourceSpecification > resourceSpecifications = resources .stream ().flatMap (List ::stream ).toList ();
209
192
if (!CollectionUtils .isEmpty (resourceSpecifications )) {
@@ -215,8 +198,8 @@ public McpSyncServer mcpSyncServer(McpServerTransportProviderBase transportProvi
215
198
// Prompts
216
199
if (serverProperties .getCapabilities ().isPrompt ()) {
217
200
logger .info ("Enable prompts capabilities, notification: "
218
- + changeNotificationProperties .isPromptChangeNotification ());
219
- capabilitiesBuilder .prompts (changeNotificationProperties .isPromptChangeNotification ());
201
+ + serverProperties . getToolChangeNotification () .isPromptChangeNotification ());
202
+ capabilitiesBuilder .prompts (serverProperties . getToolChangeNotification () .isPromptChangeNotification ());
220
203
221
204
List <SyncPromptSpecification > promptSpecifications = prompts .stream ().flatMap (List ::stream ).toList ();
222
205
if (!CollectionUtils .isEmpty (promptSpecifications )) {
@@ -262,7 +245,6 @@ public McpSyncServer mcpSyncServer(McpServerTransportProviderBase transportProvi
262
245
@ ConditionalOnProperty (prefix = McpServerProperties .CONFIG_PREFIX , name = "type" , havingValue = "ASYNC" )
263
246
public McpAsyncServer mcpAsyncServer (McpServerTransportProviderBase transportProvider ,
264
247
McpSchema .ServerCapabilities .Builder capabilitiesBuilder , McpServerProperties serverProperties ,
265
- McpServerChangeNotificationProperties changeNotificationProperties ,
266
248
ObjectProvider <List <AsyncToolSpecification >> tools ,
267
249
ObjectProvider <List <AsyncResourceSpecification >> resources ,
268
250
ObjectProvider <List <AsyncPromptSpecification >> prompts ,
@@ -288,8 +270,8 @@ public McpAsyncServer mcpAsyncServer(McpServerTransportProviderBase transportPro
288
270
tools .stream ().flatMap (List ::stream ).toList ());
289
271
290
272
logger .info ("Enable tools capabilities, notification: "
291
- + changeNotificationProperties .isToolChangeNotification ());
292
- capabilitiesBuilder .tools (changeNotificationProperties .isToolChangeNotification ());
273
+ + serverProperties . getToolChangeNotification () .isToolChangeNotification ());
274
+ capabilitiesBuilder .tools (serverProperties . getToolChangeNotification () .isToolChangeNotification ());
293
275
294
276
if (!CollectionUtils .isEmpty (toolSpecifications )) {
295
277
serverBuilder .tools (toolSpecifications );
@@ -300,8 +282,9 @@ public McpAsyncServer mcpAsyncServer(McpServerTransportProviderBase transportPro
300
282
// Resources
301
283
if (serverProperties .getCapabilities ().isResource ()) {
302
284
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 ());
305
288
306
289
List <AsyncResourceSpecification > resourceSpecifications = resources .stream ().flatMap (List ::stream ).toList ();
307
290
if (!CollectionUtils .isEmpty (resourceSpecifications )) {
@@ -313,8 +296,8 @@ public McpAsyncServer mcpAsyncServer(McpServerTransportProviderBase transportPro
313
296
// Prompts
314
297
if (serverProperties .getCapabilities ().isPrompt ()) {
315
298
logger .info ("Enable prompts capabilities, notification: "
316
- + changeNotificationProperties .isPromptChangeNotification ());
317
- capabilitiesBuilder .prompts (changeNotificationProperties .isPromptChangeNotification ());
299
+ + serverProperties . getToolChangeNotification () .isPromptChangeNotification ());
300
+ capabilitiesBuilder .prompts (serverProperties . getToolChangeNotification () .isPromptChangeNotification ());
318
301
List <AsyncPromptSpecification > promptSpecifications = prompts .stream ().flatMap (List ::stream ).toList ();
319
302
320
303
if (!CollectionUtils .isEmpty (promptSpecifications )) {
0 commit comments