20
20
import java .util .List ;
21
21
import java .util .function .Consumer ;
22
22
import java .util .function .Function ;
23
- import java .util .stream .Stream ;
24
23
25
24
import io .modelcontextprotocol .server .McpAsyncServer ;
26
25
import io .modelcontextprotocol .server .McpServer ;
41
40
import reactor .core .publisher .Mono ;
42
41
43
42
import org .springframework .ai .mcp .McpToolUtils ;
44
- import org .springframework .ai .model .function .FunctionCallback ;
45
43
import org .springframework .ai .tool .ToolCallback ;
46
44
import org .springframework .ai .tool .ToolCallbackProvider ;
47
45
import org .springframework .beans .factory .ObjectProvider ;
@@ -161,7 +159,7 @@ public McpSyncServer mcpSyncServer(ServerMcpTransport transport,
161
159
// Create the server with both tool and resource capabilities
162
160
SyncSpec serverBuilder = McpServer .sync (transport ).serverInfo (serverInfo );
163
161
164
- List <SyncToolRegistration > toolResgistrations = new ArrayList <>(tools .stream ().flatMap (List ::stream ).toList ());
162
+ List <SyncToolRegistration > toolRegistrations = new ArrayList <>(tools .stream ().flatMap (List ::stream ).toList ());
165
163
166
164
List <ToolCallback > providerToolCallbacks = toolCallbackProvider .stream ()
167
165
.map (pr -> List .of (pr .getToolCallbacks ()))
@@ -170,28 +168,28 @@ public McpSyncServer mcpSyncServer(ServerMcpTransport transport,
170
168
.map (fc -> (ToolCallback ) fc )
171
169
.toList ();
172
170
173
- toolResgistrations .addAll (this .toSyncToolRegistration (providerToolCallbacks , serverProperties ));
171
+ toolRegistrations .addAll (this .toSyncToolRegistration (providerToolCallbacks , serverProperties ));
174
172
175
- if (!CollectionUtils .isEmpty (toolResgistrations )) {
176
- serverBuilder .tools (toolResgistrations );
173
+ if (!CollectionUtils .isEmpty (toolRegistrations )) {
174
+ serverBuilder .tools (toolRegistrations );
177
175
capabilitiesBuilder .tools (serverProperties .isToolChangeNotification ());
178
- logger .info ("Registered tools" + toolResgistrations .size () + " notification: "
176
+ logger .info ("Registered tools" + toolRegistrations .size () + " notification: "
179
177
+ serverProperties .isToolChangeNotification ());
180
178
}
181
179
182
- List <SyncResourceRegistration > resourceResgistrations = resources .stream ().flatMap (List ::stream ).toList ();
183
- if (!CollectionUtils .isEmpty (resourceResgistrations )) {
184
- serverBuilder .resources (resourceResgistrations );
180
+ List <SyncResourceRegistration > resourceRegistrations = resources .stream ().flatMap (List ::stream ).toList ();
181
+ if (!CollectionUtils .isEmpty (resourceRegistrations )) {
182
+ serverBuilder .resources (resourceRegistrations );
185
183
capabilitiesBuilder .resources (false , serverProperties .isResourceChangeNotification ());
186
- logger .info ("Registered resources" + resourceResgistrations .size () + " notification: "
184
+ logger .info ("Registered resources" + resourceRegistrations .size () + " notification: "
187
185
+ serverProperties .isResourceChangeNotification ());
188
186
}
189
187
190
- List <SyncPromptRegistration > promptResgistrations = prompts .stream ().flatMap (List ::stream ).toList ();
191
- if (!CollectionUtils .isEmpty (promptResgistrations )) {
192
- serverBuilder .prompts (promptResgistrations );
188
+ List <SyncPromptRegistration > promptRegistrations = prompts .stream ().flatMap (List ::stream ).toList ();
189
+ if (!CollectionUtils .isEmpty (promptRegistrations )) {
190
+ serverBuilder .prompts (promptRegistrations );
193
191
capabilitiesBuilder .prompts (serverProperties .isPromptChangeNotification ());
194
- logger .info ("Registered prompts" + promptResgistrations .size () + " notification: "
192
+ logger .info ("Registered prompts" + promptRegistrations .size () + " notification: "
195
193
+ serverProperties .isPromptChangeNotification ());
196
194
}
197
195
@@ -238,38 +236,38 @@ public McpAsyncServer mcpAsyncServer(ServerMcpTransport transport,
238
236
serverProperties .getVersion ());
239
237
240
238
// Create the server with both tool and resource capabilities
241
- AsyncSpec serverBilder = McpServer .async (transport ).serverInfo (serverInfo );
239
+ AsyncSpec serverBuilder = McpServer .async (transport ).serverInfo (serverInfo );
242
240
243
- List <AsyncToolRegistration > toolResgistrations = new ArrayList <>(tools .stream ().flatMap (List ::stream ).toList ());
241
+ List <AsyncToolRegistration > toolRegistrations = new ArrayList <>(tools .stream ().flatMap (List ::stream ).toList ());
244
242
List <ToolCallback > providerToolCallbacks = toolCallbackProvider .stream ()
245
243
.map (pr -> List .of (pr .getToolCallbacks ()))
246
244
.flatMap (List ::stream )
247
245
.filter (fc -> fc instanceof ToolCallback )
248
246
.map (fc -> (ToolCallback ) fc )
249
247
.toList ();
250
248
251
- toolResgistrations .addAll (this .toAsyncToolRegistration (providerToolCallbacks , serverProperties ));
249
+ toolRegistrations .addAll (this .toAsyncToolRegistration (providerToolCallbacks , serverProperties ));
252
250
253
- if (!CollectionUtils .isEmpty (toolResgistrations )) {
254
- serverBilder .tools (toolResgistrations );
251
+ if (!CollectionUtils .isEmpty (toolRegistrations )) {
252
+ serverBuilder .tools (toolRegistrations );
255
253
capabilitiesBuilder .tools (serverProperties .isToolChangeNotification ());
256
- logger .info ("Registered tools" + toolResgistrations .size () + " notification: "
254
+ logger .info ("Registered tools" + toolRegistrations .size () + " notification: "
257
255
+ serverProperties .isToolChangeNotification ());
258
256
}
259
257
260
- List <AsyncResourceRegistration > resourceResgistrations = resources .stream ().flatMap (List ::stream ).toList ();
261
- if (!CollectionUtils .isEmpty (resourceResgistrations )) {
262
- serverBilder .resources (resourceResgistrations );
258
+ List <AsyncResourceRegistration > resourceRegistrations = resources .stream ().flatMap (List ::stream ).toList ();
259
+ if (!CollectionUtils .isEmpty (resourceRegistrations )) {
260
+ serverBuilder .resources (resourceRegistrations );
263
261
capabilitiesBuilder .resources (false , serverProperties .isResourceChangeNotification ());
264
- logger .info ("Registered resources" + resourceResgistrations .size () + " notification: "
262
+ logger .info ("Registered resources" + resourceRegistrations .size () + " notification: "
265
263
+ serverProperties .isResourceChangeNotification ());
266
264
}
267
265
268
- List <AsyncPromptRegistration > promptResgistrations = prompts .stream ().flatMap (List ::stream ).toList ();
269
- if (!CollectionUtils .isEmpty (promptResgistrations )) {
270
- serverBilder .prompts (promptResgistrations );
266
+ List <AsyncPromptRegistration > promptRegistrations = prompts .stream ().flatMap (List ::stream ).toList ();
267
+ if (!CollectionUtils .isEmpty (promptRegistrations )) {
268
+ serverBuilder .prompts (promptRegistrations );
271
269
capabilitiesBuilder .prompts (serverProperties .isPromptChangeNotification ());
272
- logger .info ("Registered prompts" + promptResgistrations .size () + " notification: "
270
+ logger .info ("Registered prompts" + promptRegistrations .size () + " notification: "
273
271
+ serverProperties .isPromptChangeNotification ());
274
272
}
275
273
@@ -278,13 +276,13 @@ public McpAsyncServer mcpAsyncServer(ServerMcpTransport transport,
278
276
consumer .accept (roots );
279
277
return Mono .empty ();
280
278
};
281
- serverBilder .rootsChangeConsumer (asyncConsumer );
279
+ serverBuilder .rootsChangeConsumer (asyncConsumer );
282
280
logger .info ("Registered roots change consumer" );
283
281
});
284
282
285
- serverBilder .capabilities (capabilitiesBuilder .build ());
283
+ serverBuilder .capabilities (capabilitiesBuilder .build ());
286
284
287
- return serverBilder .build ();
285
+ return serverBuilder .build ();
288
286
}
289
287
290
288
}
0 commit comments