fix(mcp): limit active tool fallback

This commit is contained in:
yoni 2026-09-22 15:50:10 +00:00
parent 5126f51f5f
commit 009d8ce116
2 changed files with 6 additions and 2 deletions

View file

@ -138,7 +138,7 @@ def _search_score(tool: MCPTool, query_terms: list[str], active: bool) -> tuple[
elif term in description:
score += 10
matched_terms += 1
if matched_terms == 0 and not active:
if matched_terms == 0:
return (-1, name)
return (score + (matched_terms * 5), name)
@ -178,6 +178,10 @@ async def search_mcp_tools(
for tool in tools
if (score := _search_score(tool, terms, tool.name in entry.active_tools))[0] >= 0
]
if not ranked:
ranked = [
((100, tool.name.lower()), tool) for tool in tools if tool.name in entry.active_tools
]
ranked.sort(key=lambda item: (-item[0][0], item[0][1]))
return {
"connection": connection,

View file

@ -549,7 +549,7 @@ async def test_search_matches_any_query_term_and_prioritizes_active_tools() -> N
[
MCPTool(
name="fetch_page",
description="Fetch page content",
description="Read page content",
inputSchema={"type": "object"},
),
MCPTool(