@@ -175,7 +175,7 @@ class AsyncSpecification {
175175 * Each tool is uniquely identified by a name and includes metadata describing its
176176 * schema.
177177 */
178- private final List <McpServerFeatures .AsyncToolSpecification > tools = new ArrayList <>();
178+ private final List <McpServerFeatures .AsyncToolCallSpecification > tools = new ArrayList <>();
179179
180180 /**
181181 * The Model Context Protocol (MCP) provides a standardized way for servers to
@@ -321,13 +321,40 @@ public AsyncSpecification capabilities(McpSchema.ServerCapabilities serverCapabi
321321 * map of arguments passed to the tool.
322322 * @return This builder instance for method chaining
323323 * @throws IllegalArgumentException if tool or handler is null
324+ * @deprecated Use {@link #toolCall(McpSchema.Tool, BiFunction)} instead for tool
325+ * calls that require a request object.
324326 */
327+ @ Deprecated
325328 public AsyncSpecification tool (McpSchema .Tool tool ,
326329 BiFunction <McpAsyncServerExchange , Map <String , Object >, Mono <CallToolResult >> handler ) {
327330 Assert .notNull (tool , "Tool must not be null" );
328331 Assert .notNull (handler , "Handler must not be null" );
329332
330- this .tools .add (new McpServerFeatures .AsyncToolSpecification (tool , handler ));
333+ this .tools .add (new McpServerFeatures .AsyncToolSpecification (tool , handler ).toToolCall ());
334+
335+ return this ;
336+ }
337+
338+ /**
339+ * Adds a single tool with its implementation handler to the server. This is a
340+ * convenience method for registering individual tools without creating a
341+ * {@link McpServerFeatures.AsyncToolCallSpecification} explicitly.
342+ * @param tool The tool definition including name, description, and schema. Must
343+ * not be null.
344+ * @param handler The function that implements the tool's logic. Must not be null.
345+ * The function's first argument is an {@link McpAsyncServerExchange} upon which
346+ * the server can interact with the connected client. The second argument is the
347+ * {@link McpSchema.CallToolRequest} object containing the tool call
348+ * @return This builder instance for method chaining
349+ * @throws IllegalArgumentException if tool or handler is null
350+ */
351+ public AsyncSpecification toolCall (McpSchema .Tool tool ,
352+ BiFunction <McpAsyncServerExchange , McpSchema .CallToolRequest , Mono <CallToolResult >> handler ) {
353+
354+ Assert .notNull (tool , "Tool must not be null" );
355+ Assert .notNull (handler , "Handler must not be null" );
356+
357+ this .tools .add (new McpServerFeatures .AsyncToolCallSpecification (tool , handler ));
331358
332359 return this ;
333360 }
@@ -341,10 +368,29 @@ public AsyncSpecification tool(McpSchema.Tool tool,
341368 * @return This builder instance for method chaining
342369 * @throws IllegalArgumentException if toolSpecifications is null
343370 * @see #tools(McpServerFeatures.AsyncToolSpecification...)
371+ * @deprecated Use {@link #toolCalls(List)} instead for adding multiple tool
372+ * calls.
344373 */
374+ @ Deprecated
345375 public AsyncSpecification tools (List <McpServerFeatures .AsyncToolSpecification > toolSpecifications ) {
346376 Assert .notNull (toolSpecifications , "Tool handlers list must not be null" );
347- this .tools .addAll (toolSpecifications );
377+ this .tools .addAll (toolSpecifications .stream ().map (s -> s .toToolCall ()).toList ());
378+ return this ;
379+ }
380+
381+ /**
382+ * Adds multiple tools with their handlers to the server using a List. This method
383+ * is useful when tools are dynamically generated or loaded from a configuration
384+ * source.
385+ * @param toolCallSpecifications The list of tool specifications to add. Must not
386+ * be null.
387+ * @return This builder instance for method chaining
388+ * @throws IllegalArgumentException if toolSpecifications is null
389+ * @see #tools(McpServerFeatures.AsyncToolCallSpecification...)
390+ */
391+ public AsyncSpecification toolCalls (List <McpServerFeatures .AsyncToolCallSpecification > toolCallSpecifications ) {
392+ Assert .notNull (toolCallSpecifications , "Tool handlers list must not be null" );
393+ this .tools .addAll (toolCallSpecifications );
348394 return this ;
349395 }
350396
@@ -363,11 +409,28 @@ public AsyncSpecification tools(List<McpServerFeatures.AsyncToolSpecification> t
363409 * @param toolSpecifications The tool specifications to add. Must not be null.
364410 * @return This builder instance for method chaining
365411 * @throws IllegalArgumentException if toolSpecifications is null
366- * @see #tools(List)
412+ * @deprecated Use
413+ * {@link #toolCalls(McpServerFeatures.AsyncToolCallSpecification...)} instead
367414 */
415+ @ Deprecated
368416 public AsyncSpecification tools (McpServerFeatures .AsyncToolSpecification ... toolSpecifications ) {
369417 Assert .notNull (toolSpecifications , "Tool handlers list must not be null" );
370418 for (McpServerFeatures .AsyncToolSpecification tool : toolSpecifications ) {
419+ this .tools .add (tool .toToolCall ());
420+ }
421+ return this ;
422+ }
423+
424+ /**
425+ * Adds multiple tools with their handlers to the server using varargs. This
426+ * method provides a convenient way to register multiple tools inline.
427+ * @param toolSpecifications The tool specifications to add. Must not be null.
428+ * @return This builder instance for method chaining
429+ * @throws IllegalArgumentException if toolSpecifications is null
430+ */
431+ public AsyncSpecification toolCalls (McpServerFeatures .AsyncToolCallSpecification ... toolCallSpecifications ) {
432+ Assert .notNull (toolCallSpecifications , "Tool handlers list must not be null" );
433+ for (McpServerFeatures .AsyncToolCallSpecification tool : toolCallSpecifications ) {
371434 this .tools .add (tool );
372435 }
373436 return this ;
@@ -667,7 +730,7 @@ class SyncSpecification {
667730 * Each tool is uniquely identified by a name and includes metadata describing its
668731 * schema.
669732 */
670- private final List <McpServerFeatures .SyncToolSpecification > tools = new ArrayList <>();
733+ private final List <McpServerFeatures .SyncToolCallSpecification > tools = new ArrayList <>();
671734
672735 /**
673736 * The Model Context Protocol (MCP) provides a standardized way for servers to
@@ -812,13 +875,39 @@ public SyncSpecification capabilities(McpSchema.ServerCapabilities serverCapabil
812875 * list of arguments passed to the tool.
813876 * @return This builder instance for method chaining
814877 * @throws IllegalArgumentException if tool or handler is null
878+ * @deprecated Use {@link #toolCall(McpSchema.Tool, BiFunction)} instead for tool
879+ * calls that require a request object.
815880 */
881+ @ Deprecated
816882 public SyncSpecification tool (McpSchema .Tool tool ,
817883 BiFunction <McpSyncServerExchange , Map <String , Object >, McpSchema .CallToolResult > handler ) {
818884 Assert .notNull (tool , "Tool must not be null" );
819885 Assert .notNull (handler , "Handler must not be null" );
820886
821- this .tools .add (new McpServerFeatures .SyncToolSpecification (tool , handler ));
887+ this .tools .add (new McpServerFeatures .SyncToolSpecification (tool , handler ).toToolCall ());
888+
889+ return this ;
890+ }
891+
892+ /**
893+ * Adds a single tool with its implementation handler to the server. This is a
894+ * convenience method for registering individual tools without creating a
895+ * {@link McpServerFeatures.SyncToolSpecification} explicitly.
896+ * @param tool The tool definition including name, description, and schema. Must
897+ * not be null.
898+ * @param handler The function that implements the tool's logic. Must not be null.
899+ * The function's first argument is an {@link McpSyncServerExchange} upon which
900+ * the server can interact with the connected client. The second argument is the
901+ * list of arguments passed to the tool.
902+ * @return This builder instance for method chaining
903+ * @throws IllegalArgumentException if tool or handler is null
904+ */
905+ public SyncSpecification toolCall (McpSchema .Tool tool ,
906+ BiFunction <McpSyncServerExchange , McpSchema .CallToolRequest , McpSchema .CallToolResult > handler ) {
907+ Assert .notNull (tool , "Tool must not be null" );
908+ Assert .notNull (handler , "Handler must not be null" );
909+
910+ this .tools .add (new McpServerFeatures .SyncToolCallSpecification (tool , handler ));
822911
823912 return this ;
824913 }
@@ -832,10 +921,28 @@ public SyncSpecification tool(McpSchema.Tool tool,
832921 * @return This builder instance for method chaining
833922 * @throws IllegalArgumentException if toolSpecifications is null
834923 * @see #tools(McpServerFeatures.SyncToolSpecification...)
924+ * @deprecated Use {@link #toolCalls(List)} instead for adding multiple tool
925+ * calls.
835926 */
927+ @ Deprecated
836928 public SyncSpecification tools (List <McpServerFeatures .SyncToolSpecification > toolSpecifications ) {
837929 Assert .notNull (toolSpecifications , "Tool handlers list must not be null" );
838- this .tools .addAll (toolSpecifications );
930+ this .tools .addAll (toolSpecifications .stream ().map (s -> s .toToolCall ()).toList ());
931+ return this ;
932+ }
933+
934+ /**
935+ * Adds multiple tools with their handlers to the server using a List. This method
936+ * is useful when tools are dynamically generated or loaded from a configuration
937+ * source.
938+ * @param toolSpecifications The list of tool specifications to add. Must not be
939+ * null.
940+ * @return This builder instance for method chaining
941+ * @throws IllegalArgumentException if toolSpecifications is null
942+ */
943+ public SyncSpecification toolCalls (List <McpServerFeatures .SyncToolCallSpecification > toolCallSpecifications ) {
944+ Assert .notNull (toolCallSpecifications , "Tool handlers list must not be null" );
945+ this .tools .addAll (toolCallSpecifications );
839946 return this ;
840947 }
841948
@@ -855,10 +962,30 @@ public SyncSpecification tools(List<McpServerFeatures.SyncToolSpecification> too
855962 * @return This builder instance for method chaining
856963 * @throws IllegalArgumentException if toolSpecifications is null
857964 * @see #tools(List)
965+ * @deprecated Use
966+ * {@link #toolCalls(McpServerFeatures.SyncToolCallSpecification...)} instead for
967+ * tool calls that require a request object.
858968 */
969+ @ Deprecated
859970 public SyncSpecification tools (McpServerFeatures .SyncToolSpecification ... toolSpecifications ) {
860971 Assert .notNull (toolSpecifications , "Tool handlers list must not be null" );
861972 for (McpServerFeatures .SyncToolSpecification tool : toolSpecifications ) {
973+ this .tools .add (tool .toToolCall ());
974+ }
975+ return this ;
976+ }
977+
978+ /**
979+ * Adds multiple tools with their handlers to the server using varargs. This
980+ * method provides a convenient way to register multiple tools inline.
981+ * @param toolSpecifications The tool specifications to add. Must not be null.
982+ * @return This builder instance for method chaining
983+ * @throws IllegalArgumentException if toolSpecifications is null
984+ * @see #tools(List)
985+ */
986+ public SyncSpecification toolCalls (McpServerFeatures .SyncToolCallSpecification ... toolCallSpecifications ) {
987+ Assert .notNull (toolCallSpecifications , "Tool handlers list must not be null" );
988+ for (McpServerFeatures .SyncToolCallSpecification tool : toolCallSpecifications ) {
862989 this .tools .add (tool );
863990 }
864991 return this ;
0 commit comments