fix(mcp_semantic_tool_filter): resolve client-suffixed tool names (LibreChat-style)#26858
fix(mcp_semantic_tool_filter): resolve client-suffixed tool names (LibreChat-style)#26858GopalGB wants to merge 1 commit into
Conversation
|
Too many files changed for review. ( |
|
|
Merging this PR will not alter performance
Comparing |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
4dcb8c5 to
a3b04a3
Compare
|
Force-pushed cleaned-up branch. Two changes:
Will sign the CLA via cla-assistant.io and re-trigger checks. |
a3b04a3 to
4bc0c8c
Compare
|
Two more fixes pushed:
Branch state: 1 commit, 2 files ( |
…breChat-style) Closes BerriAI#26507. Adds LibreChat-style suffix wrapping so client-side tool name suffixes are stripped before semantic matching, then re-applied on tool emission. Tested via tests/test_litellm/proxy/_experimental/mcp_server/test_semantic_tool_filter.py Signed-off-by: GopalGB <67310594+GopalGB@users.noreply.github.com>
4bc0c8c to
e124e9a
Compare
Closes #26507.
Repro
LibreChat (and similar MCP clients that connect to multiple servers through one proxy) appends a per-tool unique-ID suffix to canonical tool names to disambiguate same-named tools across servers, e.g.
fc_web_search-firecrawl_scrape_a1b2c3d4.The semantic-tool-filter matcher currently only handles the symmetric prefix wrapping (opencode-style,
litellm_<canonical>). Suffix-wrapped names fall through_name_matches_canonical, the filter shipstools: []withtool_choice: "auto"to the upstream provider, and every strict OpenAI-compatible model returns400 'tool_choice' is only allowed when 'tools' are specified.Fix
Extend
_name_matches_canonicalto also acceptclient_name.startswith(canonical + sep)matches, while keeping the same anchoring guards as the suffix path:_or-); bare-substring matches do not count, soearthquake_alertdoes not match canonicalear.canonicalmust containMCP_TOOL_PREFIX_SEPARATOR, otherwise unrelated local user functions whose names share the same characters (e.g.firecrawl_scrape_v2_helpervs canonicalfirecrawl_scrape) would be spuriously selected. Symmetric with the suffix-direction guard added in fix(mcp_semantic_tool_filter): match tools with client-side namespace prefix (#26078) #26117.The semantic delta is ~6 lines of logic and a refreshed docstring; the rest of the diff is reflowing introduced by the project's auto-formatter.
Test
Adds five regression tests:
test_client_suffix_with_underscore_separator— exact shape from the bug report (<canonical>_<uid>)test_client_suffix_with_dash_separator— dash-separator varianttest_prefix_without_separator_does_not_match— bare-substring guard in the prefix direction (earthquake_alert!=ear)test_suffix_does_not_match_unprefixed_canonical— unprefixed-canonical guard in the prefix direction (mirror of fix(mcp_semantic_tool_filter): match tools with client-side namespace prefix (#26078) #26117's local-function guard)test_prefix_and_suffix_wrappers_can_coexist— mixed-client scenarioAll 14
TestGetToolsByNamestests pass after the fix:The new tests fail on the unpatched matcher (verified by reverting only the source change with
git stash push <source-file>and re-running). All previous tests still pass.🤖 Generated with Claude Code