-
Notifications
You must be signed in to change notification settings - Fork 530
refactor: deprecate tool spec's arguments-only handler in favor of CallToolRequest #375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your efforts!
* @param call Deprecated. Uset he {@link AsyncToolCallSpecification#callTool} | ||
* instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT:
handler
or toolHandler
can be used for instead of callTool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are already using the handler
as the parameter's name in McpServer
builder.
@Test | ||
void testRemoveTool() { | ||
Tool too = new McpSchema.Tool(TEST_TOOL_NAME, "Duplicate tool", emptyJsonSchema); | ||
|
||
var mcpAsyncServer = McpServer.async(createMcpTransportProvider()) | ||
.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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @deprecated Use {@link #AsyncToolSpecification(McpSchema.Tool, null, | |
* BiFunction)} instead. | |
* @deprecated Use {@link AsyncToolSpecification(McpSchema.Tool, null, | |
* BiFunction)} instead. |
* }</pre> | ||
* | ||
* @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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* {@link McpServerFeatures.AsyncToolCallSpecification} explicitly. | |
* {@link McpServerFeatures.AsyncToolSpecification} explicitly. |
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
CallToolRequest
object, 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()