From 6c57169162601e02e3c335f0ad7e6cd80bfc8504 Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Sat, 13 Jun 2026 20:05:46 +0800 Subject: [PATCH] feat(mcp): add one-click install/upgrade button --- .../editor/EditorSettingsDialog.vue | 55 ++++++++++++++++++- apps/desktop/src/i18n/locales/en.ts | 6 ++ apps/desktop/src/i18n/locales/es.ts | 6 ++ apps/desktop/src/i18n/locales/it.ts | 6 ++ apps/desktop/src/i18n/locales/pt-BR.ts | 6 ++ apps/desktop/src/i18n/locales/zh-CN.ts | 6 ++ apps/desktop/src/lib/api.ts | 1 + apps/desktop/src/lib/tauri.ts | 4 ++ src-tauri/src/commands/mcp.rs | 20 +++++++ src-tauri/src/lib.rs | 1 + 10 files changed, 110 insertions(+), 1 deletion(-) diff --git a/apps/desktop/src/components/editor/EditorSettingsDialog.vue b/apps/desktop/src/components/editor/EditorSettingsDialog.vue index c753230cd9..a5daa2da84 100644 --- a/apps/desktop/src/components/editor/EditorSettingsDialog.vue +++ b/apps/desktop/src/components/editor/EditorSettingsDialog.vue @@ -37,7 +37,22 @@ import { isTauriRuntime } from "@/lib/tauriRuntime"; import { useTheme } from "@/composables/useTheme"; import { copyToClipboard } from "@/lib/clipboard"; import { clearDebugLogs as clearStoredDebugLogs, downloadDebugLogs, getDebugLogBundleText } from "@/lib/debugLog"; -import { aiListModels, aiTestConnection, checkMcpServerStatus, forgetWebdavSavedPassword, listSystemFonts, saveWebdavSavedPassword, webdavPasswordStatus, webdavSyncDownload, webdavSyncTest, webdavSyncUpload, type AiModelInfo, type McpServerStatus, type WebDavConfig } from "@/lib/api"; +import { + aiListModels, + aiTestConnection, + checkMcpServerStatus, + installMcpServer, + forgetWebdavSavedPassword, + listSystemFonts, + saveWebdavSavedPassword, + webdavPasswordStatus, + webdavSyncDownload, + webdavSyncTest, + webdavSyncUpload, + type AiModelInfo, + type McpServerStatus, + type WebDavConfig, +} from "@/lib/api"; import { eventToShortcut } from "@/lib/keyboardShortcuts"; import { SHORTCUT_DEFINITIONS, findShortcutConflict, normalizeShortcutSettings, type ShortcutActionId } from "@/lib/shortcutRegistry"; import { normalizeSidebarHiddenTablePrefixes } from "@/lib/sidebarTableNameDisplay"; @@ -628,6 +643,9 @@ const mcpCopied = ref<"" | "install" | "claude-config" | "codex-config">(""); const mcpConfigTab = ref<"claude" | "codex">("claude"); const mcpReadonlyMode = ref(false); const mcpAllowDangerous = ref(false); +const mcpInstalling = ref(false); +const mcpInstallMessage = ref(""); +const mcpInstallError = ref(false); const mcpEnvEntries = computed(() => { const entries: Array<[string, string]> = []; @@ -717,6 +735,30 @@ async function copyMcpText(kind: "install" | "claude-config" | "codex-config", v }, 1500); } +async function installMcp() { + if (mcpInstalling.value) return; + mcpInstalling.value = true; + mcpInstallMessage.value = ""; + mcpInstallError.value = false; + try { + const result = await installMcpServer(); + mcpInstallMessage.value = result; + mcpInstallError.value = false; + // 安装成功后刷新状态 + await refreshMcpStatus(); + } catch (e: any) { + mcpInstallMessage.value = e?.message || String(e); + mcpInstallError.value = true; + } finally { + mcpInstalling.value = false; + // 3秒后清除消息 + window.setTimeout(() => { + mcpInstallMessage.value = ""; + mcpInstallError.value = false; + }, 3000); + } +} + // ---------- WebDAV Sync ---------- const webdavEndpoint = ref(localStorage.getItem("dbx-webdav-endpoint") || ""); const webdavUsername = ref(localStorage.getItem("dbx-webdav-username") || ""); @@ -2276,6 +2318,17 @@ watch( + + +
+ {{ mcpInstallMessage }}
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts index 64f5547d34..d50ec7f024 100644 --- a/apps/desktop/src/i18n/locales/en.ts +++ b/apps/desktop/src/i18n/locales/en.ts @@ -2174,6 +2174,12 @@ mcpBinPath: "Command path", mcpInstallCommand: "Install command", mcpUpdateCommand: "Upgrade command", + mcpInstallButton: "Install", + mcpUpdateButton: "Upgrade", + mcpUpToDate: "Up to date", + mcpInstalling: "Installing...", + mcpInstallSuccess: "Installation successful", + mcpInstallFailed: "Installation failed", mcpConfig: "MCP config", mcpCodexConfig: "Codex config", mcpCodexConfigPath: "Codex can use ~/.codex/config.toml or a project-level .codex/config.toml.", diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts index 50e0172d66..06e08c230c 100644 --- a/apps/desktop/src/i18n/locales/es.ts +++ b/apps/desktop/src/i18n/locales/es.ts @@ -1890,6 +1890,12 @@ mcpBinPath: "Ruta del comando", mcpInstallCommand: "Comando de instalación", mcpUpdateCommand: "Comando de actualización", + mcpInstallButton: "Instalar", + mcpUpdateButton: "Actualizar", + mcpUpToDate: "Actualizado", + mcpInstalling: "Instalando...", + mcpInstallSuccess: "Instalación exitosa", + mcpInstallFailed: "Error de instalación", mcpConfig: "Configuración de MCP", mcpCodexConfig: "Configuración de Codex", mcpCodexConfigPath: "Codex puede usar ~/.codex/config.toml o .codex/config.toml dentro del proyecto.", diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.ts index bb394bdd5c..3cee816b2d 100644 --- a/apps/desktop/src/i18n/locales/it.ts +++ b/apps/desktop/src/i18n/locales/it.ts @@ -1959,6 +1959,12 @@ mcpBinPath: "Comando path", mcpInstallCommand: "Comando di installazione", mcpUpdateCommand: "Comando di aggiornamento", + mcpInstallButton: "Installa", + mcpUpdateButton: "Aggiorna", + mcpUpToDate: "Aggiornato", + mcpInstalling: "Installazione...", + mcpInstallSuccess: "Installazione completata", + mcpInstallFailed: "Installazione fallita", mcpConfig: "Configurazione MCP", mcpCodexConfig: "Configurazione Codex", mcpCodexConfigPath: "Codex può utilizzare ~/.codex/config.toml o un .codex/config.toml a livello di progetto.", diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.ts index c44dada1c1..4bec67483b 100644 --- a/apps/desktop/src/i18n/locales/pt-BR.ts +++ b/apps/desktop/src/i18n/locales/pt-BR.ts @@ -1970,6 +1970,12 @@ mcpBinPath: "Caminho do comando", mcpInstallCommand: "Comando de instalação", mcpUpdateCommand: "Comando de atualização", + mcpInstallButton: "Instalar", + mcpUpdateButton: "Atualizar", + mcpUpToDate: "Atualizado", + mcpInstalling: "Instalando...", + mcpInstallSuccess: "Instalação bem-sucedida", + mcpInstallFailed: "Falha na instalação", mcpConfig: "Configuração do MCP", mcpCodexConfig: "Configuração do Codex", mcpCodexConfigPath: "O Codex pode usar ~/.codex/config.toml ou um .codex/config.toml no nível do projeto.", diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts index 0af9caeafb..41eb7463c9 100644 --- a/apps/desktop/src/i18n/locales/zh-CN.ts +++ b/apps/desktop/src/i18n/locales/zh-CN.ts @@ -2198,6 +2198,12 @@ mcpBinPath: "命令路径", mcpInstallCommand: "安装命令", mcpUpdateCommand: "升级命令", + mcpInstallButton: "安装", + mcpUpdateButton: "升级", + mcpUpToDate: "已是最新", + mcpInstalling: "安装中...", + mcpInstallSuccess: "安装成功", + mcpInstallFailed: "安装失败", mcpConfig: "MCP 配置", mcpCodexConfig: "Codex 配置", mcpCodexConfigPath: "Codex 可放在 ~/.codex/config.toml 或项目级 .codex/config.toml。", diff --git a/apps/desktop/src/lib/api.ts b/apps/desktop/src/lib/api.ts index 12417eddfd..ea555dbaff 100644 --- a/apps/desktop/src/lib/api.ts +++ b/apps/desktop/src/lib/api.ts @@ -294,6 +294,7 @@ export const deleteHistoryEntry = forward("deleteHistoryEntry"); // Updates export const checkMcpServerStatus = forward("checkMcpServerStatus"); +export const installMcpServer = forward("installMcpServer"); export const checkForUpdates = forward("checkForUpdates"); export const getSystemProxyUrl = forward("getSystemProxyUrl"); export const getAppVersion = forward("getAppVersion"); diff --git a/apps/desktop/src/lib/tauri.ts b/apps/desktop/src/lib/tauri.ts index 8cd544e85b..8509163520 100644 --- a/apps/desktop/src/lib/tauri.ts +++ b/apps/desktop/src/lib/tauri.ts @@ -1043,6 +1043,10 @@ export async function checkMcpServerStatus(): Promise { return invoke("check_mcp_server_status"); } +export async function installMcpServer(): Promise { + return invoke("install_mcp_server"); +} + export async function checkForUpdates(): Promise { return invoke("check_for_updates"); } diff --git a/src-tauri/src/commands/mcp.rs b/src-tauri/src/commands/mcp.rs index 5a86401385..a47df8a0ba 100644 --- a/src-tauri/src/commands/mcp.rs +++ b/src-tauri/src/commands/mcp.rs @@ -62,6 +62,26 @@ pub async fn check_mcp_server_status() -> Result { }) } +#[tauri::command] +pub async fn install_mcp_server() -> Result { + tauri::async_runtime::spawn_blocking(|| { + let output = command_output( + "npm", + &["install", "-g", "@dbx-app/mcp-server@latest", "--registry=https://registry.npmjs.org"], + )?; + + if !output.success { + let error_msg = if !output.stderr.is_empty() { output.stderr } else { output.stdout }; + return Err(format!("Installation failed: {}", error_msg)); + } + + let version = installed_mcp_version().unwrap_or_else(|| "unknown".to_string()); + Ok(format!("Successfully installed @dbx-app/mcp-server@{}", version)) + }) + .await + .map_err(|e| e.to_string())? +} + async fn fetch_latest_mcp_version() -> Result { let mut builder = reqwest::Client::builder().timeout(Duration::from_secs(10)).user_agent("dbx-mcp-status-checker"); let proxy_url = diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index d07513c1da..fc26b77a86 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -514,6 +514,7 @@ pub fn run() { commands::history::clear_history, commands::history::delete_history_entry, commands::mcp::check_mcp_server_status, + commands::mcp::install_mcp_server, commands::update::check_for_updates, commands::update::get_system_proxy_url, commands::transfer::start_transfer,