From 2742f2e1ffdbc6049da18ffea324746d6c1c3c81 Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Wed, 18 Jun 2025 17:28:21 +0800 Subject: [PATCH] =?UTF-8?q?update:=E4=BF=AE=E5=A4=8Dmcp=E8=BF=94=E5=9B=9Ej?= =?UTF-8?q?son=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/connection.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index 7928d1cf..e10ea3d4 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -752,18 +752,25 @@ class ConnectionHandler: ).result() self.logger.bind(tag=TAG).debug(f"MCP工具调用结果: {result}") + resultJson = None if isinstance(result, str): try: - result = json.loads(result) + resultJson = json.loads(result) except Exception as e: - self.logger.bind(tag=TAG).error(f"解析MCP工具返回结果失败: {e}") + self.logger.bind(tag=TAG).error( + f"解析MCP工具返回结果失败: {e}" + ) # 视觉大模型不经过二次LLM处理 - if isinstance(result, dict) and "action" in result: + if ( + resultJson is not None + and isinstance(resultJson, dict) + and "action" in resultJson + ): result = ActionResponse( - action=Action[result["action"]], + action=Action[resultJson["action"]], result=None, - response=result.get("response", "") + response=resultJson.get("response", ""), ) else: result = ActionResponse(