-
Notifications
You must be signed in to change notification settings - Fork 2.1k
refactor: Improve MCP tool name prefix generation with automatic duplicate handling #4369
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
refactor: Improve MCP tool name prefix generation with automatic duplicate handling #4369
Conversation
…icate handling - Introduce DefaultMcpToolNamePrefixGenerator to ensure unique tool names across MCP connections - Replace default prefix generation strategy from client/title-based to duplicate detection - Automatically add counter prefixes (dp_1_, dp_2_) when duplicate tool names are detected - Track existing connections and tool names to maintain idempotency - Update tests to reflect new duplicate handling behavior (keep existing tool on duplicate) - Update documentation to describe the new default generator behavior - Change default from McpToolNamePrefixGenerator.defaultGenerator() to new DefaultMcpToolNamePrefixGenerator BREAKING CHANGE: The default tool name generation strategy has changed. Tools now use their original names by default, with automatic prefixing only when duplicates are detected across different connections. Signed-off-by: Christian Tzolov <[email protected]>
| return (mcpConnectionIfo, tool) -> McpToolUtils.prefixedToolName(mcpConnectionIfo.clientInfo().name(), | ||
| mcpConnectionIfo.clientInfo().title(), tool.name()); | ||
| } | ||
| // static McpToolNamePrefixGenerator defaultGenerator() { |
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.
will remove when merging.
| .add(new ConnectionId(mcpConnectionInfo.clientInfo(), (mcpConnectionInfo.initializeResult() != null) | ||
| ? mcpConnectionInfo.initializeResult().serverInfo() : null, tool))) { | ||
| if (!this.allUsedToolNames.add(uniqueToolName)) { | ||
| uniqueToolName = "dp_" + this.counter.getAndIncrement() + "_" + uniqueToolName; |
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.
While one can provide a custom prefix generator, It would be good if we can make the prefix "dp_" customisable.
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.
perhaps "sa" to denote "Spring AI" as a prefix here instead of "dp_"?
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.
After discussion, changing this to use "alt_" when merging.
|
Rebased, updated the prefix for the duplicate tool name to use "alt_", merged as 31db86d |
BREAKING CHANGE: The default tool name generation strategy has changed. Tools now use their original names by default, with automatic prefixing only when duplicates are detected across different connections.