pub struct ToolIndex {
by_id: HashMap<String, McpTool>,
}Expand description
An in-memory index over all tools from all running MCP servers.
Build one via ToolIndex::from_tools, then use search and
get_schema to serve progressive-disclosure meta-tool calls without
exposing the full registry to external clients.
Fields§
§by_id: HashMap<String, McpTool>Keyed by "<server_name>__<tool_name>".
Implementations§
Source§impl ToolIndex
impl ToolIndex
Sourcepub fn from_tools(iter: impl IntoIterator<Item = (String, McpTool)>) -> Self
pub fn from_tools(iter: impl IntoIterator<Item = (String, McpTool)>) -> Self
Build a ToolIndex from an iterator of (qualified_id, tool) pairs.
The caller is responsible for constructing qualified_id in the format
"<server_name>__<tool_name>". See [build_tool_index] in
gglib-proxy for the canonical construction path.
Duplicate IDs are silently overwritten by the last occurrence (mirrors the behaviour of the MCP server registry, which does not permit two servers with the same name to be active simultaneously).
Sourcepub fn search(&self, query: &str) -> Vec<ToolSummary>
pub fn search(&self, query: &str) -> Vec<ToolSummary>
Search the index by keyword and return at most SEARCH_RESULTS_CAP
lightweight ToolSummary entries.
§Matching
Both the tool_id and the tool’s description field are searched
using case-insensitive substring matching. A tool is included if the
lowercased query appears anywhere in either field.
An empty query returns the first SEARCH_RESULTS_CAP tools in
an unspecified (but deterministic within a single process run) order —
useful for an LLM that wants a broad overview before deciding what to
fetch.
§Hard cap
At most SEARCH_RESULTS_CAP results are returned regardless of how
many tools match. This is intentional: searches that return too many
results should be narrowed with a more specific keyword.
Sourcepub fn get_schema(&self, tool_id: &str) -> Option<&Value>
pub fn get_schema(&self, tool_id: &str) -> Option<&Value>
Retrieve the full JSON input schema for a single tool by its qualified
tool_id.
Returns None when no tool with that ID exists in the index, or when
the tool exists but its upstream server did not expose a schema.
§Token cost
Calling this for a single tool is the central efficiency gain of the Progressive Disclosure pattern — the client pays only for the one schema it actually needs, not for all schemas in the registry.