diff --git a/litellm/proxy/_experimental/mcp_server/semantic_tool_filter.py b/litellm/proxy/_experimental/mcp_server/semantic_tool_filter.py index 79f95faafca..dcde10e7c6d 100644 --- a/litellm/proxy/_experimental/mcp_server/semantic_tool_filter.py +++ b/litellm/proxy/_experimental/mcp_server/semantic_tool_filter.py @@ -3,6 +3,7 @@ Semantic MCP Tool Filtering using semantic-router Filters MCP tools semantically for /chat/completions and /responses endpoints. """ + from typing import TYPE_CHECKING, Any, Dict, List, Optional from litellm._logging import verbose_logger diff --git a/litellm/proxy/hooks/mcp_semantic_filter/hook.py b/litellm/proxy/hooks/mcp_semantic_filter/hook.py index 7f2a50a1056..cb951a9ba62 100644 --- a/litellm/proxy/hooks/mcp_semantic_filter/hook.py +++ b/litellm/proxy/hooks/mcp_semantic_filter/hook.py @@ -4,6 +4,7 @@ Semantic Tool Filter Hook Pre-call hook that filters MCP tools semantically before LLM inference. Reduces context window size and improves tool selection accuracy. """ + from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union from litellm._logging import verbose_proxy_logger @@ -226,10 +227,14 @@ class SemanticToolFilterHook(CustomLogger): # Separate MCP tools (prefixed) from non-MCP tools — only filter # MCP tools, always pass non-MCP tools through untouched. def _tool_name(t): - return t.get("name", "") if isinstance(t, dict) else getattr(t, "name", "") + return ( + t.get("name", "") if isinstance(t, dict) else getattr(t, "name", "") + ) mcp_tools = [t for t in tools if is_tool_name_prefixed(_tool_name(t))] - non_mcp_tools = [t for t in tools if not is_tool_name_prefixed(_tool_name(t))] + non_mcp_tools = [ + t for t in tools if not is_tool_name_prefixed(_tool_name(t)) + ] if not mcp_tools: return None