The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(mcp): re-render a missed env ref from scratch every time
Teknium045b4fd43748
diff --git a/tests/tools/test_mcp_stdio_env_unset_ref.py b/tests/tools/test_mcp_stdio_env_unset_ref.pyindex e7d2006b7ed..b4a38ed7cc9 100644--- a/tests/tools/test_mcp_stdio_env_unset_ref.py+++ b/tests/tools/test_mcp_stdio_env_unset_ref.py@@ -30,6 +30,12 @@ def test_unset_whole_ref_counts_as_absent_and_set_values_pass_verbatim():assert result["PARTIAL"] == "${OPT_DIR}/bin"assert result["RESOLVED_LITERAL"] == "${STILL_UNSET}" # a set value is data, whatever it looks like+ # Unset at load, set (even to its own placeholder text) by connect: the re-render passes it.+ from tools.mcp_tool_config import _interpolate_env_vars+ loaded = _interpolate_env_vars({"FORWARD": "${LATE}"})+ with patch.dict("os.environ", {**PARENT, "LATE": "${LATE}"}, clear=True):+ assert _build_safe_env(_interpolate_env_vars(loaded))["FORWARD"] == "${LATE}"+def test_child_spawned_through_the_sdk_merge_sees_the_documented_env():from mcp.client.stdio import get_default_environmentdiff --git a/tools/mcp_tool_config.py b/tools/mcp_tool_config.pyindex 526b3e1875f..4bcb2ba8d82 100644--- a/tools/mcp_tool_config.py+++ b/tools/mcp_tool_config.py@@ -571,9 +571,9 @@ def _interpolate_env_vars(value):if not resolved:missed.append(m.group(0))return resolved or m.group(0)- text = _ENV_VAR_PATTERN.sub(_replace, template)- if text == template and not missed:+ if not _ENV_VAR_PATTERN.search(template):return value+ text = _ENV_VAR_PATTERN.sub(_replace, template)return _RenderedStr(text, template, missed=bool(missed), unset_ref=missed == [template])if isinstance(value, dict):return {k: _interpolate_env_vars(v) for k, v in value.items()}