Skip to content

Commit ea377de

Browse files
committed
fixes mypy linting
1 parent a13aa47 commit ea377de

File tree

3 files changed

+39
-33
lines changed

3 files changed

+39
-33
lines changed

litellm/llms/databricks/chat/transformation.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def convert_anthropic_tool_to_databricks_tool(
180180

181181
return DatabricksTool(
182182
type="function",
183-
function=DatabricksFunction(**kwags),
183+
function=DatabricksFunction(name=tool["name"], **kwags),
184184
)
185185

186186
def _map_openai_to_dbrx_tool(self, model: str, tools: List) -> List[DatabricksTool]:
@@ -338,7 +338,8 @@ def extract_content_str(
338338
content_str = ""
339339
for item in content:
340340
if item.get("type") == "text":
341-
content_str += item.get("text", "")
341+
text_value = item.get("text", "")
342+
content_str += str(text_value) if text_value is not None else ""
342343
return content_str
343344
else:
344345
raise Exception(f"Unsupported content type: {type(content)}")
@@ -369,18 +370,19 @@ def extract_reasoning_content(
369370
for item in content:
370371
if item.get("type") == "reasoning":
371372
summary_list = item.get("summary", [])
372-
for sum in summary_list:
373-
if reasoning_content is None:
374-
reasoning_content = ""
375-
reasoning_content += sum["text"]
376-
thinking_block = ChatCompletionThinkingBlock(
377-
type="thinking",
378-
thinking=sum.get("text", ""),
379-
signature=sum.get("signature", ""),
380-
)
381-
if thinking_blocks is None:
382-
thinking_blocks = []
383-
thinking_blocks.append(thinking_block)
373+
if isinstance(summary_list, list):
374+
for sum in summary_list:
375+
if reasoning_content is None:
376+
reasoning_content = ""
377+
reasoning_content += sum["text"]
378+
thinking_block = ChatCompletionThinkingBlock(
379+
type="thinking",
380+
thinking=sum.get("text", ""),
381+
signature=sum.get("signature", ""),
382+
)
383+
if thinking_blocks is None:
384+
thinking_blocks = []
385+
thinking_blocks.append(thinking_block)
384386
return reasoning_content, thinking_blocks
385387

386388
@staticmethod

litellm/responses/mcp/litellm_proxy_mcp_handler.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ def _should_use_litellm_mcp_gateway(tools: Optional[Iterable[ToolParam]]) -> boo
2727
"""
2828
if tools:
2929
for tool in tools:
30-
if (isinstance(tool, dict) and
31-
tool.get("type") == "mcp" and
32-
tool.get("server_url", "").startswith(LITELLM_PROXY_MCP_SERVER_URL)):
33-
return True
30+
if isinstance(tool, dict) and tool.get("type") == "mcp":
31+
server_url = tool.get("server_url", "")
32+
if isinstance(server_url, str) and server_url.startswith(LITELLM_PROXY_MCP_SERVER_URL):
33+
return True
3434
return False
3535

3636
@staticmethod
@@ -46,10 +46,12 @@ def _parse_mcp_tools(tools: Optional[Iterable[ToolParam]]) -> Tuple[List[ToolPar
4646

4747
if tools:
4848
for tool in tools:
49-
if (isinstance(tool, dict) and
50-
tool.get("type") == "mcp" and
51-
tool.get("server_url", "").startswith(LITELLM_PROXY_MCP_SERVER_URL)):
52-
mcp_tools_with_litellm_proxy.append(tool)
49+
if isinstance(tool, dict) and tool.get("type") == "mcp":
50+
server_url = tool.get("server_url", "")
51+
if isinstance(server_url, str) and server_url.startswith(LITELLM_PROXY_MCP_SERVER_URL):
52+
mcp_tools_with_litellm_proxy.append(tool)
53+
else:
54+
other_tools.append(tool)
5355
else:
5456
other_tools.append(tool)
5557

@@ -74,8 +76,9 @@ async def _get_mcp_tools_from_manager(
7476
if mcp_tools_with_litellm_proxy:
7577
for _tool in mcp_tools_with_litellm_proxy:
7678
# if user specifies servers as server_url: litellm_proxy/mcp/zapier,github then return zapier,github
77-
if _tool.get("server_url", "").startswith(LITELLM_PROXY_MCP_SERVER_URL_PREFIX):
78-
mcp_servers.append(_tool.get("server_url", "").split("/")[-1])
79+
server_url = _tool.get("server_url", "") if isinstance(_tool, dict) else ""
80+
if isinstance(server_url, str) and server_url.startswith(LITELLM_PROXY_MCP_SERVER_URL_PREFIX):
81+
mcp_servers.append(server_url.split("/")[-1])
7982

8083
return await _get_tools_from_mcp_servers(
8184
user_api_key_auth=user_api_key_auth,
@@ -588,7 +591,7 @@ def _create_tool_execution_events(
588591

589592
from litellm.responses.mcp.mcp_streaming_iterator import create_mcp_call_events
590593

591-
tool_execution_events = []
594+
tool_execution_events: List[Any] = []
592595

593596
# Create events for each tool execution
594597
for tool_result in tool_results:

litellm/responses/mcp/mcp_streaming_iterator.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ async def create_mcp_list_tools_events(
4545
LiteLLM_Proxy_MCP_Handler,
4646
)
4747

48-
events = []
48+
events: List[ResponsesAPIStreamingResponse] = []
4949

5050
try:
5151
# Extract MCP server names
5252
mcp_servers = []
5353
for tool in mcp_tools_with_litellm_proxy:
5454
if isinstance(tool, dict) and "server_url" in tool:
55-
server_url = tool["server_url"]
56-
if server_url.startswith("litellm_proxy/mcp/"):
55+
server_url = tool.get("server_url")
56+
if isinstance(server_url, str) and server_url.startswith("litellm_proxy/mcp/"):
5757
server_name = server_url.split("/")[-1]
5858
mcp_servers.append(server_name)
5959

@@ -72,7 +72,7 @@ async def create_mcp_list_tools_events(
7272
# Convert tools to dict format for the event
7373
mcp_tools_dict = []
7474
for tool in filtered_mcp_tools:
75-
if hasattr(tool, 'model_dump'):
75+
if hasattr(tool, 'model_dump') and callable(getattr(tool, 'model_dump')):
7676
mcp_tools_dict.append(tool.model_dump())
7777
elif hasattr(tool, '__dict__'):
7878
mcp_tools_dict.append(tool.__dict__)
@@ -96,7 +96,8 @@ async def create_mcp_list_tools_events(
9696
if mcp_tools_with_litellm_proxy:
9797
first_tool = mcp_tools_with_litellm_proxy[0]
9898
if isinstance(first_tool, dict):
99-
server_label = first_tool.get("server_label", "")
99+
server_label_value = first_tool.get("server_label", "")
100+
server_label = str(server_label_value) if server_label_value is not None else ""
100101

101102
# Format tools for OpenAI output_item.done format
102103
formatted_tools = []
@@ -109,9 +110,9 @@ async def create_mcp_list_tools_events(
109110

110111
# Add input_schema if available
111112
if hasattr(tool, 'inputSchema'):
112-
tool_dict["input_schema"] = tool.inputSchema
113+
tool_dict["input_schema"] = getattr(tool, 'inputSchema')
113114
elif hasattr(tool, 'input_schema'):
114-
tool_dict["input_schema"] = tool.input_schema
115+
tool_dict["input_schema"] = getattr(tool, 'input_schema')
115116

116117
formatted_tools.append(tool_dict)
117118

@@ -171,7 +172,7 @@ def create_mcp_call_events(
171172
sequence_start: int = 1
172173
) -> List[ResponsesAPIStreamingResponse]:
173174
"""Create MCP call events following OpenAI's specification"""
174-
events = []
175+
events: List[ResponsesAPIStreamingResponse] = []
175176
item_id = base_item_id or f"mcp_{uuid.uuid4().hex[:8]}"
176177

177178
# MCP call in progress event

0 commit comments

Comments
 (0)