@@ -67,18 +67,25 @@ def to_dict(self) -> Dict:
6767 # We keep it for backwards compatibility
6868 return self .model_dump (exclude_none = True )
6969
70- def get_filtered_env_vars (self ) -> Dict [str , str ]:
70+ def get_filtered_env_vars (self , env : Dict [ str , str ] ) -> Dict [str , str ]:
7171 """Get filtered environment variables with empty values removed
7272
7373 This is a utility for clients to filter out empty environment
7474 variables, regardless of client-specific formatting.
7575
76+ Args:
77+ env: Dictionary of environment variables to use for resolving
78+ ${VAR_NAME} references.
79+
7680 Returns:
7781 Dictionary of non-empty environment variables
7882 """
7983 if not self .env_vars :
8084 return {}
8185
86+ # Use provided environment without falling back to os.environ
87+ environment = env
88+
8289 # Filter out empty environment variables
8390 non_empty_env = {}
8491 for key , value in self .env_vars .items ():
@@ -88,7 +95,7 @@ def get_filtered_env_vars(self) -> Dict[str, str]:
8895 if value .startswith ("${" ) and value .endswith ("}" ):
8996 # Extract the variable name from ${VAR_NAME}
9097 env_var_name = value [2 :- 1 ]
91- env_value = os . environ .get (env_var_name , "" )
98+ env_value = environment .get (env_var_name , "" )
9299 # Only include if the variable has a value in the environment
93100 if env_value .strip () != "" :
94101 non_empty_env [key ] = value
0 commit comments