diff --git a/mcpgateway/admin.py b/mcpgateway/admin.py index c513761494..dc07b20693 100644 --- a/mcpgateway/admin.py +++ b/mcpgateway/admin.py @@ -12339,15 +12339,16 @@ async def admin_edit_gateway( auth_headers = [] # Handle passthrough_headers - passthrough_headers = str(form.get("passthrough_headers")) - if passthrough_headers and passthrough_headers.strip(): + # Use [] (empty list) to signal "user cleared the field" vs None (not provided) + passthrough_headers_raw = form.get("passthrough_headers") + passthrough_headers_str = str(passthrough_headers_raw) if passthrough_headers_raw else "" + passthrough_headers: Optional[List[str]] = [] + if passthrough_headers_str.strip(): try: - passthrough_headers = orjson.loads(passthrough_headers) + passthrough_headers = orjson.loads(passthrough_headers_str) except (orjson.JSONDecodeError, ValueError): # Fallback to comma-separated parsing - passthrough_headers = [h.strip() for h in passthrough_headers.split(",") if h.strip()] - else: - passthrough_headers = None + passthrough_headers = [h.strip() for h in passthrough_headers_str.split(",") if h.strip()] # Parse OAuth configuration - support both JSON string and individual form fields oauth_config_json = str(form.get("oauth_config")) diff --git a/mcpgateway/services/gateway_service.py b/mcpgateway/services/gateway_service.py index 90c488e385..f18c7a922b 100644 --- a/mcpgateway/services/gateway_service.py +++ b/mcpgateway/services/gateway_service.py @@ -2144,11 +2144,12 @@ async def update_gateway( prompt.visibility = gateway.visibility if gateway_update.passthrough_headers is not None: if isinstance(gateway_update.passthrough_headers, list): - gateway.passthrough_headers = gateway_update.passthrough_headers + # [] means "user cleared the field" → store None in DB + gateway.passthrough_headers = gateway_update.passthrough_headers if gateway_update.passthrough_headers else None else: if isinstance(gateway_update.passthrough_headers, str): parsed: List[str] = [h.strip() for h in gateway_update.passthrough_headers.split(",") if h.strip()] - gateway.passthrough_headers = parsed + gateway.passthrough_headers = parsed if parsed else None else: raise GatewayError("Invalid passthrough_headers format: must be list[str] or comma-separated string")