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)
This commit is contained in:
OYLFLMH 2026-06-30 14:19:22 +00:00 committed by Teknium
parent d46b3bdeb4
commit f46ae96963

9
cli.py
View file

@ -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)