Module tool_index

Module tool_index 

Source
Expand description

In-memory index for progressive tool disclosure.

§Problem

Dumping the full JSON schema of every MCP tool to an external client (e.g. VS Code Copilot) on every tools/list call costs 100 k+ tokens at 100+ tools and causes context-window timeouts. The Progressive Disclosure pattern fixes this by exposing three meta-tools instead of the full registry:

Meta-toolPurpose
search_toolsKeyword search; returns lightweight summaries
get_tool_schemaLazily fetches one tool’s full JSON schema
invoke_toolForwards execution to the upstream MCP server

§Design

ToolIndex is a pure-data, allocation-once structure built from the complete McpTool list that the McpService already holds in memory. It lives in gglib-core so that every frontend (CLI, Axum, Tauri) can share the same type without depending on gglib-mcp.

The index intentionally does not cache itself inside AppState. Rebuilding from the in-memory McpService on each search_tools or get_tool_schema call is microseconds and automatically reflects MCP server start / stop events.

Structs§

ToolIndex
An in-memory index over all tools from all running MCP servers.
ToolSummary
A lightweight, schema-free description of a single MCP tool.

Constants§

SEARCH_RESULTS_CAP
Maximum number of ToolSummary entries returned by a single ToolIndex::search call.