mcp: connect in background, never block startup #146

Merged
hermes merged 1 commits from mcp-async into main 2026-10-10 22:17:42 +00:00
Collaborator

MCP servers no longer block startup; a hung or slow server cost up to 70s (10s connect + 60s list).

  • Hub::spawn(cfgs) returns at once; one task per server fills its Slot (state behind RwLock, pending flag, watch signal on completion). Hub::start (wait for all) stays for hx mcp, hx prefix, tests.
  • Startup listing (tools/prompts/resources) uses the 10s connect timeout, not timeout_secs (that now only bounds tool calls).
  • main.rs: waits at most 1s so fast servers land in the startup system prompt (cache-stable); the rest connect in the background.
  • Pending servers: mcp_describe/mcp_call/mcp_read always registered; they wait for the slot (bounded) then return a clear still connecting / failed error. mcp_describe without tool lists a server's tools. Late servers are not eager-registered and not added to the system prompt (no mid-session cache break); the prompt names the pending servers.
  • /mcp shows connecting…; MCP prompts as slash commands appear only for servers ready at startup (typed /server:prompt still works).
  • Test spawn_does_not_block_on_slow_server (fake server gets FAKE_INIT_DELAY). tests/all.sh green.

Not done: dynamic slash-command and side-panel refresh when a late server finishes (needs TUI hook); no auto-retry of failed servers.

MCP servers no longer block startup; a hung or slow server cost up to 70s (10s connect + 60s list). - `Hub::spawn(cfgs)` returns at once; one task per server fills its `Slot` (state behind `RwLock`, `pending` flag, `watch` signal on completion). `Hub::start` (wait for all) stays for `hx mcp`, `hx prefix`, tests. - Startup listing (tools/prompts/resources) uses the 10s connect timeout, not `timeout_secs` (that now only bounds tool calls). - main.rs: waits at most 1s so fast servers land in the startup system prompt (cache-stable); the rest connect in the background. - Pending servers: `mcp_describe`/`mcp_call`/`mcp_read` always registered; they wait for the slot (bounded) then return a clear `still connecting` / `failed` error. `mcp_describe` without `tool` lists a server's tools. Late servers are not eager-registered and not added to the system prompt (no mid-session cache break); the prompt names the pending servers. - `/mcp` shows `connecting…`; MCP prompts as slash commands appear only for servers ready at startup (typed `/server:prompt` still works). - Test `spawn_does_not_block_on_slow_server` (fake server gets `FAKE_INIT_DELAY`). `tests/all.sh` green. Not done: dynamic slash-command and side-panel refresh when a late server finishes (needs TUI hook); no auto-retry of failed servers.
hermes added 1 commit 2026-10-10 22:15:16 +00:00
hermes merged commit 8b5d24436f into main 2026-10-10 22:17:42 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: johannes/hx#146