diff --git a/litellm/responses/mcp/litellm_proxy_mcp_handler.py b/litellm/responses/mcp/litellm_proxy_mcp_handler.py index 6254e60bf20..46bb067eeeb 100644 --- a/litellm/responses/mcp/litellm_proxy_mcp_handler.py +++ b/litellm/responses/mcp/litellm_proxy_mcp_handler.py @@ -4,6 +4,9 @@ from collections.abc import Iterable, Mapping, Sequence from datetime import datetime from typing import TYPE_CHECKING, Any, Final, Literal, Optional, TypeAlias, TypedDict, overload +from openai.types.chat import ChatCompletionToolParam +from openai.types.responses.function_tool_param import FunctionToolParam + from litellm._logging import verbose_logger from litellm.constants import MAXIMUM_TRACEBACK_LINES_TO_LOG from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj @@ -30,14 +33,13 @@ from litellm.types.utils import ( StandardLoggingMCPToolCall, ) from litellm.utils import Rules, function_setup -from openai.types.chat import ChatCompletionToolParam -from openai.types.responses.function_tool_param import FunctionToolParam if TYPE_CHECKING: - from litellm.proxy._types import UserAPIKeyAuth - from litellm.proxy.utils import ProxyLogging from mcp.types import CallToolResult from mcp.types import Tool as MCPTool + + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.utils import ProxyLogging else: MCPTool = Any @@ -667,6 +669,7 @@ class LiteLLM_Proxy_MCP_Handler: ) -> list[MCPToolResult]: """Execute tool calls and return results.""" from fastapi import HTTPException + from litellm._uuid import uuid from litellm.exceptions import BlockedPiiEntityError, GuardrailRaisedException from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( diff --git a/litellm/responses/mcp/mcp_streaming_iterator.py b/litellm/responses/mcp/mcp_streaming_iterator.py index 8534e13aa06..69e698f7f65 100644 --- a/litellm/responses/mcp/mcp_streaming_iterator.py +++ b/litellm/responses/mcp/mcp_streaming_iterator.py @@ -22,9 +22,10 @@ from litellm.types.llms.openai import ( ) if TYPE_CHECKING: + from mcp.types import Tool as MCPTool + from litellm.proxy._types import UserAPIKeyAuth from litellm.responses.mcp.litellm_proxy_mcp_handler import MCPToolResult - from mcp.types import Tool as MCPTool else: MCPTool = Any @@ -330,10 +331,11 @@ class MCPEnhancedStreamingIterator(BaseResponsesAPIStreamingIterator): def _extract_mcp_headers_from_params(self) -> None: """Extract MCP headers from original request params to pass to tool calls""" + from starlette.datastructures import Headers + from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from starlette.datastructures import Headers # Extract headers from secret_fields in original_request_params raw_headers_from_request: dict[str, str] | None = None