refactor: deprecate tool spec's arguments-only handler in favor of CallToolRequest#375
refactor: deprecate tool spec's arguments-only handler in favor of CallToolRequest#375
Conversation
…llToolRequest Tool handlers now receive CallToolRequest instead of raw arguments to enable access to additional metadata parameters like progressToken - Deprecate handlers that take only Map<String, Object> arguments - Introduce new handlers that receive the full CallToolRequest object - Maintain backward compatibility with deprecated call handlers - Enhance API to provide access to complete tool request context beyond just arguments - Add builder pattern for AsyncToolSpecification and SyncToolSpecification - Add duplicate tool name validation during server building and runtime registration - Update all test files to use new callTool handlers and builder pattern - Add test coverage for new builder functionality and CallToolRequest handling Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
134130
left a comment
There was a problem hiding this comment.
Thank you for your efforts!
| * @param call Deprecated. Uset he {@link AsyncToolCallSpecification#callTool} | ||
| * instead. |
There was a problem hiding this comment.
| * @param call Deprecated. Uset he {@link AsyncToolCallSpecification#callTool} | |
| * instead. | |
| * @param call Deprecated. Use the {@link AsyncToolSpecification#callTool} | |
| * instead. |
| @Deprecated BiFunction<McpAsyncServerExchange, Map<String, Object>, Mono<McpSchema.CallToolResult>> call, | ||
| BiFunction<McpAsyncServerExchange, McpSchema.CallToolRequest, Mono<McpSchema.CallToolResult>> callTool) { |
There was a problem hiding this comment.
NIT:
handler or toolHandler can be used for instead of callTool
There was a problem hiding this comment.
We are already using the handler as the parameter's name in McpServer builder.
There was a problem hiding this comment.
Good point. toolHandler will be consistent with the other spec handler fields: readHandler, promptHandler, completionHandler ..
There was a problem hiding this comment.
Isn't callHandler a more appropriate name?
There was a problem hiding this comment.
Exactly. callHandler or callTollHandler. whatever!
| .serverInfo("test-server", "1.0.0") | ||
| .capabilities(ServerCapabilities.builder().tools(true).build()) | ||
| .tool(too, (exchange, args) -> Mono.just(new CallToolResult(List.of(), false))) | ||
| .toolCall(too, (exchange, args) -> Mono.just(new CallToolResult(List.of(), false))) |
There was a problem hiding this comment.
NIT:
| .toolCall(too, (exchange, args) -> Mono.just(new CallToolResult(List.of(), false))) | |
| .toolCall(too, (exchange, request) -> Mono.just(new CallToolResult(List.of(), false))) |
| * @deprecated Use {@link #AsyncToolSpecification(McpSchema.Tool, null, | ||
| * BiFunction)} instead. |
There was a problem hiding this comment.
| * @deprecated Use {@link #AsyncToolSpecification(McpSchema.Tool, null, | |
| * BiFunction)} instead. | |
| * @deprecated Use {@link AsyncToolSpecification(McpSchema.Tool, null, | |
| * BiFunction)} instead. |
| * @param tool The tool definition including name, description, and parameter schema | ||
| * @param call The function that implements the tool's logic, receiving arguments and | ||
| * returning results. The function's first argument is an | ||
| * @param (deprecated) call The function that implements the tool's logic, receiving |
There was a problem hiding this comment.
| * @param (deprecated) call The function that implements the tool's logic, receiving | |
| * @param call Deprecated. The function that implements the tool's logic, receiving |
| /** | ||
| * Adds a single tool with its implementation handler to the server. This is a | ||
| * convenience method for registering individual tools without creating a | ||
| * {@link McpServerFeatures.AsyncToolCallSpecification} explicitly. |
There was a problem hiding this comment.
| * {@link McpServerFeatures.AsyncToolCallSpecification} explicitly. | |
| * {@link McpServerFeatures.AsyncToolSpecification} explicitly. |
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
…llToolRequest (#375) Tool handlers now receive CallToolRequest instead of raw arguments to enable access to additional metadata parameters like progressToken - Deprecate handlers that take only Map<String, Object> arguments - Introduce new handlers that receive the full CallToolRequest object - Maintain backward compatibility with deprecated call handlers - Enhance API to provide access to complete tool request context beyond just arguments - Add builder pattern for AsyncToolSpecification and SyncToolSpecification - Add duplicate tool name validation during server building and runtime registration - Update all test files to use new callTool handlers and builder pattern - Add test coverage for new builder functionality and CallToolRequest handling Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
|
rebased, squashed and merged at 901175e |
|
Now it's my turn! |
…redOutputCallToolHandler Follow up to #357 to update tool call handler signature from Map<String, Object> to McpSchema.CallToolRequest for consistency with changes in #375. - Change BiFunction parameter from Map<String, Object> to McpSchema.CallToolRequest for better type safety - Update method signature to accept CallToolRequest instead of raw arguments map - Replace toolSpecification.call() with toolSpecification.callHandler() - Migrate to builder pattern for AsyncToolSpecification construction Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
…redOutputCallToolHandler Follow up to #357 to update tool call handler signature from Map<String, Object> to McpSchema.CallToolRequest for consistency with changes in #375. - Change BiFunction parameter from Map<String, Object> to McpSchema.CallToolRequest for better type safety - Update method signature to accept CallToolRequest instead of raw arguments map - Replace toolSpecification.call() with toolSpecification.callHandler() - Migrate to builder pattern for AsyncToolSpecification construction Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Refactor tool specifications to use builder pattern and deprecate arguments-only handlers in favor of CallToolRequest
Related to #300
Motivation and Context
The current tool handler API only provides access to the arguments Map, limiting handlers to just the parameter values. This change introduces handlers that receive the full
CallToolRequestobject, giving access to the complete request context including tool name and arguments together. Additionally, the builder pattern improves API ergonomics and enables better validation during tool registration.Key improvements:
How Has This Been Tested?
Breaking Changes
None - This change is fully backward compatible. Existing code using the deprecated constructors and
tool()methods will continue to work unchanged. Users can migrate to the new API at their own pace.Types of changes
Checklist
Additional context
Migration Path:
Old API:
new McpServerFeatures.SyncToolSpecification(toolDef, (exchange, args) -> ...)New API:
McpServerFeatures.SyncToolSpecification.builder().tool(toolDef).callTool((exchange, callToolReq) -> ...)).build()Old API:
new McpServerFeatures.AsyncToolSpecification(toolDef, (exchange, args) -> ...)New API:
McpServerFeatures.AsyncToolSpecification.builder().tool(toolDef).callTool((exchange, callToolReq) -> ...)).build()