diff --git a/litellm/proxy/_experimental/mcp_server/semantic_tool_filter.py b/litellm/proxy/_experimental/mcp_server/semantic_tool_filter.py index b6f6c7a87a0..a41678a6412 100644 --- a/litellm/proxy/_experimental/mcp_server/semantic_tool_filter.py +++ b/litellm/proxy/_experimental/mcp_server/semantic_tool_filter.py @@ -245,8 +245,8 @@ class SemanticMCPToolFilter: ``fc_web_search-firecrawl_scrape`` does match ``fc_web_search-firecrawl_scrape_a1b2c3d4`` but does not match ``fc_web_search-firecrawl_scrape_extra_tool`` (the part after the - canonical must be a single unique-ID segment, not another - ```` pair). + canonical contains a separator, indicating it's another + namespaced tool, not a unique-ID suffix). Both prefix and suffix matching are gated on ``canonical`` itself containing ``MCP_TOOL_PREFIX_SEPARATOR``. Server-registered MCP @@ -288,7 +288,12 @@ class SemanticMCPToolFilter: # namespaced tool, not a unique-ID suffix. if remainder and remainder[0] in ("_", "-"): rest = remainder[1:] - if MCP_TOOL_PREFIX_SEPARATOR not in rest: + # A unique-ID segment contains no separator at all (it's a + # short hex or alphanumeric string). Reject remainders that + # contain either underscore or dash, since both are valid + # separators in MCP tool names regardless of the configured + # MCP_TOOL_PREFIX_SEPARATOR. + if "_" not in rest and "-" not in rest: return True return False diff --git a/tests/test_litellm/proxy/_experimental/mcp_server/test_semantic_tool_filter.py b/tests/test_litellm/proxy/_experimental/mcp_server/test_semantic_tool_filter.py index 4b02988a4dc..1b21210bd3f 100644 --- a/tests/test_litellm/proxy/_experimental/mcp_server/test_semantic_tool_filter.py +++ b/tests/test_litellm/proxy/_experimental/mcp_server/test_semantic_tool_filter.py @@ -681,8 +681,8 @@ class TestGetToolsByNames: """ ``svc-search-extra_tool`` must NOT match canonical ``svc-search`` because the remainder after the separator (``extra_tool``) itself - contains ``MCP_TOOL_PREFIX_SEPARATOR`` (``-``), indicating it is - another namespaced tool, not a unique-ID suffix. + contains a separator character (``_``), indicating it is another + namespaced tool, not a unique-ID suffix. """ filter_instance = self._make_filter() available_tools = [