@@ -288,24 +288,27 @@ def _serialize_with_mcp_handling(self, handler, info: SerializationInfo):
288288 # - expose_secrets=True: keep as-is (explicitly requested)
289289 # - cipher present: encrypt and store in encrypted_mcp_config, omit original
290290 # - default: omit (redact sensitive data)
291- if self .mcp_config : # Only process non-empty configs
292- if info .context and info .context .get ("expose_secrets" ):
293- # Keep mcp_config as-is (already in result from handler)
294- pass
295- elif info .context and info .context .get ("cipher" ):
296- # Encrypt and add encrypted_mcp_config
297- cipher : Cipher = info .context ["cipher" ]
298- json_str = json .dumps (self .mcp_config )
299- encrypted = cipher .encrypt (SecretStr (json_str ))
300- if encrypted :
301- result ["encrypted_mcp_config" ] = encrypted
302- # Remove plaintext mcp_config
303- result .pop ("mcp_config" , None )
304- else :
305- # Default: redact by omitting
306- result .pop ("mcp_config" , None )
307-
308- return result
291+ if not self .mcp_config : # Only process non-empty configs
292+ result .pop ("mcp_config" , None )
293+ return result
294+ elif info .context and info .context .get ("expose_secrets" ):
295+ # Keep mcp_config as-is (already in result from handler)
296+ return result
297+ elif info .context and info .context .get ("cipher" ):
298+ # Encrypt and add encrypted_mcp_config
299+ cipher : Cipher = info .context ["cipher" ]
300+ json_str = json .dumps (self .mcp_config )
301+ encrypted = cipher .encrypt (SecretStr (json_str ))
302+ if encrypted :
303+ result ["encrypted_mcp_config" ] = encrypted
304+ # Remove plaintext mcp_config
305+ result .pop ("mcp_config" , None )
306+ return result
307+ else :
308+ # Default: redact by omitting
309+ result .pop ("mcp_config" , None )
310+ return result
311+
309312
310313 condenser : CondenserBase | None = Field (
311314 default = None ,
0 commit comments