fix: make doctor checks resilient to slow mcporter calls (#103)
This commit is contained in:
@@ -29,15 +29,35 @@ class BossZhipinChannel(Channel):
|
||||
)
|
||||
try:
|
||||
r = subprocess.run(
|
||||
[mcporter, "list"], capture_output=True,
|
||||
encoding="utf-8", errors="replace", timeout=10
|
||||
[mcporter, "config", "get", "bosszhipin", "--json"],
|
||||
capture_output=True,
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
timeout=5,
|
||||
)
|
||||
if r.returncode != 0 or "bosszhipin" not in r.stdout.lower():
|
||||
return "off", (
|
||||
"mcporter 已装但 Boss直聘 MCP 未配置。\n"
|
||||
" 详见 https://github.com/mucsbr/mcp-bosszp"
|
||||
)
|
||||
except Exception:
|
||||
return "off", "mcporter 连接异常"
|
||||
|
||||
try:
|
||||
r = subprocess.run(
|
||||
[mcporter, "call", "bosszhipin.get_login_info_tool", "--output", "json"],
|
||||
capture_output=True,
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
timeout=10,
|
||||
)
|
||||
out = r.stdout.lower()
|
||||
if "boss" in out or "zhipin" in out:
|
||||
return "ok", "可搜索职位、向 HR 打招呼"
|
||||
if r.returncode == 0 and "\"is_logged_in\": true" in out:
|
||||
return "ok", "完整可用(职位搜索、登录态检查、向 HR 打招呼)"
|
||||
if r.returncode == 0:
|
||||
return "ok", "MCP 已连接,可搜索职位;打招呼前可能需要先登录"
|
||||
return "warn", "MCP 已配置,但连接异常;请检查 mcp-bosszp 服务状态"
|
||||
except subprocess.TimeoutExpired:
|
||||
return "warn", "MCP 已配置,但健康检查超时;请检查 mcp-bosszp 服务状态"
|
||||
except Exception:
|
||||
pass
|
||||
return "off", (
|
||||
"mcporter 已装但 Boss直聘 MCP 未配置。\n"
|
||||
" 详见 https://github.com/mucsbr/mcp-bosszp"
|
||||
)
|
||||
return "warn", "MCP 已配置,但连接异常;请检查 mcp-bosszp 服务状态"
|
||||
|
||||
@@ -51,10 +51,13 @@ class XiaoHongShuChannel(Channel):
|
||||
)
|
||||
try:
|
||||
r = subprocess.run(
|
||||
[mcporter, "config", "list"], capture_output=True,
|
||||
encoding="utf-8", errors="replace", timeout=5
|
||||
[mcporter, "config", "get", "xiaohongshu", "--json"],
|
||||
capture_output=True,
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
timeout=5,
|
||||
)
|
||||
if "xiaohongshu" not in r.stdout:
|
||||
if r.returncode != 0 or "xiaohongshu" not in r.stdout.lower():
|
||||
return "off", (
|
||||
"mcporter 已装但小红书 MCP 未配置。运行:\n"
|
||||
+ _docker_run_hint() + "\n"
|
||||
@@ -62,13 +65,20 @@ class XiaoHongShuChannel(Channel):
|
||||
)
|
||||
except Exception:
|
||||
return "off", "mcporter 连接异常"
|
||||
|
||||
try:
|
||||
r = subprocess.run(
|
||||
[mcporter, "call", "xiaohongshu.check_login_status()"],
|
||||
capture_output=True, encoding="utf-8", errors="replace", timeout=10
|
||||
[mcporter, "list", "xiaohongshu", "--json"],
|
||||
capture_output=True,
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
timeout=10,
|
||||
)
|
||||
if "已登录" in r.stdout or "logged" in r.stdout.lower():
|
||||
return "ok", "完整可用(阅读、搜索、发帖、评论、点赞)"
|
||||
return "warn", "MCP 已连接但未登录,需扫码登录"
|
||||
out = r.stdout.lower()
|
||||
if r.returncode == 0 and '"status": "ok"' in out:
|
||||
return "ok", "MCP 已连接(阅读、搜索、发帖、评论、点赞)"
|
||||
return "warn", "MCP 已配置,但连接异常;请检查 xiaohongshu-mcp 服务状态"
|
||||
except subprocess.TimeoutExpired:
|
||||
return "warn", "MCP 已配置,但健康检查超时;请检查 xiaohongshu-mcp 服务状态"
|
||||
except Exception:
|
||||
return "warn", "MCP 连接异常,检查 xiaohongshu-mcp 服务是否在运行"
|
||||
return "warn", "MCP 已配置,但连接异常;请检查 xiaohongshu-mcp 服务状态"
|
||||
|
||||
Reference in New Issue
Block a user