Skip to content

feat: refactor the tool specifications #351

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

Closed
wants to merge 3 commits into from
Closed

Conversation

tzolov
Copy link
Contributor

@tzolov tzolov commented Jun 29, 2025

  • Deprecate AsyncToolSpecification in favor of AsyncToolCallSpecification
  • Deprecate SyncToolSpecification in favor of SyncToolCallSpecification
  • Tool handlers now receive CallToolRequest instead of raw arguments to enable access to additional metadata parameters like progressToken
  • Add toolCall() and toolCalls() builder methods alongside deprecated variants
  • Update addTool() methods to support new tool call specifications
  • Maintain backward compatibility through deprecation annotations
  • Add tests for new tool call functionality

Motivation and Context

This change allows tool handlers to process additional metadata parameters from the full CallToolRequest object, enabling features like progress tracking.

Related to #300

How Has This Been Tested?

Additional tests to AbstractMcpAsyncClientTests and AbstractMcpSyncClientTests

Breaking Changes

AsyncToolCallSpecification/SyncToolCallSpecification replace the deprecated AsyncToolSpecification/SyncToolSpecification.
The old specifications are maintained for backward compatibility during transition. Internally, the deprecated specifications are converted to the new format, but only arguments remain visible to CallToolRequest.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change but backward compatibility is provided
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

- Deprecate AsyncToolSpecification in favor of AsyncToolCallSpecification
- Deprecate SyncToolSpecification in favor of SyncToolCallSpecification
- Tool handlers now receive CallToolRequest instead of raw arguments to
  enable access to additional metadata parameters like progressToken
- Add toolCall() and toolCalls() builder methods alongside deprecated variants
- Update addTool() methods to support new tool call specifications
- Maintain backward compatibility through deprecation annotations
- Add tests for new tool call functionality

This change allows tool handlers to process additional metadata parameters
from the full CallToolRequest object, enabling features like progress tracking.

Signed-off-by: Christian Tzolov <[email protected]>
Copy link

@134130 134130 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

Comment on lines 391 to 395
public AsyncSpecification toolCalls(List<McpServerFeatures.AsyncToolCallSpecification> toolCallSpecifications) {
Assert.notNull(toolCallSpecifications, "Tool handlers list must not be null");
this.tools.addAll(toolCallSpecifications);
return this;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hadn't considered until reviewing this just now, but this should probably do some minimal validation for things like duplicate tool names. Unsure if that's already planned as a more comprehensive backlog thing or if we should do this now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @LucaButBoring , while we had some duplication validation for the runtime tool addition we lacked such for the initial tool registration.
I've updated the PR to add duplication validation.

- Add AssertNotDupplicateTool validation method to prevent duplicate tool registration
- Throw IllegalArgumentException during server building when duplicate tool names detected
- Throw McpError when attempting to add duplicate tools to existing server
- Add test coverage for duplicate detection scenarios:
  - Individual tool registration during building
  - Batch tool registration (list and varargs)
  - Runtime duplicate tool addition
- Apply validation to both sync and async server implementations

This prevents tool name conflicts that could cause unexpected behavior
or runtime errors in MCP server implementations.

Signed-off-by: Christian Tzolov <[email protected]>
@@ -208,6 +208,12 @@ private AsyncSpecification(McpServerTransportProvider transportProvider) {
this.transportProvider = transportProvider;
}

private void AssertNotDupplicateTool(String toolName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: method name -> assertNotDuplicateTool

Signed-off-by: Christian Tzolov <[email protected]>
@tzolov
Copy link
Contributor Author

tzolov commented Jul 5, 2025

Replaced by #375

@134130 , @LucaButBoring , @chemicL I've re-designed the the approach.
Instead of introducing an additional AsyncToolCallSpecification and SyncToolCallSpecification records I'm reusing the existing AsyncToolSpecification and SyncToolSpecification by adding an additional callTool : CallToolRequest field and deprecating the old call : Map<String, Object> one. Also fixed some minor bugs and improved the test coverage.
Will appreciate your thoughts on the #375

@tzolov tzolov closed this Jul 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants