From 9383b78381a81a7379b2ca0ea62914973bfd5cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=AC=E6=98=8E?= <83812544+Ed1s0nZ@users.noreply.github.com> Date: Sat, 15 Nov 2025 18:26:26 +0800 Subject: [PATCH] Refactor start action to check connection status immediately Modify the status check logic for the 'start' action to immediately verify connection status before polling. --- web/static/js/app.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/web/static/js/app.js b/web/static/js/app.js index 4b50b2f6..8306e27e 100644 --- a/web/static/js/app.js +++ b/web/static/js/app.js @@ -2984,8 +2984,26 @@ async function toggleExternalMCP(name, currentStatus) { const result = await response.json(); - // 如果是启动操作,轮询状态直到连接成功或失败 + // 如果是启动操作,先立即检查一次状态 if (action === 'start') { + // 立即检查一次状态(可能已经连接) + try { + const statusResponse = await apiFetch(`/api/external-mcp/${encodeURIComponent(name)}`); + if (statusResponse.ok) { + const statusData = await statusResponse.json(); + const status = statusData.status || 'disconnected'; + + if (status === 'connected') { + // 已经连接,立即刷新 + await loadExternalMCPs(); + return; + } + } + } catch (error) { + console.error('检查状态失败:', error); + } + + // 如果还未连接,开始轮询 await pollExternalMCPStatus(name, 30); // 最多轮询30次(约30秒) } else { // 停止操作,直接刷新