diff --git a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py index 377e5acf8ad..b66126490f5 100644 --- a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py +++ b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py @@ -1438,8 +1438,14 @@ def _raise_single_server_list_failure(error: Exception, server: MCPServer) -> No case MCPUpstreamAuthError() | MCPServerListError(): raise error case HTTPException() if error.status_code in (401, 403): - headers: Final = error.headers or {} - challenge_header: Final = headers.get("WWW-Authenticate") or headers.get("www-authenticate") + challenge_header: Final = next( + ( + value + for name, value in (error.headers.items() if error.headers else ()) + if name.lower() == "www-authenticate" + ), + None, + ) raise MCPUpstreamAuthError( status_code=error.status_code, www_authenticate=None if server.is_dcr_bridge else challenge_header, @@ -4527,10 +4533,10 @@ class MCPServerManager: ) has_static_authorization: Final = any( - isinstance(k, str) and k.lower() == "authorization" for k in (server.static_headers or {}) + isinstance(k, str) and k.lower() == "authorization" for k in (server.static_headers or ()) ) has_extra_authorization: Final = any( - isinstance(k, str) and k.lower() == "authorization" for k in (extra_headers or {}) + isinstance(k, str) and k.lower() == "authorization" for k in (extra_headers or ()) ) if get_mcp_jwt_signer() is None or has_static_authorization or mcp_auth_header or has_extra_authorization: return _ListHeaders(headers, signed_for_user=False) @@ -4540,7 +4546,7 @@ class MCPServerManager: raw_headers=raw_headers, for_list_tools=True, ) - unsigned_items: Final = frozenset((headers or {}).items()) + unsigned_items: Final = frozenset(headers.items() if headers else ()) return _ListHeaders( signed, signed_for_user=True, diff --git a/litellm/proxy/_experimental/mcp_server/rest_endpoints.py b/litellm/proxy/_experimental/mcp_server/rest_endpoints.py index 2f3fcb88be5..1f7cc29e7e2 100644 --- a/litellm/proxy/_experimental/mcp_server/rest_endpoints.py +++ b/litellm/proxy/_experimental/mcp_server/rest_endpoints.py @@ -1150,7 +1150,7 @@ if MCP_AVAILABLE: }, ) - @router.get("/prompts/list", dependencies=[Depends(user_api_key_auth)]) + @router.get("/prompts/list", dependencies=(Depends(user_api_key_auth),)) async def list_prompts_rest_api( request: Request, server_id: Annotated[str, Query(description="The MCP server id, name, or alias to list prompts for")], @@ -1176,7 +1176,7 @@ if MCP_AVAILABLE: raise _catalog_list_http_exception(e, context.server, "prompts") from e return ListMCPPromptsRestAPIResponse.from_prompts(prompts) - @router.get("/resources/list", dependencies=[Depends(user_api_key_auth)]) + @router.get("/resources/list", dependencies=(Depends(user_api_key_auth),)) async def list_resources_rest_api( request: Request, server_id: Annotated[str, Query(description="The MCP server id, name, or alias to list resources for")],