The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(mcp): count an adopted shared connection as live in the config reconcile
teknium1c815d9128279
diff --git a/tests/tools/test_mcp_reconcile_with_config.py b/tests/tools/test_mcp_reconcile_with_config.pyindex 0a382b8a5c3..1471cbf8a29 100644--- a/tests/tools/test_mcp_reconcile_with_config.py+++ b/tests/tools/test_mcp_reconcile_with_config.py@@ -128,3 +128,32 @@ def test_reconcile_retries_failed_first_connect_only_after_cooldown(monkeypatch,mcp_tool._server_connect_retry_after, mcp_tool._server_scope_keys):store.pop("ghost", None)mcp_tool._server_connecting.discard("ghost")+++def test_reconcile_counts_adopted_shared_connection_as_live(monkeypatch, tmp_path):+ """Multiplexed gateway: profile B adopted profile A's live connection to ``x`` (the key sits under+ owner A with B in ``_server_tool_scopes``). ``x`` IS live for B — the same resolution+ ``_select_new_servers`` uses — so the every-tick reconcile must not re-enter discovery and log+ ``added=['x']`` forever for a server that already serves this profile."""+ from tools import mcp_tool+ from tools import mcp_tool_config as _config+ from tools import mcp_tool_discovery as disc++ monkeypatch.setenv("HERMES_HOME", str(tmp_path))+ monkeypatch.setattr(_config, "_load_mcp_config", lambda: {"x": {"url": "https://x/mcp"}})+ monkeypatch.setattr(mcp_tool, "_mcp_registry_scope", lambda: "B")+ discovered: list = []+ monkeypatch.setattr(disc, "discover_mcp_tools", lambda *a, **k: discovered.append(1) or [])+ with mcp_tool._lock:+ mcp_tool._servers[("A", "x")] = object()+ mcp_tool._server_scope_keys[("A", "x")] = "A"+ mcp_tool._server_tool_scopes[("A", "x")] = {"A", "B"}+ try:+ for _ in range(3):+ assert disc.reconcile_mcp_servers_with_config() == {"removed": [], "added": [], "pending": []}+ assert not discovered, "an adopted shared connection is live for this scope; nothing to add"+ finally:+ with mcp_tool._lock:+ mcp_tool._servers.pop(("A", "x"), None)+ mcp_tool._server_scope_keys.pop(("A", "x"), None)+ mcp_tool._server_tool_scopes.pop(("A", "x"), None)diff --git a/tools/mcp_tool_discovery.py b/tools/mcp_tool_discovery.pyindex 1a50013996b..cc6b4b26308 100644--- a/tools/mcp_tool_discovery.py+++ b/tools/mcp_tool_discovery.py@@ -518,9 +518,13 @@ def reconcile_mcp_servers_with_config() -> Dict[str, List[str]]:for key in lazy:_forget_lazy_server(key)with _core._lock:- known = {_key_name(key) for key, owner in _core._server_scope_keys.items()- if owner == scope and (key in _core._servers or key in _core._server_connecting)}- known |= {_key_name(key) for key in _core._lazy_server_configs}+ # Same resolution ``_select_new_servers`` applies: this scope's own connection OR a shared+ # one it adopted from another profile counts as live. Owner==scope alone misses the adopted+ # case, so a multiplexed profile would re-enter discovery (cross-process lock) and log+ # "added" every tick forever for a server that is already serving it.+ known = {name for name in wanted+ if (key := _resolve_server_key(name, scope, current=False)) in _core._servers+ or key in _core._server_connecting or key in _core._lazy_server_configs}# A configured server that is not live is retried here — this is the only reviver for one whose# FIRST connect failed (#112445) — but only once its connect cooldown lapsed: ``discover_mcp_tools``# would skip it anyway, and entering it takes the cross-process discovery lock (up to 120 s ofdiff --git a/website/docs/user-guide/features/mcp.md b/website/docs/user-guide/features/mcp.mdindex ebf37711046..9677f5caa94 100644--- a/website/docs/user-guide/features/mcp.md+++ b/website/docs/user-guide/features/mcp.md@@ -663,7 +663,7 @@ If you change MCP config, use:This reloads MCP servers from config and refreshes the available tool list. It is also the explicit way to re-probe availability-gated tools (Docker, `HASS_TOKEN`, OAuth…): a session's tool set is otherwise frozen, so a credential or daemon that appears mid-session is only picked up on `/reload-mcp`, `/new`, or context compaction. For runtime tool changes pushed by the server itself, see [Dynamic Tool Discovery](#dynamic-tool-discovery) above.-A running messaging gateway (`hermes gateway run`) also watches `config.yaml` on its own: within about a minute of you removing an `mcp_servers` entry or setting `enabled: false`, that server's connection is torn down; a newly added entry is connected. No restart or `/reload-mcp` needed for the edit to take effect.+A running messaging gateway (`hermes gateway run`) also watches `config.yaml` on its own: within about a minute of you removing an `mcp_servers` entry or setting `enabled: false`, that server's connection is torn down; a newly added entry is connected. A server whose first connect failed (an unreachable host, or an OAuth server on a headless box that had no token yet) is retried automatically on its connect cooldown schedule (30 s, doubling up to 10 min) once you fix the cause. No restart or `/reload-mcp` needed for the edit to take effect.**Expired OAuth tokens in the background.** The gateway, `/reload-mcp`, and the periodic self-probe of a parked server never open a browser — nobody is there to complete the flow. When a refresh token dies, the server parks with a warning in `gateway.log` and you re-authorize once with `hermes mcp login <server>` (or the Desktop/dashboard *Authorize* button); the parked server picks the new token up on its next probe.