Skip to main content

Module tool_search

Module tool_search 

Source
Expand description

Tool Search — Semantic tool matching for dynamic MCP tool loading

When the MCP ecosystem grows large (100+ tools), injecting all tool descriptions into the system prompt wastes context. Tool Search selects only the relevant tools per-turn based on keyword and semantic matching.

§How It Works

  1. All registered tools (builtin + MCP) are indexed with their name, description, and parameter schema.
  2. Before each LLM call, the user prompt is matched against the index.
  3. Only tools scoring above the threshold are included in the request.
  4. Builtin tools are always included (they’re small and essential).

§Usage

use a3s_code_core::tool_search::{ToolIndex, ToolSearchConfig};

let config = ToolSearchConfig::default();
let mut index = ToolIndex::new(config);

// Index tools
index.add("mcp__github__create_issue", "Create a GitHub issue", &["github", "issue", "bug"]);
index.add("mcp__postgres__query", "Run a SQL query", &["sql", "database", "query"]);

// Search
let matches = index.search("create a bug report on GitHub", 5);
// → ["mcp__github__create_issue"]

Structs§

ToolIndex
Index of all registered tools for semantic search.
ToolMatch
A scored search result.
ToolSearchConfig
Configuration for tool search behavior.