Skip to content

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]

fix: prevent MCP type objects from being captured in locals()

Yuta Saito9d173ba4fe5d
diff --git a/litellm/main.py b/litellm/main.py
index e32d05a81d0..969cf55a3d6 100644
--- a/litellm/main.py
+++ b/litellm/main.py
@@ -1095,6 +1095,9 @@ def completion( # type: ignore # noqa: PLR0915
# validate tool_choice
tool_choice = validate_chat_completion_tool_choice(tool_choice=tool_choice)
+ ######### unpacking kwargs #####################
+ args = locals()
+
skip_mcp_handler = kwargs.pop("_skip_mcp_handler", False)
if not skip_mcp_handler and tools:
from litellm.responses.mcp.chat_completions_handler import (
@@ -1154,8 +1157,6 @@ def completion( # type: ignore # noqa: PLR0915
shared_session=shared_session,
**kwargs,
)
- ######### unpacking kwargs #####################
- args = locals()
api_base = kwargs.get("api_base", None)
mock_response: Optional[MOCK_RESPONSE_TYPE] = kwargs.get("mock_response", None)
mock_tool_calls = kwargs.get("mock_tool_calls", None)