fix(proxy): reject suffix remainders containing any separator, not just configured one

Greptile review on #26533: the guard `MCP_TOOL_PREFIX_SEPARATOR not in rest`
only checked for the configured separator (default `-`). When the suffix
separator is `-` and the remainder is `extra_tool`, the guard passes because
`extra_tool` contains no `-` — but `_` is also a valid MCP separator.

Fix: check for both `_` and `-` in the remainder, since a unique-ID segment
should contain no separator at all.
This commit is contained in:
Prithvi1994 2026-04-26 00:33:16 +00:00
parent f13d6b4eda
commit 76d8d29951
2 changed files with 10 additions and 5 deletions

View file

@ -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
``<sep><tool_name>`` 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

View file

@ -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 = [