feat: 将 JSON 处理库从 json 更改为 orjson,以提高性能和兼容性

This commit is contained in:
Windpicker-owo
2025-11-06 12:47:56 +08:00
parent e29266582d
commit 17c1d4b4f9
18 changed files with 83 additions and 78 deletions

View File

@@ -5,7 +5,7 @@ MCP Client Manager
"""
import asyncio
import json
import orjson
import shutil
from pathlib import Path
from typing import Any
@@ -89,7 +89,7 @@ class MCPClientManager:
try:
with open(self.config_path, encoding="utf-8") as f:
config_data = json.load(f)
config_data = orjson.loads(f.read())
servers = {}
mcp_servers = config_data.get("mcpServers", {})
@@ -106,7 +106,7 @@ class MCPClientManager:
logger.info(f"成功加载 {len(servers)} 个 MCP 服务器配置")
return servers
except json.JSONDecodeError as e:
except orjson.JSONDecodeError as e:
logger.error(f"解析 MCP 配置文件失败: {e}")
return {}
except Exception as e:

View File

@@ -236,10 +236,10 @@ class ToolExecutor:
if isinstance(content, str):
result_preview = content
elif isinstance(content, list | dict):
import json
import orjson
try:
result_preview = json.dumps(content, ensure_ascii=False)
result_preview = orjson.dumps(content, option=orjson.OPT_NON_STR_KEYS).decode('utf-8')
except Exception:
result_preview = str(content)
else: