Skip to content

Commit 9ed7504

Browse files
committed
fix: MCP client initialization failed
fixes: #5755
1 parent 447b454 commit 9ed7504

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

astrbot/core/provider/func_tool_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ async def init_mcp_clients(
411411
name=name,
412412
cfg=cfg,
413413
shutdown_event=shutdown_event,
414-
timeout_seconds=init_timeout_value,
414+
timeout=init_timeout_value,
415415
),
416416
name=f"mcp-init:{name}",
417417
)

astrbot/core/provider/manager.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -334,26 +334,19 @@ async def initialize(
334334
if not self.curr_tts_provider_inst and self.tts_provider_insts:
335335
self.curr_tts_provider_inst = self.tts_provider_insts[0]
336336

337-
# 初始化 MCP Client 连接(等待完成以确保工具可用)
338-
strict_mcp_init = os.getenv("ASTRBOT_MCP_INIT_STRICT", "").strip().lower() in {
339-
"1",
340-
"true",
341-
"yes",
342-
"on",
343-
}
344-
mcp_init_summary = await self.llm_tools.init_mcp_clients(
345-
raise_on_all_failed=strict_mcp_init,
346-
init_timeout=init_timeout,
347-
)
348-
if (
349-
mcp_init_summary.total > 0
350-
and mcp_init_summary.success == 0
351-
and not strict_mcp_init
352-
):
353-
logger.warning(
354-
"MCP 服务全部初始化失败,系统将继续启动(可设置 "
355-
"ASTRBOT_MCP_INIT_STRICT=1 以在此场景下中止启动)。"
337+
try:
338+
strict_mcp_init = os.getenv("ASTRBOT_MCP_INIT_STRICT", "").strip().lower() in {
339+
"1",
340+
"true",
341+
"yes",
342+
"on",
343+
}
344+
await self.llm_tools.init_mcp_clients(
345+
raise_on_all_failed=strict_mcp_init,
346+
init_timeout=init_timeout,
356347
)
348+
except Exception as e:
349+
logger.error("MCP service initialization failed", exc_info=True)
357350

358351
def dynamic_import_provider(self, type: str) -> None:
359352
"""动态导入提供商适配器模块

0 commit comments

Comments
 (0)