From 47ef6a7ee676064a02f21148fd2719ea1e7ae1bf Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Sat, 27 Sep 2025 09:02:08 -0700 Subject: [PATCH] fix(mcp/): pass oauth2 headers on call tools --- litellm/experimental_mcp_client/client.py | 3 +++ litellm/proxy/_experimental/mcp_server/server.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/litellm/experimental_mcp_client/client.py b/litellm/experimental_mcp_client/client.py index d4db9251fc..2e02f460b6 100644 --- a/litellm/experimental_mcp_client/client.py +++ b/litellm/experimental_mcp_client/client.py @@ -117,6 +117,9 @@ class MCPClient: await self._session.initialize() else: # http headers = self._get_auth_headers() + verbose_logger.debug( + "litellm headers for streamablehttp_client: ", headers + ) self._transport_ctx = streamablehttp_client( url=self.server_url, timeout=timedelta(seconds=self.timeout), diff --git a/litellm/proxy/_experimental/mcp_server/server.py b/litellm/proxy/_experimental/mcp_server/server.py index f79d40ca61..7f16179390 100644 --- a/litellm/proxy/_experimental/mcp_server/server.py +++ b/litellm/proxy/_experimental/mcp_server/server.py @@ -270,6 +270,7 @@ if MCP_AVAILABLE: user_api_key_auth=user_api_key_auth, mcp_auth_header=mcp_auth_header, mcp_server_auth_headers=mcp_server_auth_headers, + oauth2_headers=oauth2_headers, **data, # for logging ) except BlockedPiiEntityError as e: @@ -505,6 +506,7 @@ if MCP_AVAILABLE: user_api_key_auth: Optional[UserAPIKeyAuth] = None, mcp_auth_header: Optional[str] = None, mcp_server_auth_headers: Optional[Dict[str, str]] = None, + oauth2_headers: Optional[Dict[str, str]] = None, **kwargs: Any, ) -> List[Union[TextContent, ImageContent, EmbeddedResource]]: """ @@ -552,6 +554,7 @@ if MCP_AVAILABLE: user_api_key_auth=user_api_key_auth, mcp_auth_header=mcp_auth_header, mcp_server_auth_headers=mcp_server_auth_headers, + oauth2_headers=oauth2_headers, litellm_logging_obj=litellm_logging_obj, ) @@ -604,6 +607,7 @@ if MCP_AVAILABLE: user_api_key_auth: Optional[UserAPIKeyAuth] = None, mcp_auth_header: Optional[str] = None, mcp_server_auth_headers: Optional[Dict[str, str]] = None, + oauth2_headers: Optional[Dict[str, str]] = None, litellm_logging_obj: Optional[Any] = None, ) -> List[Union[TextContent, ImageContent, EmbeddedResource]]: """Handle tool execution for managed server tools""" @@ -616,6 +620,7 @@ if MCP_AVAILABLE: user_api_key_auth=user_api_key_auth, mcp_auth_header=mcp_auth_header, mcp_server_auth_headers=mcp_server_auth_headers, + oauth2_headers=oauth2_headers, proxy_logging_obj=proxy_logging_obj, ) verbose_logger.debug("CALL TOOL RESULT: %s", call_tool_result)