From d8c5c31e611532e36228da0c0e77db5bc86c8ea3 Mon Sep 17 00:00:00 2001 From: SuYao Date: Fri, 25 Jul 2025 00:14:09 +0800 Subject: [PATCH] fix(mcp-tools): enhance tool lookup logic to support partial matches (#8473) * fix(mcp-tools): enhance tool lookup logic to support partial matches - Updated the tool lookup logic in `geminiFunctionCallToMcpTool` to include partial matches for both tool IDs and names, improving the flexibility of tool identification. * refactor(mcp-tools): simplify tool lookup logic for improved clarity - Refactored the tool lookup logic in `geminiFunctionCallToMcpTool` to streamline the identification process by consolidating checks for tool IDs and names into a single variable. This enhances readability and maintains functionality for partial matches. --- src/renderer/src/utils/mcp-tools.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/renderer/src/utils/mcp-tools.ts b/src/renderer/src/utils/mcp-tools.ts index ca3e355768..e575917f7a 100644 --- a/src/renderer/src/utils/mcp-tools.ts +++ b/src/renderer/src/utils/mcp-tools.ts @@ -417,10 +417,12 @@ export function geminiFunctionCallToMcpTool( ): MCPTool | undefined { if (!toolCall) return undefined if (!mcpTools) return undefined - const tool = mcpTools.find((tool) => tool.id === toolCall.name || tool.name === toolCall.name) - if (!tool) { - return undefined - } + + const toolName = toolCall.name || toolCall.id + if (!toolName) return undefined + + const tool = mcpTools.find((tool) => tool.id.includes(toolName) || tool.name.includes(toolName)) + return tool }