You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature] Architecture: On-demand MCP Tool Discovery to preserve local context windows #1571
architectureNeeds a structural design changearea:mcpMCP client and server integrationarea:providersLLM providers, models, tokenisation, context limitsenhancementNew feature or requestperformanceSpeed, memory use or token efficiencyproposalA speculative idea rather than committed work
Implement an on-demand, lazy-loading discovery mechanism for MCP (Model Context Protocol) tool schemas, rather than hydrating all available tools into the system prompt at the start of a session.
Use Case
As users add more MCP servers, the number of available tools grows rapidly. Passing 50+ massive JSON tool schemas into the system prompt destroys the limited context window of local models (e.g., Llama 3) and heavily degrades their reasoning ability and time-to-first-token (TTFT).
Proposed Solution
Extract a lightweight "Tool Catalog" (just tool names and 1-sentence descriptions).
Inject only the catalog into the initial system prompt.
Provide a native load_tool_schema(tool_name) tool.
When the agent realizes it needs a specific tool from the catalog, it calls load_tool_schema, and the harness dynamically injects the full schema into the context for subsequent turns.
Alternatives Considered
Hardcoding a limit on allowed tools (reduces functionality).
Relying on the user to manually toggle tools on/off via CLI flags (bad UX).
Additional Context
I have searched existing issues to ensure this is not a duplicate
This feature aligns with the project's goals (local-first AI assistance)
Taking this issue here is my exact plan after going through the codebase let me know what you think!
Implementation Plan
Two-Tier MCP Registry (source/mcp/)
Store MCP tools as lightweight catalog entries (name, description, serverName) in memory.
Hold the full JSON parameter schemas separately so they aren't hydrated into the system prompt upfront.
load_mcp_tool Meta-Tool (source/tools/mcp/)
Introduce a built-in load_mcp_tool({ tool_name: string }) tool.
When called, it dynamically activates and registers the full parameter schema into the session's active tool list (ToolManager) for subsequent turns.
System Prompt Catalog (source/app/prompts/)
Inject a compact <mcp_tools_catalog> prompt section listing available tool names with 1-sentence descriptions when lazy mode is active (~15 tokens per tool instead of hundreds).
architectureNeeds a structural design changearea:mcpMCP client and server integrationarea:providersLLM providers, models, tokenisation, context limitsenhancementNew feature or requestperformanceSpeed, memory use or token efficiencyproposalA speculative idea rather than committed work
Activity
rishu685 commentedon Oct 8, 2026
Taking this issue here is my exact plan after going through the codebase let me know what you think!
Implementation Plan
source/mcp/)name,description,serverName) in memory.load_mcp_toolMeta-Tool (source/tools/mcp/)load_mcp_tool({ tool_name: string })tool.ToolManager) for subsequent turns.source/app/prompts/)<mcp_tools_catalog>prompt section listing available tool names with 1-sentence descriptions when lazy mode is active (~15 tokens per tool instead of hundreds).source/types/config.ts,source/config/)mcp.lazyDiscovery("auto"|true|false).nano&minimaltool profiles, or when MCP schemas exceed a token threshold./mcpcommand to display which tools are in catalog vs active/hydrated.feat(mcp): on-demand MCP tool discovery to preserve local context win…
feat(mcp): on-demand MCP tool discovery to preserve local context win…
feat(mcp): on-demand MCP tool discovery to preserve local context win…
feat(mcp): on-demand MCP tool discovery to preserve local context win…
feat(mcp): on-demand MCP tool discovery to preserve local context win…
feat(mcp): on-demand MCP tool discovery to preserve local context win…