diff --git a/strix/tools/mcp/agent_tools.py b/strix/tools/mcp/agent_tools.py index e6ff1e3e..ab068c64 100644 --- a/strix/tools/mcp/agent_tools.py +++ b/strix/tools/mcp/agent_tools.py @@ -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, diff --git a/tests/test_mcp_client.py b/tests/test_mcp_client.py index 992bc0b4..54f49f54 100644 --- a/tests/test_mcp_client.py +++ b/tests/test_mcp_client.py @@ -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(