diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py index 67866d7ff7f..6d6ca8b1e3a 100644 --- a/litellm/litellm_core_utils/litellm_logging.py +++ b/litellm/litellm_core_utils/litellm_logging.py @@ -2658,14 +2658,10 @@ class Logging(LiteLLMLoggingBaseClass): # An MCP tool call that fails at the tool level (CallToolResult.isError) # likewise still incurs the configured per-query cost, computed before # this handler runs; don't zero it like a generic failed LLM call. - preserve_mcp_cost = ( - self.call_type == CallTypes.call_mcp_tool.value - and self.model_call_details.get("response_cost") + preserve_mcp_cost = self.call_type == CallTypes.call_mcp_tool.value and self.model_call_details.get( + "response_cost" ) - if ( - self.model_call_details.get("combined_usage_object") is None - and not preserve_mcp_cost - ): + if self.model_call_details.get("combined_usage_object") is None and not preserve_mcp_cost: self.model_call_details["response_cost"] = 0 if hasattr(exception, "headers") and isinstance(exception.headers, dict): diff --git a/litellm/proxy/_experimental/mcp_server/server.py b/litellm/proxy/_experimental/mcp_server/server.py index da102499b6a..6d9e20f2b5d 100644 --- a/litellm/proxy/_experimental/mcp_server/server.py +++ b/litellm/proxy/_experimental/mcp_server/server.py @@ -181,9 +181,7 @@ def _mcp_session_id_from_headers( def _mcp_content_block_text(block: object) -> Optional[str]: """The ``text`` of an MCP content block (``TextContent`` object or ``dict``), or ``None`` when the block carries no usable text.""" - text = ( - block.get("text") if isinstance(block, dict) else getattr(block, "text", None) - ) + text = block.get("text") if isinstance(block, dict) else getattr(block, "text", None) return text if isinstance(text, str) and text else None @@ -2558,9 +2556,7 @@ if MCP_AVAILABLE: content = getattr(response, "content", None) or () if not is_error: return None - texts = tuple( - text for block in content if (text := _mcp_content_block_text(block)) - ) + texts = tuple(text for block in content if (text := _mcp_content_block_text(block))) return "\n".join(texts) or "MCP tool call returned an error result" @client