From 766897e733369ca67e5b70844b2daa26bf369fde Mon Sep 17 00:00:00 2001 From: one Date: Fri, 27 Jun 2025 16:09:06 +0800 Subject: [PATCH] refactor: show error on missing mcp tool (#7587) --- src/renderer/src/i18n/locales/en-us.json | 3 ++- src/renderer/src/i18n/locales/ja-jp.json | 3 ++- src/renderer/src/i18n/locales/ru-ru.json | 3 ++- src/renderer/src/i18n/locales/zh-cn.json | 3 ++- src/renderer/src/i18n/locales/zh-tw.json | 3 ++- src/renderer/src/utils/mcp-tools.ts | 2 ++ 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/renderer/src/i18n/locales/en-us.json b/src/renderer/src/i18n/locales/en-us.json index b58056ae92..b36b931f25 100644 --- a/src/renderer/src/i18n/locales/en-us.json +++ b/src/renderer/src/i18n/locales/en-us.json @@ -1478,7 +1478,8 @@ "version": "Version" }, "errors": { - "32000": "MCP server failed to start, please check the parameters according to the tutorial" + "32000": "MCP server failed to start, please check the parameters according to the tutorial", + "toolNotFound": "Tool {{name}} not found" }, "serverPlural": "servers", "serverSingular": "server", diff --git a/src/renderer/src/i18n/locales/ja-jp.json b/src/renderer/src/i18n/locales/ja-jp.json index 64f6a98475..a43b02177c 100644 --- a/src/renderer/src/i18n/locales/ja-jp.json +++ b/src/renderer/src/i18n/locales/ja-jp.json @@ -1473,7 +1473,8 @@ "updateSuccess": "サーバーが正常に更新されました", "url": "URL", "errors": { - "32000": "MCP サーバーが起動しませんでした。パラメーターを確認してください" + "32000": "MCP サーバーが起動しませんでした。パラメーターを確認してください", + "toolNotFound": "ツール {{name}} が見つかりません" }, "editMcpJson": "MCP 設定を編集", "installHelp": "インストールヘルプを取得", diff --git a/src/renderer/src/i18n/locales/ru-ru.json b/src/renderer/src/i18n/locales/ru-ru.json index e027e7270d..3eea3431f4 100644 --- a/src/renderer/src/i18n/locales/ru-ru.json +++ b/src/renderer/src/i18n/locales/ru-ru.json @@ -1465,7 +1465,8 @@ "version": "Версия" }, "errors": { - "32000": "MCP сервер не запущен, пожалуйста, проверьте параметры" + "32000": "MCP сервер не запущен, пожалуйста, проверьте параметры", + "toolNotFound": "Инструмент {{name}} не найден" }, "serverPlural": "серверы", "serverSingular": "сервер", diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json index 894d53c2be..7bb2f25608 100644 --- a/src/renderer/src/i18n/locales/zh-cn.json +++ b/src/renderer/src/i18n/locales/zh-cn.json @@ -1478,7 +1478,8 @@ "version": "版本" }, "errors": { - "32000": "MCP 服务器启动失败,请根据教程检查参数是否填写完整" + "32000": "MCP 服务器启动失败,请根据教程检查参数是否填写完整", + "toolNotFound": "未找到工具 {{name}}" }, "serverPlural": "服务器", "serverSingular": "服务器", diff --git a/src/renderer/src/i18n/locales/zh-tw.json b/src/renderer/src/i18n/locales/zh-tw.json index 65a3a3f58c..949afc9639 100644 --- a/src/renderer/src/i18n/locales/zh-tw.json +++ b/src/renderer/src/i18n/locales/zh-tw.json @@ -1468,7 +1468,8 @@ "version": "版本" }, "errors": { - "32000": "MCP 伺服器啟動失敗,請根據教程檢查參數是否填寫完整" + "32000": "MCP 伺服器啟動失敗,請根據教程檢查參數是否填寫完整", + "toolNotFound": "未找到工具 {{name}}" }, "serverPlural": "伺服器", "serverSingular": "伺服器", diff --git a/src/renderer/src/utils/mcp-tools.ts b/src/renderer/src/utils/mcp-tools.ts index b26836ee13..ecc5e4d433 100644 --- a/src/renderer/src/utils/mcp-tools.ts +++ b/src/renderer/src/utils/mcp-tools.ts @@ -2,6 +2,7 @@ import { ContentBlockParam, MessageParam, ToolUnion, ToolUseBlock } from '@anthr import { Content, FunctionCall, Part, Tool, Type as GeminiSchemaType } from '@google/genai' import Logger from '@renderer/config/logger' import { isFunctionCallingModel, isVisionModel } from '@renderer/config/models' +import i18n from '@renderer/i18n' import store from '@renderer/store' import { addMCPServer } from '@renderer/store/mcp' import { @@ -479,6 +480,7 @@ export function parseToolUse(content: string, mcpTools: MCPTool[]): ToolUseRespo const mcpTool = mcpTools.find((tool) => tool.id === toolName) if (!mcpTool) { Logger.error(`Tool "${toolName}" not found in MCP tools`) + window.message.error(i18n.t('settings.mcp.errors.toolNotFound', { name: toolName })) continue }