@@ -149,11 +149,11 @@ private List<McpServerFeatures.SyncToolSpecification> toSyncToolSpecifications(L
149
149
150
150
// De-duplicate tools by their name, keeping the first occurrence of each tool
151
151
// name
152
- return tools .stream ()
153
- .collect (Collectors .toMap (tool -> tool .getToolDefinition ().name (), // Key :
154
- // tool
155
- // name
156
- tool -> tool , // Value: the tool itself
152
+ return tools .stream () // Key: tool name
153
+ .collect (Collectors .toMap (tool -> tool .getToolDefinition ().name (), tool -> tool , // Value :
154
+ // the
155
+ // tool
156
+ // itself
157
157
(existing , replacement ) -> existing )) // On duplicate key, keep the
158
158
// existing tool
159
159
.values ()
@@ -185,47 +185,66 @@ public McpSyncServer mcpSyncServer(McpServerTransportProvider transportProvider,
185
185
// Create the server with both tool and resource capabilities
186
186
SyncSpecification serverBuilder = McpServer .sync (transportProvider ).serverInfo (serverInfo );
187
187
188
- List <SyncToolSpecification > toolSpecifications = new ArrayList <>(tools .stream ().flatMap (List ::stream ).toList ());
188
+ // Tools
189
+ if (serverProperties .getCapabilities ().isTool ()) {
190
+ logger .info ("Enable tools capabilities, notification: " + serverProperties .isToolChangeNotification ());
191
+ capabilitiesBuilder .tools (serverProperties .isToolChangeNotification ());
189
192
190
- List <ToolCallback > providerToolCallbacks = toolCallbackProvider .stream ()
191
- .map (pr -> List .of (pr .getToolCallbacks ()))
192
- .flatMap (List ::stream )
193
- .filter (fc -> fc instanceof ToolCallback )
194
- .map (fc -> (ToolCallback ) fc )
195
- .toList ();
193
+ List <SyncToolSpecification > toolSpecifications = new ArrayList <>(
194
+ tools .stream ().flatMap (List ::stream ).toList ());
196
195
197
- toolSpecifications .addAll (this .toSyncToolSpecifications (providerToolCallbacks , serverProperties ));
196
+ List <ToolCallback > providerToolCallbacks = toolCallbackProvider .stream ()
197
+ .map (pr -> List .of (pr .getToolCallbacks ()))
198
+ .flatMap (List ::stream )
199
+ .filter (fc -> fc instanceof ToolCallback )
200
+ .map (fc -> (ToolCallback ) fc )
201
+ .toList ();
198
202
199
- if (!CollectionUtils .isEmpty (toolSpecifications )) {
200
- serverBuilder .tools (toolSpecifications );
201
- capabilitiesBuilder .tools (serverProperties .isToolChangeNotification ());
202
- logger .info ("Registered tools: " + toolSpecifications .size () + ", notification: "
203
- + serverProperties .isToolChangeNotification ());
203
+ toolSpecifications .addAll (this .toSyncToolSpecifications (providerToolCallbacks , serverProperties ));
204
+
205
+ if (!CollectionUtils .isEmpty (toolSpecifications )) {
206
+ serverBuilder .tools (toolSpecifications );
207
+ logger .info ("Registered tools: " + toolSpecifications .size ());
208
+ }
204
209
}
205
210
206
- List <SyncResourceSpecification > resourceSpecifications = resources .stream ().flatMap (List ::stream ).toList ();
207
- if (!CollectionUtils .isEmpty (resourceSpecifications )) {
208
- serverBuilder .resources (resourceSpecifications );
211
+ // Resources
212
+ if (serverProperties .getCapabilities ().isResource ()) {
213
+ logger .info (
214
+ "Enable resources capabilities, notification: " + serverProperties .isResourceChangeNotification ());
209
215
capabilitiesBuilder .resources (false , serverProperties .isResourceChangeNotification ());
210
- logger .info ("Registered resources: " + resourceSpecifications .size () + ", notification: "
211
- + serverProperties .isResourceChangeNotification ());
216
+
217
+ List <SyncResourceSpecification > resourceSpecifications = resources .stream ().flatMap (List ::stream ).toList ();
218
+ if (!CollectionUtils .isEmpty (resourceSpecifications )) {
219
+ serverBuilder .resources (resourceSpecifications );
220
+ logger .info ("Registered resources: " + resourceSpecifications .size ());
221
+ }
212
222
}
213
223
214
- List < SyncPromptSpecification > promptSpecifications = prompts . stream (). flatMap ( List :: stream ). toList ();
215
- if (! CollectionUtils . isEmpty ( promptSpecifications )) {
216
- serverBuilder . prompts ( promptSpecifications );
224
+ // Prompts
225
+ if (serverProperties . getCapabilities (). isPrompt ( )) {
226
+ logger . info ( "Enable prompts capabilities, notification: " + serverProperties . isPromptChangeNotification () );
217
227
capabilitiesBuilder .prompts (serverProperties .isPromptChangeNotification ());
218
- logger .info ("Registered prompts: " + promptSpecifications .size () + ", notification: "
219
- + serverProperties .isPromptChangeNotification ());
228
+
229
+ List <SyncPromptSpecification > promptSpecifications = prompts .stream ().flatMap (List ::stream ).toList ();
230
+ if (!CollectionUtils .isEmpty (promptSpecifications )) {
231
+ serverBuilder .prompts (promptSpecifications );
232
+ logger .info ("Registered prompts: " + promptSpecifications .size ());
233
+ }
220
234
}
221
235
222
- List <SyncCompletionSpecification > completionSpecifications = completions .stream ()
223
- .flatMap (List ::stream )
224
- .toList ();
225
- if (!CollectionUtils .isEmpty (completionSpecifications )) {
226
- serverBuilder .completions (completionSpecifications );
236
+ // Completions
237
+ if (serverProperties .getCapabilities ().isCompletion ()) {
238
+ logger .info ("Enable completions capabilities" );
227
239
capabilitiesBuilder .completions ();
228
- logger .info ("Registered completions: " + completionSpecifications .size ());
240
+
241
+ List <SyncCompletionSpecification > completionSpecifications = completions .stream ()
242
+ .flatMap (List ::stream )
243
+ .toList ();
244
+ if (!CollectionUtils .isEmpty (completionSpecifications )) {
245
+ serverBuilder .completions (completionSpecifications );
246
+ logger .info ("Registered completions: " + completionSpecifications .size ());
247
+ }
229
248
}
230
249
231
250
rootsChangeConsumers .ifAvailable (consumer -> {
@@ -257,11 +276,11 @@ private List<McpServerFeatures.AsyncToolSpecification> toAsyncToolSpecification(
257
276
McpServerProperties serverProperties ) {
258
277
// De-duplicate tools by their name, keeping the first occurrence of each tool
259
278
// name
260
- return tools .stream ()
261
- .collect (Collectors .toMap (tool -> tool .getToolDefinition ().name (), // Key :
262
- // tool
263
- // name
264
- tool -> tool , // Value: the tool itself
279
+ return tools .stream () // Key: tool name
280
+ .collect (Collectors .toMap (tool -> tool .getToolDefinition ().name (), tool -> tool , // Value :
281
+ // the
282
+ // tool
283
+ // itself
265
284
(existing , replacement ) -> existing )) // On duplicate key, keep the
266
285
// existing tool
267
286
.values ()
@@ -303,35 +322,51 @@ public McpAsyncServer mcpAsyncServer(McpServerTransportProvider transportProvide
303
322
304
323
toolSpecifications .addAll (this .toAsyncToolSpecification (providerToolCallbacks , serverProperties ));
305
324
325
+ // Tools
326
+ if (serverProperties .getCapabilities ().isTool ()) {
327
+ logger .info ("Enable tools capabilities, notification: " + serverProperties .isToolChangeNotification ());
328
+ capabilitiesBuilder .tools (serverProperties .isToolChangeNotification ());
329
+ }
330
+
306
331
if (!CollectionUtils .isEmpty (toolSpecifications )) {
307
332
serverBuilder .tools (toolSpecifications );
308
- capabilitiesBuilder .tools (serverProperties .isToolChangeNotification ());
309
- logger .info ("Registered tools: " + toolSpecifications .size () + ", notification: "
310
- + serverProperties .isToolChangeNotification ());
333
+ logger .info ("Registered tools: " + toolSpecifications .size ());
334
+ }
335
+
336
+ // Resources
337
+ if (serverProperties .getCapabilities ().isResource ()) {
338
+ logger .info (
339
+ "Enable resources capabilities, notification: " + serverProperties .isResourceChangeNotification ());
340
+ capabilitiesBuilder .resources (false , serverProperties .isResourceChangeNotification ());
311
341
}
312
342
313
343
List <AsyncResourceSpecification > resourceSpecifications = resources .stream ().flatMap (List ::stream ).toList ();
314
344
if (!CollectionUtils .isEmpty (resourceSpecifications )) {
315
345
serverBuilder .resources (resourceSpecifications );
316
- capabilitiesBuilder .resources (false , serverProperties .isResourceChangeNotification ());
317
- logger .info ("Registered resources: " + resourceSpecifications .size () + ", notification: "
318
- + serverProperties .isResourceChangeNotification ());
346
+ logger .info ("Registered resources: " + resourceSpecifications .size ());
319
347
}
320
348
349
+ // Prompts
350
+ if (serverProperties .getCapabilities ().isPrompt ()) {
351
+ logger .info ("Enable prompts capabilities, notification: " + serverProperties .isPromptChangeNotification ());
352
+ capabilitiesBuilder .prompts (serverProperties .isPromptChangeNotification ());
353
+ }
321
354
List <AsyncPromptSpecification > promptSpecifications = prompts .stream ().flatMap (List ::stream ).toList ();
322
355
if (!CollectionUtils .isEmpty (promptSpecifications )) {
323
356
serverBuilder .prompts (promptSpecifications );
324
- capabilitiesBuilder .prompts (serverProperties .isPromptChangeNotification ());
325
- logger .info ("Registered prompts: " + promptSpecifications .size () + ", notification: "
326
- + serverProperties .isPromptChangeNotification ());
357
+ logger .info ("Registered prompts: " + promptSpecifications .size ());
327
358
}
328
359
360
+ // Completions
361
+ if (serverProperties .getCapabilities ().isCompletion ()) {
362
+ logger .info ("Enable completions capabilities" );
363
+ capabilitiesBuilder .completions ();
364
+ }
329
365
List <AsyncCompletionSpecification > completionSpecifications = completions .stream ()
330
366
.flatMap (List ::stream )
331
367
.toList ();
332
368
if (!CollectionUtils .isEmpty (completionSpecifications )) {
333
369
serverBuilder .completions (completionSpecifications );
334
- capabilitiesBuilder .completions ();
335
370
logger .info ("Registered completions: " + completionSpecifications .size ());
336
371
}
337
372
0 commit comments