diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py index 5799ff6bfb0..c622c85321d 100644 --- a/litellm/litellm_core_utils/litellm_logging.py +++ b/litellm/litellm_core_utils/litellm_logging.py @@ -4768,16 +4768,18 @@ class StandardLoggingPayloadSetup: if proxy_server_request is not None: _request_headers = proxy_server_request.get("headers", {}) if _request_headers and isinstance(_request_headers, dict): + _sensitive_x_header = re.compile( + r"^(x-litellm-api-key|x-api-key|x-goog-api-key" + r"|x-mcp-(auth|servers|access-groups)" + r"|x-mcp-.+-(authorization|x-api-key))$" + ) custom_headers = { k: v for k, v in _request_headers.items() if k.lower().startswith("x-") and v is not None and isinstance(v, str) - and not re.match( - r"^x-mcp-.+-(authorization|x-api-key)$", - k.lower(), - ) + and not _sensitive_x_header.match(k.lower()) } if custom_headers: clean_metadata["requester_custom_headers"] = custom_headers diff --git a/litellm/proxy/_experimental/mcp_server/server.py b/litellm/proxy/_experimental/mcp_server/server.py index bcbf4f75ef9..73c4bc0ab44 100644 --- a/litellm/proxy/_experimental/mcp_server/server.py +++ b/litellm/proxy/_experimental/mcp_server/server.py @@ -378,9 +378,6 @@ if MCP_AVAILABLE: body_data["litellm_trace_id"] = chain_id body_data["litellm_session_id"] = chain_id - _scope_headers: list[tuple[bytes, bytes]] = [ - (b"content-type", b"application/json"), - ] _scope_headers: list[tuple[bytes, bytes]] = [ (b"content-type", b"application/json"), ] @@ -391,6 +388,13 @@ if MCP_AVAILABLE: _scope_headers.append( (k.lower().encode("latin-1"), v.encode("latin-1")) ) + request = Request( + scope={ + "type": "http", + "method": "POST", + "path": "/mcp/tools/call", + "headers": _scope_headers, + } ) if user_api_key_auth is not None: data = await add_litellm_data_to_request(