2424Tests for Streamlit helpers MCP configuration bugs.
2525
2626Bug 1: load_mcp_server_configs() does not interpolate ${ENV_VAR} patterns.
27- Bug 2: test_mcp_connection() does not include system env vars in subprocess .
27+ Bug 2: test_mcp_connection() leaks full process env to subprocesses .
2828"""
2929
3030import json
@@ -139,12 +139,13 @@ def test_missing_env_var_without_default_returns_empty(self, monkeypatch):
139139
140140
141141class TestMcpConnectionSubprocessEnv :
142- """Bug 2: test_mcp_connection() should pass full system env to subprocess """
142+ """Bug 2: test_mcp_connection() should avoid leaking full process env"""
143143
144144 @pytest .mark .asyncio
145145 async def test_subprocess_env_includes_system_path (self , monkeypatch ):
146- """StdioServerParams.env should contain both custom and system env vars"""
146+ """StdioServerParams.env should contain custom env and safe default vars"""
147147 monkeypatch .setenv ("PATH" , "/usr/bin:/usr/local/bin" )
148+ monkeypatch .setenv ("UNRELATED_OAUTH_CLIENT_SECRET" , "oauth-secret-not-for-mcp" )
148149
149150 config = MCPServerConfig (
150151 name = "test-server" ,
@@ -175,11 +176,13 @@ def capture_workbench(server_params):
175176 assert params .env ["CUSTOM_KEY" ] == "custom_val"
176177 assert "PATH" in params .env
177178 assert params .env ["PATH" ] == "/usr/bin:/usr/local/bin"
179+ assert "UNRELATED_OAUTH_CLIENT_SECRET" not in params .env
178180
179181 @pytest .mark .asyncio
180- async def test_subprocess_env_with_no_config_env_gets_system_env (self , monkeypatch ):
181- """Even with env=None in config, subprocess should get system env """
182+ async def test_subprocess_env_with_no_config_env_gets_safe_default_env (self , monkeypatch ):
183+ """Even with env=None in config, subprocess should only get safe defaults """
182184 monkeypatch .setenv ("PATH" , "/usr/bin:/usr/local/bin" )
185+ monkeypatch .setenv ("PEAK_GLOBAL_SECRET" , "global-secret-not-for-mcp" )
183186
184187 config = MCPServerConfig (
185188 name = "test-server" ,
@@ -206,3 +209,5 @@ def capture_workbench(server_params):
206209 assert success is True
207210 params = captured_params ["server_params" ]
208211 assert "PATH" in params .env
212+ assert params .env ["PATH" ] == "/usr/bin:/usr/local/bin"
213+ assert "PEAK_GLOBAL_SECRET" not in params .env
0 commit comments