[
https://issues.apache.org/jira/browse/CAMEL-23958?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Claus Ibsen resolved CAMEL-23958.
---------------------------------
Resolution: Fixed
> camel-openai: duplicate MCP tool names from multiple servers are all sent to
> the model
> --------------------------------------------------------------------------------------
>
> Key: CAMEL-23958
> URL: https://issues.apache.org/jira/browse/CAMEL-23958
> Project: Camel
> Issue Type: Bug
> Components: camel-openai
> Affects Versions: 4.21.0
> Reporter: Federico Mariani
> Assignee: Claus Ibsen
> Priority: Minor
> Labels: ai
> Fix For: 4.22.0
>
>
> When two configured MCP servers expose a tool with the same name,
> {{OpenAIEndpoint.initializeMcpServers}} deduplicates the *dispatch* map but
> not the *advertised* tool list:
> {code:java}
> cachedMcpTools.addAll(McpToolConverter.convert(tools)); // adds ALL tools,
> duplicates included
> for (McpSchema.Tool tool : tools) {
> if (toolClientMap.putIfAbsent(tool.name(), mcpClient) != null) {
> LOG.warn("Duplicate MCP tool name '{}' from server '{}', using first
> registered", ...);
> }
> ...
> }
> {code}
> Consequences:
> * the chat completion request contains two {{function}} tools with the same
> name (the OpenAI API rejects duplicate function names; OpenAI-compatible
> servers behave unpredictably);
> * even where the request is accepted, the model may generate arguments
> against the *second* server's schema, but dispatch by name routes the call to
> the *first* server — a silent cross-server misdispatch.
> The same defect exists in {{reconnectMcpServer}}, which re-adds all re-listed
> tools without checking for names owned by other servers.
> h3. Suggested fix
> Only add a converted tool to {{cachedMcpTools}} when its name won the
> {{putIfAbsent}} registration (and mirror that in the reconnect path), keeping
> the existing WARN. A follow-up option for explicit disambiguation/filtering
> is proposed separately (MCP tool filtering).
> _This issue was drafted by Claude Code on behalf of Federico Mariani_
--
This message was sent by Atlassian Jira
(v8.20.10#820010)