From f46ae969635f5c6dee63cfd0d9a770b05a822b6a Mon Sep 17 00:00:00 2001 From: OYLFLMH Date: Tue, 30 Jun 2026 14:19:22 +0000 Subject: [PATCH] fix(cli): expand env vars in mcp_servers config watcher comparison _check_config_mcp_changes compared mcp_servers from two inconsistent sources: - init: self.config.get('mcp_servers') -> from load_config() + _expand_env_vars -> expanded values - watcher: yaml.safe_load(cfg_path) -> raw templates When mcp_servers uses env-var templates like ${POWERMEM_API_KEY}, every save_config_value() that rewrites config.yaml (even for unrelated keys) triggers a false-positive MCP reload, reconnecting all servers. Apply _expand_env_vars() to the raw watcher value before comparison so both sides use the same expanded representation. Test plan: tests/cli/test_cli_mcp_config_watch.py (6/6 pass) --- cli.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cli.py b/cli.py index c86e7a4a329..3756fc7fa50 100644 --- a/cli.py +++ b/cli.py @@ -10030,6 +10030,15 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin, CLIBillingMixin): return new_mcp = new_cfg.get("mcp_servers") or {} + # Expand ${VAR} templates so the comparison is consistent with the + # init snapshot (self._config_mcp_servers), which was populated from + # the deep-merged + expanded config. Without this, any + # save_config_value() that rewrites config.yaml (even for unrelated + # keys) triggers a false-positive MCP reload because the raw yaml + # still has "${POWERMEM_API_KEY}" while the snapshot has the + # expanded value. + from hermes_cli.config import _expand_env_vars + new_mcp = _expand_env_vars(new_mcp) if new_mcp == self._config_mcp_servers: return # mcp_servers unchanged (some other section was edited)