feat(tool system): Optimization of the tool system

1. Optimization of the JSON tool, add insert, replace, delete, parse
2. Optimization of the mcp test_connection
3. tool list desc
4. datetime_tool default timezone set Asia/Shanghai
This commit is contained in:
谢俊男
2025-12-26 19:11:20 +08:00
parent 05e25c5882
commit 9fb7d7d059
6 changed files with 300 additions and 25 deletions

View File

@@ -379,9 +379,8 @@ class MCPClient:
Returns:
响应数据
"""
request_id = str(request_data["id"])
if self.connection_type == "websocket":
request_id = str(request_data["id"])
return await self._send_websocket_request(request_data, request_id, timeout)
else:
return await self._send_http_request(request_data, timeout)
@@ -423,12 +422,19 @@ class MCPClient:
json=request_data,
timeout=aiohttp.ClientTimeout(total=timeout)
) as response:
if response.status != 200:
error_text = await response.text()
raise MCPConnectionError(f"HTTP请求失败 {response.status}: {error_text}")
return await response.json()
if response.status == 200:
return await response.json()
else:
async with self._session.post(
self.server_url,
json=request_data,
timeout=aiohttp.ClientTimeout(total=timeout)
) as root_response:
if root_response.status != 200:
error_text = await root_response.text()
raise MCPConnectionError(f"HTTP请求失败 {response.status}: {error_text}")
return await response.json()
except aiohttp.ClientError as e:
raise MCPConnectionError(f"HTTP请求失败: {e}")