From 17ac2ce0ed52874616c79c910667e41e34604826 Mon Sep 17 00:00:00 2001
From: wangzhibo <wangzhibo@shsening.com>
Date: 星期一, 31 八月 2026 13:14:12 +0800
Subject: [PATCH] add translation app

---
 xiaozhi-esp32-server/main/xiaozhi-server/core/providers/tools/server_mcp/mcp_manager.py |   38 +++++++++++++++++++++++++++-----------
 1 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/xiaozhi-esp32-server/main/xiaozhi-server/core/providers/tools/server_mcp/mcp_manager.py b/xiaozhi-esp32-server/main/xiaozhi-server/core/providers/tools/server_mcp/mcp_manager.py
index b1fc0aa..24bf48b 100644
--- a/xiaozhi-esp32-server/main/xiaozhi-server/core/providers/tools/server_mcp/mcp_manager.py
+++ b/xiaozhi-esp32-server/main/xiaozhi-server/core/providers/tools/server_mcp/mcp_manager.py
@@ -2,6 +2,7 @@
 
 import asyncio
 import os
+import sys
 import json
 from typing import Dict, Any, List
 
@@ -33,18 +34,33 @@
 
     def load_config(self) -> Dict[str, Any]:
         """鍔犺浇MCP鏈嶅姟閰嶇疆"""
-        if len(self.config_path) == 0:
-            return {}
+        servers: Dict[str, Any] = {}
+        if self.config_path:
+            try:
+                with open(self.config_path, "r", encoding="utf-8") as f:
+                    config = json.load(f)
+                servers = config.get("mcpServers", {}) or {}
+            except Exception as e:
+                logger.bind(tag=TAG).error(
+                    f"Error loading MCP config from {self.config_path}: {e}"
+                )
+                servers = {}
+        return self._ensure_builtin_servers(servers)
 
-        try:
-            with open(self.config_path, "r", encoding="utf-8") as f:
-                config = json.load(f)
-            return config.get("mcpServers", {})
-        except Exception as e:
-            logger.bind(tag=TAG).error(
-                f"Error loading MCP config from {self.config_path}: {e}"
-            )
-            return {}
+    def _ensure_builtin_servers(self, servers: Dict[str, Any]) -> Dict[str, Any]:
+        """Register the Phase 1 translate MCP even if data/.mcp_server_settings.json is missing."""
+        if "english-translate" in servers:
+            return servers
+        script = os.path.join(
+            get_project_dir(), "mcp_servers", "translate", "server.py"
+        )
+        if os.path.isfile(script):
+            servers["english-translate"] = {
+                "command": sys.executable or "python",
+                "args": [script],
+            }
+            logger.bind(tag=TAG).info("宸叉敞鍐屽唴缃� english-translate MCP")
+        return servers
 
     async def _init_server(self, name: str, srv_config: Dict[str, Any]):
         """鍒濆鍖栧崟涓狹CP鏈嶅姟"""

--
Gitblit v1.9.1