ToolIndex

Struct ToolIndex 

Source
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

Source

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).

Source

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.

Source

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.

Source

pub fn contains(&self, tool_id: &str) -> bool

Returns true if the index contains a tool with the given tool_id.

Used by invoke_tool to validate the ID before attempting resolution against the live MCP service.

Source

pub fn len(&self) -> usize

Total number of tools in the index across all MCP servers.

Source

pub fn is_empty(&self) -> bool

Returns true if no tools are currently indexed (no MCP servers running or all servers have zero tools).

Trait Implementations§

Source§

impl Debug for ToolIndex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ToolIndex

Source§

fn default() -> ToolIndex

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more