The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
perf: use reusable http client
Krrish Dholakia9ced18b69518
diff --git a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.pyindex b42364b6db8..71f1fab13bc 100644--- a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py+++ b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py@@ -14,8 +14,8 @@ import refrom typing import Any, Dict, List, Optional, Set, Tuple, Union, castfrom urllib.parse import urlparse-from fastapi import HTTPExceptionimport httpx+from fastapi import HTTPExceptionfrom httpx import HTTPStatusErrorfrom mcp.types import CallToolRequestParams as MCPCallToolRequestParamsfrom mcp.types import CallToolResult@@ -24,6 +24,7 @@ from mcp.types import Tool as MCPToolfrom litellm._logging import verbose_loggerfrom litellm.exceptions import BlockedPiiEntityError, GuardrailRaisedExceptionfrom litellm.experimental_mcp_client.client import MCPClient+from litellm.llms.custom_httpx.http_handler import get_async_httpx_clientfrom litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import (MCPRequestHandler,)@@ -42,10 +43,9 @@ from litellm.proxy._types import (MCPTransportType,UserAPIKeyAuth,)-from litellm.proxy.common_utils.encrypt_decrypt_utils import (- decrypt_value_helper,-)+from litellm.proxy.common_utils.encrypt_decrypt_utils import decrypt_value_helperfrom litellm.proxy.utils import ProxyLogging+from litellm.types.llms.custom_http import httpxSpecialProviderfrom litellm.types.mcp import MCPAuth, MCPStdioConfigfrom litellm.types.mcp_server.mcp_server_manager import (MCPInfo,@@ -386,12 +386,12 @@ class MCPServerManager:)# Update tool name to server name mapping (for both prefixed and base names)- self.tool_name_to_mcp_server_name_mapping[- base_tool_name- ] = server_prefix- self.tool_name_to_mcp_server_name_mapping[- prefixed_tool_name- ] = server_prefix+ self.tool_name_to_mcp_server_name_mapping[base_tool_name] = (+ server_prefix+ )+ self.tool_name_to_mcp_server_name_mapping[prefixed_tool_name] = (+ server_prefix+ )registered_count += 1verbose_logger.debug(@@ -729,11 +729,9 @@ class MCPServerManager:"""Discover OAuth metadata by following RFC 9728 (protected resource metadata discovery)."""try:- async with httpx.AsyncClient(- timeout=10.0, follow_redirects=False- ) as client:- response = await client.get(server_url)- response.raise_for_status()+ client = get_async_httpx_client(llm_provider=httpxSpecialProvider.MCP)+ response = await client.get(server_url)+ response.raise_for_status()verbose_logger.warning("MCP OAuth discovery unexpectedly succeeded for %s; server did not challenge",server_url,diff --git a/litellm/types/llms/custom_http.py b/litellm/types/llms/custom_http.pyindex 6b86f55e025..46956fedc8e 100644--- a/litellm/types/llms/custom_http.py+++ b/litellm/types/llms/custom_http.py@@ -22,6 +22,7 @@ class httpxSpecialProvider(str, Enum):PromptFactory = "prompt_factory"SSO_HANDLER = "sso_handler"Search = "search"+ MCP = "mcp"VerifyTypes = Union[str, bool, ssl.SSLContext]