fix(im_llm): 代理绕过Docker内部hostname

This commit is contained in:
QihuAI Design committed 2026-07-31 08:51:15 +08:00
1 parent 96aabc31f6
commit 9a43ee244d
24 files changed
+898 -129

No files matched your search

+20 -3
View File
@@ -855,17 +855,34 @@ def _test_mcp_server(server, db) -> dict:
hdrs = json.loads(server.headers) if isinstance(server.headers, str) else (server.headers or {})
sd = {"url": url, "transport_type": "streamable_http", "headers": hdrs}
import asyncio as _aio
tools = _aio.run(_lmt(sd, timeout=15))
# raise_on_error=True 让网络异常透传,暴露真实错误而非 "no tools found"
tools = _aio.run(_lmt(sd, timeout=15, raise_on_error=True))
result["success"] = bool(tools)
result["details"]["tools_count"] = len(tools)
result["details"]["tools"] = [t.get("name") for t in tools[:5]]
result["message"] = f"Connected — {len(tools)} tools available" if tools else "Connected but no tools found"
if tools:
result["message"] = f"Connected — {len(tools)} tools available"
else:
result["message"] = "Connected but no tools found (server returned empty list)"
result["details"]["status_code"] = 200
if tools:
server.tools_count = len(tools)
server.status = "connected"
except Exception as e:
result["message"] = f"Connection failed: {str(e)}"
# 把真实异常(类型+消息)透传给前端,告别误导性的 "Connected but no tools found"
err_type = type(e).__name__
err_msg = str(e)[:300]
result["message"] = f"{err_type}: {err_msg}"
result["details"]["error_type"] = err_type
result["details"]["error"] = err_msg
if "ConnectError" in err_type or "Timeout" in err_type:
result["details"]["hint"] = "网络层无法到达 MCP 服务器,请检查代理配置或服务端 URL"
elif "404" in err_msg or "NotFound" in err_type:
result["details"]["hint"] = "服务端 URL 不存在或路径错误"
elif "401" in err_msg or "Unauthorized" in err_type:
result["details"]["hint"] = "认证失败:检查请求头中的 Authorization"
else:
result["details"]["hint"] = "检查认证头/transport_type 或服务端状态"
elif transport == "sse":