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(mcp): require every reference to opt in before auto-executing tools

Tin Chi Locf23df94313a
diff --git a/litellm/responses/mcp/litellm_proxy_mcp_handler.py b/litellm/responses/mcp/litellm_proxy_mcp_handler.py
index d2c9f220690..a94cd2413d8 100644
--- a/litellm/responses/mcp/litellm_proxy_mcp_handler.py
+++ b/litellm/responses/mcp/litellm_proxy_mcp_handler.py
@@ -478,17 +478,25 @@ class LiteLLM_Proxy_MCP_Handler:
) -> bool:
"""Check if we should auto-execute tool calls.
- Only auto-execute tools if user passed a MCP tool with require_approval set to "never".
-
-
+ Auto-execution requires EVERY MCP reference to opt in with
+ ``require_approval="never"``. A single reference that requires approval
+ ("always", "manual", the object form, or an unset value) disables
+ auto-execution for the whole request. This fails closed: when an
+ approval-required reference shares a request with a "never" one, the
+ model's tool calls are returned to the caller instead of being run, so
+ an approval-gated tool can never be invoked without approval. Returns
+ False for an empty list.
"""
- for tool in mcp_tools_with_litellm_proxy:
- if isinstance(tool, dict):
- if tool.get("require_approval") == "never":
- return True
- elif getattr(tool, "require_approval", None) == "never":
- return True
- return False
+ references = list(mcp_tools_with_litellm_proxy or [])
+ if not references:
+ return False
+ for tool in references:
+ approval = (
+ tool.get("require_approval") if isinstance(tool, dict) else getattr(tool, "require_approval", None)
+ )
+ if approval != "never":
+ return False
+ return True
@staticmethod
def _extract_tool_calls_from_response(response: ResponsesAPIResponse) -> List[Any]:
diff --git a/tests/mcp_tests/test_aresponses_api_with_mcp.py b/tests/mcp_tests/test_aresponses_api_with_mcp.py
index 9cd45f3d6fc..32295310005 100644
--- a/tests/mcp_tests/test_aresponses_api_with_mcp.py
+++ b/tests/mcp_tests/test_aresponses_api_with_mcp.py
@@ -86,6 +86,15 @@ async def test_mcp_helper_methods():
LiteLLM_Proxy_MCP_Handler._should_auto_execute_tools(mcp_tools_always) == False
)
+ # A single approval-required reference must disable auto-execution for the
+ # whole request; otherwise a "never" reference alongside an "always" one
+ # would let the approval-gated tool run without approval.
+ mcp_tools_mixed = [{"require_approval": "never"}, {"require_approval": "always"}]
+ assert LiteLLM_Proxy_MCP_Handler._should_auto_execute_tools(mcp_tools_mixed) == False
+ mcp_tools_manual = [{"require_approval": "never"}, {"require_approval": "manual"}]
+ assert LiteLLM_Proxy_MCP_Handler._should_auto_execute_tools(mcp_tools_manual) == False
+ assert LiteLLM_Proxy_MCP_Handler._should_auto_execute_tools([]) == False
+
print("✓ MCP helper methods test passed!")