Skip to main content

Module tools_index

Module tools_index 

Source
Expand description

Compact tool catalog index for warm --search / --detail names.

Full MCP tool lists embed every inputSchema (multi‑MB). We store a small parallel index:

  • names (sorted) — exact/prefix via binary search
  • tool_overrides — sparse MCP names when they are not kebab→snake
  • postings — kebab-segment → tool ids (in memory only; rebuilt on load)
  • descs — optional truncated text (omitted from v4 disk by default)

Session daemons keep this struct in RAM and search in-process. Disk is a thin non-session accelerator (names + overrides only).

The inverted postings map is the KV shape we need at ~3k tools. An embedded KV engine (redb/sled) is not worth the deps unless catalogs grow far larger or we need a shared index without a session daemon.

A BST does not help arbitrary substring search. Sorted names + postings are the right shape for CLI discovery.

Structs§

CompactIndex
Compact index (v4 disk omits descs/postings; v2/v3 still load).
ToolIndexEntry

Constants§

DESC_TRUNCATE
Max description chars retained when building with with_descs: true.
INDEX_VERSION
On-disk format: names + sparse overrides; postings rebuilt in memory.

Functions§

build_compact_index
build_index
find_exact
Exact name lookup via binary search on sorted names.
index_cache_key
index_to_commands
load_compact_index
load_index
rebuild_postings
Rebuild inverted postings from names (used after v4 disk load).
save_index
Persist names + overrides only (no descs / postings) for a slim disk sidecar.
save_tools_and_index
search_compact
Search using postings when pattern is a single kebab token; else scan names.
search_index
tools_to_light_commands
try_commands_from_index
Warm-path commands from disk index.