Skip to content

The agent that grows with you

fix(tui_gateway): profile-scoped RPCs bind the requested profile's secret + terminal scope

teknium10388d03f2257
diff --git a/tui_gateway/mcp_rpc_helpers.py b/tui_gateway/mcp_rpc_helpers.py
index 3b38c6a03cd..013a5133bc1 100644
--- a/tui_gateway/mcp_rpc_helpers.py
+++ b/tui_gateway/mcp_rpc_helpers.py
@@ -1,24 +1,14 @@
"""Shared helpers for the per-profile MCP lifecycle RPCs (mcp.servers.*).
-Published onto ``tui_gateway.server`` as ``_mcp_reset_profile`` /
-``_mcp_summarize_server`` so the rebound handler bodies in methods_tools resolve them.
+Published onto ``tui_gateway.server`` as ``_mcp_summarize_server`` so the rebound handler
+bodies in methods_tools resolve it.
"""
from __future__ import annotations
-import contextlib
from typing import Any, Dict
-def reset_profile(token) -> None:
- if token is None:
- return
- with contextlib.suppress(Exception):
- from hermes_constants import reset_hermes_home_override
-
- reset_hermes_home_override(token)
-
-
def summarize_server(name: str, cfg: dict) -> Dict[str, Any]:
"""Serialize one server's config for a UI (no secret values).
diff --git a/tui_gateway/methods_tools.py b/tui_gateway/methods_tools.py
index 70161a5a77c..9a9df6b4a35 100644
--- a/tui_gateway/methods_tools.py
+++ b/tui_gateway/methods_tools.py
@@ -5,6 +5,7 @@ bodies reference server globals bare (``_ok``, ``_err``, ``_sessions``, ...).
Helper names must not collide with server.py's own (``_cmd_`` / ``_toolset_`` / ``_mcp_`` prefixes).
"""
+import contextlib
import sys
from pathlib import Path
@@ -20,12 +21,20 @@ def _profile_scoped_rpc(
fail_code: int, *, required=(), catch_resolve: bool = True, prefix: str = "",
scoped: bool = True, live_session: bool = False,
):
- """Wrap a handler body with the optional ``profile`` HERMES_HOME scope. Order: ``required``
+ """Wrap a handler body with the optional ``profile`` runtime scope. Order: ``required``
params (4063 ``<key> required``) → ``live_session`` resolution via ``_sess`` (waits for the
agent build; body gets ``session`` as 3rd arg) → profile (4064 when its dir is missing) → body;
body exceptions become ``fail_code`` (``prefix`` + message). ``catch_resolve`` also maps
resolve-time exceptions to ``fail_code``; mcp.servers.* let them propagate to dispatch().
- ``scoped=False`` ignores ``profile``. The override is always reset afterwards."""
+ ``scoped=False`` ignores ``profile``.
+
+ The scope is the same home + secret + terminal composition a turn binds
+ (``_session_profile_runtime_scope``), not HERMES_HOME alone: these bodies read config.yaml,
+ whose ``${VAR}`` refs (``config._env_ref_lookup``) and the MCP probe's own header/env
+ interpolation resolve through ``get_secret`` — with only the home bound they read plain
+ ``os.environ``, i.e. the launch profile's values, so ``mcp.servers.test`` for a secondary
+ reported green against the default profile's token (or the literal placeholder). External
+ sources are hydrated first (the requested profile may never have been served in this process)."""
def deco(body):
def handler(rid, params: dict) -> dict:
@@ -38,7 +47,7 @@ def _profile_scoped_rpc(
if err:
return err
args = (rid, params, session)
- token = None
+ scope = contextlib.nullcontext()
if profile := _str_arg(params, "profile") if scoped else "":
try:
try:
@@ -47,17 +56,17 @@ def _profile_scoped_rpc(
profile_dir = None
if not profile_dir or not profile_dir.is_dir():
return _err(rid, 4064, f"profile '{profile}' not found")
- token = _tools_mod("hermes_constants").set_hermes_home_override(str(profile_dir))
+ _tools_mod("hermes_cli.env_loader").hydrate_profile_secret_sources(profile_dir)
+ scope = _session_profile_runtime_scope({"profile_home": str(profile_dir)})
except Exception as e:
if not catch_resolve:
raise
return _err(rid, fail_code, str(e))
try:
- return body(*args)
+ with scope:
+ return body(*args)
except Exception as e:
return _err(rid, fail_code, f"{prefix}{e}")
- finally:
- _mcp_reset_profile(token)
handler.__doc__ = body.__doc__
return handler
return deco
diff --git a/tui_gateway/server.py b/tui_gateway/server.py
index bafa526aa29..40de67816c3 100644
--- a/tui_gateway/server.py
+++ b/tui_gateway/server.py
@@ -3238,10 +3238,8 @@ def _resolve_name(name: str) -> str:
_paste_counter = 0
-# mcp.servers.* handlers (methods_tools) resolve these BARE through this namespace.
-from .mcp_rpc_helpers import ( # noqa: E402, F401
- reset_profile as _mcp_reset_profile,
- summarize_server as _mcp_summarize_server)
+# mcp.servers.* handlers (methods_tools) resolve this BARE through this namespace.
+from .mcp_rpc_helpers import summarize_server as _mcp_summarize_server # noqa: E402, F401
# ── Split @method handler modules (see method_ctx.py): imported last so every global the handlers close