Forráskód Böngészése

fix: unnecessary initialization

Kadxy 11 hónapja
szülő
commit
125a71fead
3 módosított fájl, 24 hozzáadás és 6 törlés
  1. 4 2
      app/components/mcp-market.tsx
  2. 20 0
      app/mcp/actions.ts
  3. 0 4
      app/mcp/mcp_config.json

+ 4 - 2
app/components/mcp-market.tsx

@@ -17,8 +17,8 @@ import {
   updateMcpConfig,
   getClientPrimitives,
   restartAllClients,
-  reinitializeMcpClients,
   getClientErrors,
+  refreshClientStatus,
 } from "../mcp/actions";
 import { McpConfig, PresetServer, ServerConfig } from "../mcp/types";
 import clsx from "clsx";
@@ -45,7 +45,7 @@ export function McpMarketPage() {
 
   // 更新服务器状态
   const updateServerStatus = async () => {
-    await reinitializeMcpClients();
+    await refreshClientStatus();
     const errors = await getClientErrors();
     setClientErrors(errors);
   };
@@ -74,6 +74,8 @@ export function McpMarketPage() {
       setIsLoading(true);
       await updateMcpConfig(newConfig);
       setConfig(newConfig);
+      // 配置改变时需要重新初始化
+      await restartAllClients();
       await updateServerStatus();
       showToast("Configuration saved successfully");
     } catch (error) {

+ 20 - 0
app/mcp/actions.ts

@@ -214,3 +214,23 @@ export async function getClientErrors(): Promise<
   }
   return errors;
 }
+
+// 获取客户端状态,不重新初始化
+export async function refreshClientStatus() {
+  logger.info("Refreshing client status...");
+
+  // 如果还没初始化过,则初始化
+  if (!initialized) {
+    return initializeMcpClients();
+  }
+
+  // 否则只更新错误状态
+  errorClients = [];
+  for (const [clientId, clientData] of clientsMap.entries()) {
+    if (clientData.errorMsg !== null) {
+      errorClients.push(clientId);
+    }
+  }
+
+  return { errorClients };
+}

+ 0 - 4
app/mcp/mcp_config.json

@@ -27,10 +27,6 @@
     "playwright": {
       "command": "npx",
       "args": ["-y", "@executeautomation/playwright-mcp-server"]
-    },
-    "gdrive": {
-      "command": "npx",
-      "args": ["-y", "@modelcontextprotocol/server-gdrive"]
     }
   }
 }