From 7768fe9b0099bef182edad20c5103a60f2cfc1e0 Mon Sep 17 00:00:00 2001 From: tarunag10 Date: Thu, 20 Aug 2026 13:28:50 +0530 Subject: [PATCH] refactor: expose MCP chained-call helpers --- litellm/responses/mcp/chat_completions_handler.py | 4 ++-- litellm/responses/mcp/litellm_proxy_mcp_handler.py | 8 +++++--- litellm/responses/mcp/mcp_streaming_iterator.py | 2 +- .../responses/mcp/test_litellm_proxy_mcp_handler.py | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/litellm/responses/mcp/chat_completions_handler.py b/litellm/responses/mcp/chat_completions_handler.py index 764fe003f2c..cb6db1be9a4 100644 --- a/litellm/responses/mcp/chat_completions_handler.py +++ b/litellm/responses/mcp/chat_completions_handler.py @@ -453,7 +453,7 @@ async def acompletion_with_mcp( ) # Make follow-up call with streaming - follow_up_call_args: Final = LiteLLM_Proxy_MCP_Handler._prepare_follow_up_call_params( + follow_up_call_args: Final = LiteLLM_Proxy_MCP_Handler.prepare_follow_up_call_params( self.base_call_args, original_stream_setting=True, ) @@ -628,7 +628,7 @@ async def acompletion_with_mcp( ) # Make follow-up call with original stream setting - follow_up_call_args: Final = LiteLLM_Proxy_MCP_Handler._prepare_follow_up_call_params( + follow_up_call_args: Final = LiteLLM_Proxy_MCP_Handler.prepare_follow_up_call_params( base_call_args, original_stream_setting=stream, ) diff --git a/litellm/responses/mcp/litellm_proxy_mcp_handler.py b/litellm/responses/mcp/litellm_proxy_mcp_handler.py index f13bcece7ca..ad54796b102 100644 --- a/litellm/responses/mcp/litellm_proxy_mcp_handler.py +++ b/litellm/responses/mcp/litellm_proxy_mcp_handler.py @@ -72,7 +72,7 @@ class LiteLLM_Proxy_MCP_Handler: """ @staticmethod - def _prepare_chained_call_params( + def prepare_chained_call_params( params: Mapping[str, Any], ) -> dict[str, Any]: # mutable-ok: returns a sanitized copy for the next provider call """Copy request params without state owned by the previous LLM call. @@ -1261,14 +1261,14 @@ class LiteLLM_Proxy_MCP_Handler: return initial_params @staticmethod - def _prepare_follow_up_call_params(call_params: dict[str, Any], original_stream_setting: bool) -> dict[str, Any]: + def prepare_follow_up_call_params(call_params: dict[str, Any], original_stream_setting: bool) -> dict[str, Any]: """ Prepare call parameters for the follow-up LLM call after tool execution. Restores the original streaming setting and removes tool_choice since we're now providing tool results, not requesting tool calls. """ - follow_up_params: Final = LiteLLM_Proxy_MCP_Handler._prepare_chained_call_params(call_params) + follow_up_params: Final = LiteLLM_Proxy_MCP_Handler.prepare_chained_call_params(call_params) # Restore original streaming setting for follow-up call follow_up_params["stream"] = original_stream_setting @@ -1278,6 +1278,8 @@ class LiteLLM_Proxy_MCP_Handler: return follow_up_params + _prepare_follow_up_call_params = prepare_follow_up_call_params + @staticmethod def _add_mcp_output_elements_to_response( response: ResponsesAPIResponse, diff --git a/litellm/responses/mcp/mcp_streaming_iterator.py b/litellm/responses/mcp/mcp_streaming_iterator.py index 1e1cbd34ce2..9dae0254d30 100644 --- a/litellm/responses/mcp/mcp_streaming_iterator.py +++ b/litellm/responses/mcp/mcp_streaming_iterator.py @@ -782,7 +782,7 @@ class MCPEnhancedStreamingIterator(BaseResponsesAPIStreamingIterator): ) # Make follow-up call with streaming - follow_up_params: Final = LiteLLM_Proxy_MCP_Handler._prepare_chained_call_params( + follow_up_params: Final = LiteLLM_Proxy_MCP_Handler.prepare_chained_call_params( self.original_request_params ) follow_up_params.update( diff --git a/tests/test_litellm/responses/mcp/test_litellm_proxy_mcp_handler.py b/tests/test_litellm/responses/mcp/test_litellm_proxy_mcp_handler.py index f2658a1b0a5..5006ea58087 100644 --- a/tests/test_litellm/responses/mcp/test_litellm_proxy_mcp_handler.py +++ b/tests/test_litellm/responses/mcp/test_litellm_proxy_mcp_handler.py @@ -459,7 +459,7 @@ def test_prepare_follow_up_call_params_resets_per_call_logging_state(): }, } - follow_up = LiteLLM_Proxy_MCP_Handler._prepare_follow_up_call_params(original, original_stream_setting=True) + follow_up = LiteLLM_Proxy_MCP_Handler.prepare_follow_up_call_params(original, original_stream_setting=True) assert "litellm_call_id" not in follow_up assert "litellm_logging_obj" not in follow_up