The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(mcp): stdio MCP children get the routed profile's vault secrets, not the default's
Teknium580322ef1e15
diff --git a/hermes_cli/env_loader.py b/hermes_cli/env_loader.pyindex 7508f53c257..ba99297d5d2 100644--- a/hermes_cli/env_loader.py+++ b/hermes_cli/env_loader.py@@ -88,6 +88,12 @@ def get_secret_source(env_var: str) -> str | None:return _SECRET_SOURCES.get(env_var)+def secret_source_names() -> tuple[str, ...]:+ """Every env-var name some profile's external secret source supplied (names only — the map is+ process-wide, so a value must be resolved through the active profile's secret scope)."""+ return tuple(_SECRET_SOURCES)++def get_secret_source_values(hermes_home: str | os.PathLike) -> dict[str, str]:"""Return the external-secret value snapshot for ``hermes_home``."""return dict(_SECRET_SOURCE_VALUES_BY_HOME.get(str(Path(hermes_home).resolve()), {}))diff --git a/tests/tools/test_mcp_tool.py b/tests/tools/test_mcp_tool.pyindex 6df52dc48ac..7027d9e8ff0 100644--- a/tests/tools/test_mcp_tool.py+++ b/tests/tools/test_mcp_tool.py@@ -1392,6 +1392,29 @@ class TestBuildSafeEnv:assert result["NOTION_TOKEN"] == "from-op"assert "UNTRACKED_SECRET_KEY" not in result+ def test_secret_source_vars_resolve_through_active_profile_scope(self, monkeypatch):+ """Under multiplex the stdio child gets the ROUTED profile's value for a source-tagged name,+ never the launch profile's os.environ copy; a name the profile lacks is omitted."""+ from agent.secret_scope import set_multiplex_active, set_secret_scope, reset_secret_scope+ from hermes_cli import env_loader+ from tools.mcp_tool_config import _build_safe_env++ monkeypatch.setitem(env_loader._SECRET_SOURCES, "GITHUB_TOKEN", "bitwarden")+ monkeypatch.setitem(env_loader._SECRET_SOURCES, "NOTION_TOKEN", "onepassword")+ fake_env = {"PATH": "/usr/bin", "GITHUB_TOKEN": "default-profile", "NOTION_TOKEN": "default-notion"}+ set_multiplex_active(True)+ token = set_secret_scope({"GITHUB_TOKEN": "profile-b"})+ try:+ with patch.dict("os.environ", fake_env, clear=True):+ result = _build_safe_env(None)+ finally:+ reset_secret_scope(token)+ set_multiplex_active(False)++ assert result["PATH"] == "/usr/bin"+ assert result["GITHUB_TOKEN"] == "profile-b"+ assert "NOTION_TOKEN" not in result+def test_windows_location_vars_passed_without_secrets(self):"""Windows launcher tools need location vars, but secrets stay filtered."""from tools.mcp_tool_config import _build_safe_envdiff --git a/tools/mcp_tool_config.py b/tools/mcp_tool_config.pyindex 419385b727f..c981144ff00 100644--- a/tools/mcp_tool_config.py+++ b/tools/mcp_tool_config.py@@ -95,14 +95,18 @@ def _build_safe_env(user_env: Optional[dict]) -> dict:"""Filtered env for stdio subprocesses so API keys/tokens don't leak: the safe baselinekeys, ``XDG_*``, vars injected by an external secret source (users configured that backendprecisely so subprocesses can consume them), plus the server config's own ``env``."""- try:- from hermes_cli.env_loader import get_secret_source- except Exception: # pragma: no cover — early bootstrap/import fallback- get_secret_source = None+ from agent.secret_scope import get_secret+ from hermes_cli.env_loader import secret_source_namesenv = {key: value for key, value in os.environ.items()- if key in _SAFE_ENV_KEYS or key.upper() in _SAFE_ENV_KEYS_CASE_INSENSITIVE- or key.startswith("XDG_") or (get_secret_source is not None and get_secret_source(key))}+ if key in _SAFE_ENV_KEYS or key.upper() in _SAFE_ENV_KEYS_CASE_INSENSITIVE or key.startswith("XDG_")}+ # Source-tagged names are process-wide (any profile's hydration tags them) while os.environ+ # holds only the LAUNCH profile's values, so the value must come from the active profile's+ # secret scope; a profile that lacks the name gets nothing, never another profile's token.+ for key in secret_source_names():+ value = get_secret(key)+ if value is not None:+ env[key] = valuefor key in ("HERMES_KANBAN_DB", "HERMES_KANBAN_BOARD"):if key in os.environ:env[key] = os.environ[key]diff --git a/website/docs/user-guide/multi-profile-gateways.md b/website/docs/user-guide/multi-profile-gateways.mdindex cad5cccdcd8..7cc7b976d87 100644--- a/website/docs/user-guide/multi-profile-gateways.md+++ b/website/docs/user-guide/multi-profile-gateways.md@@ -212,8 +212,11 @@ keep working.Per-profile `.env` credential isolation is preserved and, if anything,stricter: a profile's keys are resolved from its own scope and are never unioned-into a shared environment (this also means subprocesses like MCP servers and-Kanban workers only ever see their own profile's secrets). Terminal settings+into a shared environment. Subprocesses like MCP servers and Kanban workers only+ever see their own profile's secrets — including credentials injected by an+external secret source (1Password, Bitwarden, …): a stdio MCP server started for+profile B receives B's value for such a name, or nothing if B has none, never the+default profile's. Terminal settings(`terminal.backend`, `terminal.cwd`, `terminal.docker_volumes`,`terminal.docker_shared_container_key`, SSH targets, …) are likewise resolvedper profile on every routed turn: a profile that omits a terminal key gets the