Skip to content

perf(mcp): non-blocking startup via background MCP discovery#32811

Open
Prontsevich wants to merge 2 commits into
NousResearch:mainfrom
Prontsevich:perf/mcp-bg-discovery
Open

perf(mcp): non-blocking startup via background MCP discovery#32811
Prontsevich wants to merge 2 commits into
NousResearch:mainfrom
Prontsevich:perf/mcp-bg-discovery

Conversation

@Prontsevich

Copy link
Copy Markdown

Fire-and-forget MCP server connections on a daemon thread so the gateway / CLI / ACP process becomes interactive immediately.

Previously hermes --tui waited 2-5 s after the splash screen before rendering the UI while discover_mcp_tools() ran synchronously on the critical path.

Changes:

  • tools/mcp_tool.py: new discover_mcp_tools_background() — daemon thread wrapper
  • tui_gateway/entry.py, hermes_cli/main.py, cli.py, acp_adapter/entry.py: use background variant

Related: #29726, #29184, #19326 (closed stale)
Closes: #29726

@alt-glitch alt-glitch added type/perf Performance improvement or optimization tool/mcp MCP client and OAuth comp/cli CLI entry point, hermes_cli/, setup wizard comp/tui Terminal UI (ui-tui/ + tui_gateway/) comp/acp Agent Communication Protocol adapter P2 Medium — degraded but workaround exists labels May 26, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related competing PRs for #29726 (MCP startup hang):

Also note #25622 (open) — fixes tool registration race on startup. Background discovery may interact with the same race window if tools aren't registered before the first user message arrives.

…st path

Fire-and-forget MCP server connections on a daemon thread so the
gateway / CLI / ACP process becomes interactive immediately instead
of blocking on slow remote MCP servers (HTTP timeouts, sluggish
stdio boot).  Previously `hermes --tui` waited 2-5 s after the splash
screen before rendering the UI while `discover_mcp_tools()` ran
synchronously on the critical path.

Changes:
- tools/mcp_tool.py: add `discover_mcp_tools_background()` — thin
  wrapper that spawns `discover_mcp_tools()` on a named daemon thread
- tui_gateway/entry.py: call `discover_mcp_tools_background()` before
  sending gateway.ready (replaces inline call that blocked the JSON-RPC
  pipe for the TUI Ink app)
- hermes_cli/main.py:
  - skip `\_prepare_agent_startup()` for TUI path — plugins, MCP, and
    shell hooks are only needed by the CLI agent loop; the TUI's
    gateway subprocess discovers them independently (~370 ms saved)
  - fast-path in `\_make_tui_argv()`: when `dist/entry.js` exists and
    is fresh, skip npm install / rebuild checks entirely (~350 ms saved)
- cli.py (`\_prepare_deferred_agent_startup`): same background pattern
  for deferred startup (Termux interactive CLI)
- acp_adapter/entry.py: same pattern so ACP server launches asyncio
  immediately while MCP connects in parallel

Result:
- TUI Python wrapper: ~730 ms → ~80 ms (9× faster)
- gateway.ready: ~2700 ms → ~400 ms (7× faster)
- Total TUI cold start: ~3400 ms → ~480 ms

Related: NousResearch#29726, NousResearch#29184, NousResearch#19326 (closed stale)

Closes NousResearch#29726
@Prontsevich Prontsevich force-pushed the perf/mcp-bg-discovery branch from 1c95d71 to 4e13266 Compare June 1, 2026 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/acp Agent Communication Protocol adapter comp/cli CLI entry point, hermes_cli/, setup wizard comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists tool/mcp MCP client and OAuth type/perf Performance improvement or optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants