@@ -172,6 +172,16 @@ async def call_tool(self, *args: Any, **kwargs: Any) -> Any:
172172ClientParamsMap = dict [str , tuple [dict [str , Any ], list [str ], str | None , int | None ]]
173173
174174
175+ def _env_names (env : dict [str , Any ] | None ) -> list [str ] | None :
176+ """Return only the environment variable names, for safe debug logging.
177+
178+ Tool-call environments routinely carry credentials (e.g. ``GH_TOKEN``), so
179+ their values must never be written to logs. Callers log the names to keep
180+ debug output useful without leaking secrets.
181+ """
182+ return sorted (env ) if env is not None else None
183+
184+
175185def mcp_client_params (
176186 available_tools : AvailableTools ,
177187 requested_toolboxes : list [str ],
@@ -202,7 +212,7 @@ def mcp_client_params(
202212 case "stdio" :
203213 env = dict (sp .env ) if sp .env else None
204214 args = list (sp .args ) if sp .args else None
205- logging .debug ("Initializing toolbox: %s\n args:\n %s\n env:\n %s\n " , tb , args , env )
215+ logging .debug ("Initializing toolbox: %s\n args:\n %s\n env names :\n %s\n " , tb , args , _env_names ( env ) )
206216 if env :
207217 for k , v in list (env .items ()):
208218 try :
@@ -217,7 +227,7 @@ def mcp_client_params(
217227 "http_proxy" , "https_proxy" , "no_proxy" ):
218228 if proxy_var not in env and proxy_var in os .environ :
219229 env [proxy_var ] = os .environ [proxy_var ]
220- logging .debug ("Tool call environment: %s" , env )
230+ logging .debug ("Tool call environment names : %s" , _env_names ( env ) )
221231 if args :
222232 for i , v in enumerate (args ):
223233 args [i ] = swap_env (v )
@@ -241,7 +251,7 @@ def mcp_client_params(
241251 if sp .command is not None :
242252 env = dict (sp .env ) if sp .env else None
243253 args = list (sp .args ) if sp .args else None
244- logging .debug ("Initializing streamable toolbox: %s\n args:\n %s\n env:\n %s\n " , tb , args , env )
254+ logging .debug ("Initializing streamable toolbox: %s\n args:\n %s\n env names :\n %s\n " , tb , args , _env_names ( env ) )
245255 exe = shutil .which (sp .command )
246256 if exe is None :
247257 raise FileNotFoundError (f"Could not resolve path to { sp .command } " )
0 commit comments