From 65edd20c33509693875aee299af294280475d2b4 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Sat, 7 Nov 2026 05:41:11 -0800 Subject: [PATCH] refactor(mcp): type the semantic filter's default tool loader Annotate the chosen loader as _OpenAIToolLoader and narrow its return to FunctionToolParam, so a default that returns raw MCP tools fails the type check. Drop the unused patch import. --- litellm/proxy/hooks/mcp_semantic_filter/hook.py | 6 ++++-- tests/unit/proxy/mcp_server/test_semantic_tool_filter.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/litellm/proxy/hooks/mcp_semantic_filter/hook.py b/litellm/proxy/hooks/mcp_semantic_filter/hook.py index 163e0243379..b7b65d6f0db 100644 --- a/litellm/proxy/hooks/mcp_semantic_filter/hook.py +++ b/litellm/proxy/hooks/mcp_semantic_filter/hook.py @@ -24,6 +24,8 @@ from litellm.proxy.mcp_server.semantic_tool_filter import ( ) if TYPE_CHECKING: + from openai.types.responses.function_tool_param import FunctionToolParam + from litellm.caching.caching import DualCache from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.mcp_server.semantic_tool_filter import ( @@ -57,7 +59,7 @@ class _OpenAIToolLoader(Protocol): *, user_api_key_auth: "UserAPIKeyAuth | None", mcp_tools_with_litellm_proxy: Sequence[Mapping[str, object]], - ) -> Awaitable[tuple[Sequence[object], Mapping[str, str]]]: ... + ) -> Awaitable[tuple[Sequence["FunctionToolParam"], Mapping[str, str]]]: ... class _PydanticTool(Protocol): @@ -155,7 +157,7 @@ class SemanticToolFilterHook(CustomLogger): if not mcp_tools: return [] - load_openai_tools: Final = ( + load_openai_tools: Final[_OpenAIToolLoader] = ( LiteLLM_Proxy_MCP_Handler.process_mcp_tools_to_openai_format if self._load_openai_tools is None else self._load_openai_tools diff --git a/tests/unit/proxy/mcp_server/test_semantic_tool_filter.py b/tests/unit/proxy/mcp_server/test_semantic_tool_filter.py index 0b5cd82efd8..afbc439cb99 100644 --- a/tests/unit/proxy/mcp_server/test_semantic_tool_filter.py +++ b/tests/unit/proxy/mcp_server/test_semantic_tool_filter.py @@ -7,7 +7,7 @@ an ordered set of top K tools based on semantic similarity. import asyncio import sys -from unittest.mock import AsyncMock, Mock, patch +from unittest.mock import AsyncMock, Mock import pytest