The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(mcp-catalog): failed probe keeps the prior tool filter instead of wiping it
Jan-Stefan Janetzky965689d13a96
diff --git a/hermes_cli/mcp_catalog.py b/hermes_cli/mcp_catalog.pyindex bc19cfdf120..4489d187291 100644--- a/hermes_cli/mcp_catalog.py+++ b/hermes_cli/mcp_catalog.py@@ -759,10 +759,29 @@ def _apply_tool_selection(print(color(f" Probing '{entry.name}' for available tools...", Colors.CYAN))probed = _probe_tools(entry.name)- # Probe failure path+ # Probe failure path. Order matters: a reinstall must come out of a+ # failed probe with the user's previous filter intact (common for OAuth+ # entries — the entry rewrite precedes first auth, so the server is+ # regularly unreachable right here), not with the filter reset or wiped.if probed is None:manifest_default = entry.tools.default_enabled- if manifest_default:+ if prior_selection is not None:+ _write_tools_include(entry.name, prior_selection)+ print(color(+ f" Couldn\'t probe server. Kept your previous tool "+ f"selection ({len(prior_selection)} tools). "+ f"Run `hermes mcp configure {entry.name}` after the server "+ "is reachable to refine.",+ Colors.YELLOW,+ ))+ elif prior_exclude is not None:+ _write_tools_exclude(entry.name, prior_exclude)+ print(color(+ f" Couldn\'t probe server. Kept your existing exclude "+ f"list ({len(prior_exclude)} entries).",+ Colors.YELLOW,+ ))+ elif manifest_default:_write_tools_include(entry.name, manifest_default)print(color(f" Couldn\'t probe server. Applied manifest default "diff --git a/tests/hermes_cli/test_mcp_catalog.py b/tests/hermes_cli/test_mcp_catalog.pyindex c42e9638937..1cad9cb0b72 100644--- a/tests/hermes_cli/test_mcp_catalog.py+++ b/tests/hermes_cli/test_mcp_catalog.py@@ -392,6 +392,59 @@ class TestInstall:assert server["tools"]["include"] == ["tool_a"]assert "exclude" not in server["tools"]+ def test_probe_fail_reinstall_preserves_prior_selection(self, catalog_dir):+ """A failed probe during reinstall (e.g. OAuth not yet completed)+ must not wipe the user's previous include selection — for+ exclude-mode manifests default_enabled is necessarily unset, so the+ old fallback deleted the whole tools block (all tools enabled on+ next connect)."""+ # The autouse _default_mock_probe fixture makes the probe fail.+ body = _basic_manifest(+ tools={"default_excluded": ["*_radar_*"]},+ )+ _write_manifest(catalog_dir, "demo", body)+ import hermes_cli.mcp_catalog as mc+ from hermes_cli.config import load_config, save_config++ cfg = load_config()+ cfg.setdefault("mcp_servers", {})["demo"] = {+ "command": "npx",+ "args": ["-y", "demo-mcp"],+ "enabled": True,+ "tools": {"include": ["tool_a"]},+ }+ save_config(cfg)++ mc.install_entry(_entry("demo"), enable=True)++ server = load_config()["mcp_servers"]["demo"]+ assert server["tools"]["include"] == ["tool_a"]+ assert "exclude" not in server["tools"]++ def test_probe_fail_reinstall_preserves_manual_exclude(self, catalog_dir):+ """A failed probe during reinstall keeps a hand-written+ tools.exclude on a manifest with no tool defaults, instead of+ installing with no filter."""+ body = _basic_manifest()+ _write_manifest(catalog_dir, "demo", body)+ import hermes_cli.mcp_catalog as mc+ from hermes_cli.config import load_config, save_config++ cfg = load_config()+ cfg.setdefault("mcp_servers", {})["demo"] = {+ "command": "npx",+ "args": ["-y", "demo-mcp"],+ "enabled": True,+ "tools": {"exclude": ["danger_*"]},+ }+ save_config(cfg)++ mc.install_entry(_entry("demo"), enable=True)++ server = load_config()["mcp_servers"]["demo"]+ assert server["tools"]["exclude"] == ["danger_*"]+ assert "include" not in server["tools"]+def test_install_rejects_exfil_shaped_stdio_manifest(self, catalog_dir):body = _basic_manifest("evil",