Skip to content

The agent that grows with you

perf(mcp): non-blocking startup via background MCP discovery + TUI fast path

Sergey Prontsevich89f0b63da48b
diff --git a/acp_adapter/entry.py b/acp_adapter/entry.py
index fb9ed95450c..7b549006bc2 100644
--- a/acp_adapter/entry.py
+++ b/acp_adapter/entry.py
@@ -247,16 +247,22 @@ def main(argv: list[str] | None = None) -> None:
import acp
from .server import HermesACPAgent
- # MCP tool discovery from config.yaml — run before asyncio.run() so
- # it's safe to use blocking waits. (ACP also registers per-session
- # MCP servers dynamically via asyncio.to_thread inside the event
- # loop; that path is unaffected.) Moved from model_tools.py module
- # scope to avoid freezing the gateway's loop on lazy import (#16856).
+ # MCP tool discovery from config.yaml — fire-and-forget in a
+ # background daemon thread so the ACP server becomes responsive
+ # immediately while MCP servers connect. Previously this blocked
+ # asyncio.run() for 2-5 s. (ACP also registers per-session MCP
+ # servers dynamically via asyncio.to_thread inside the event loop;
+ # that path is unaffected.) Moved from model_tools.py module scope
+ # to avoid freezing the gateway's loop on lazy import (#16856).
# Metadata-only hosts can opt out of unrelated global MCP startup.
if os.environ.get("HERMES_ACP_SKIP_CONFIGURED_MCP", "").strip() != "1":
try:
- from tools.mcp_tool import discover_mcp_tools
- discover_mcp_tools()
+ from hermes_cli.mcp_startup import start_background_mcp_discovery
+
+ start_background_mcp_discovery(
+ logger=logger,
+ thread_name="acp-mcp-discovery",
+ )
except Exception:
logger.debug("MCP tool discovery failed at ACP startup", exc_info=True)