@@ -1515,17 +1515,10 @@ def test_load_mcp_servers_with_env_vars(tmp_path: Path, monkeypatch: pytest.Monk
15151515 assert server .id == 'my_server'
15161516 assert server .tool_prefix == 'my_server'
15171517
1518- # Test with environment variables in URL
1519- monkeypatch .setenv ('SERVER_HOST' , 'example.com' )
1520- monkeypatch .setenv ('SERVER_PORT' , '8080' )
1521- config .write_text ('{"mcpServers": {"web_server": {"url": "https://${SERVER_HOST}:${SERVER_PORT}/mcp"}}}' )
15221518
1523- servers = load_mcp_servers (config )
1524-
1525- assert len (servers ) == 1
1526- server = servers [0 ]
1527- assert isinstance (server , MCPServerStreamableHTTP )
1528- assert server .url == 'https://example.com:8080/mcp'
1519+ def test_load_mcp_servers_env_var_in_env_dict (tmp_path : Path , monkeypatch : pytest .MonkeyPatch ):
1520+ """Test environment variable expansion in env dict."""
1521+ config = tmp_path / 'mcp.json'
15291522
15301523 # Test with environment variables in env dict
15311524 monkeypatch .setenv ('API_KEY' , 'secret123' )
@@ -1542,6 +1535,23 @@ def test_load_mcp_servers_with_env_vars(tmp_path: Path, monkeypatch: pytest.Monk
15421535 assert server .env == {'API_KEY' : 'secret123' }
15431536
15441537
1538+ def test_load_mcp_servers_env_var_expansion_url (tmp_path : Path , monkeypatch : pytest .MonkeyPatch ):
1539+ """Test environment variable expansion in URL."""
1540+ config = tmp_path / 'mcp.json'
1541+
1542+ # Test with environment variables in URL
1543+ monkeypatch .setenv ('SERVER_HOST' , 'example.com' )
1544+ monkeypatch .setenv ('SERVER_PORT' , '8080' )
1545+ config .write_text ('{"mcpServers": {"web_server": {"url": "https://${SERVER_HOST}:${SERVER_PORT}/mcp"}}}' )
1546+
1547+ servers = load_mcp_servers (config )
1548+
1549+ assert len (servers ) == 1
1550+ server = servers [0 ]
1551+ assert isinstance (server , MCPServerStreamableHTTP )
1552+ assert server .url == 'https://example.com:8080/mcp'
1553+
1554+
15451555def test_load_mcp_servers_undefined_env_var (tmp_path : Path , monkeypatch : pytest .MonkeyPatch ):
15461556 """Test that undefined environment variables raise an error."""
15471557 config = tmp_path / 'mcp.json'
0 commit comments