Context
ToolRouter is the orchestrator that owns the index lifecycle, picks the ranker, and exposes the two methods the rest of the system needs (attachInitial for task start, search for mcp_load). Without it, the ranker is just a function with nowhere to live.
Architectural enabler for: RooCodeInc#12004 (large MCP catalogs); cline/cline#9398 (parallel — high MCP-token usage at idle).
Developer Notes
- New
src/services/tools/ToolRouter.ts — singleton.
- Internal state: a cached
Ranker (auto-selected via W1.2 factory), an indexed ToolDoc[] keyed by MCP server config hash, and an invalidation hook on McpHub server-list changes.
- Public API:
attachInitial(taskText: string, scopedTools: ToolDoc[], k: number): Promise<string[]> — embed/tokenize taskText, rank, return top-K names.
search(query: string, scopedTools: ToolDoc[], k: number): Promise<string[]> — same, used by mcp_load.
- Lazy index build on first call. Rebuild only when MCP server list changes (cheap; in-memory).
- Files:
src/services/tools/ToolRouter.ts, subscription wiring in src/services/mcp/McpHub.ts.
- Validation: integration test — index rebuilds when an MCP server is enabled/disabled; calls before any MCP servers are configured return empty (don't crash).
Context
ToolRouteris the orchestrator that owns the index lifecycle, picks the ranker, and exposes the two methods the rest of the system needs (attachInitialfor task start,searchformcp_load). Without it, the ranker is just a function with nowhere to live.Architectural enabler for: RooCodeInc#12004 (large MCP catalogs); cline/cline#9398 (parallel — high MCP-token usage at idle).
Developer Notes
src/services/tools/ToolRouter.ts— singleton.Ranker(auto-selected via W1.2 factory), an indexedToolDoc[]keyed by MCP server config hash, and an invalidation hook onMcpHubserver-list changes.attachInitial(taskText: string, scopedTools: ToolDoc[], k: number): Promise<string[]>— embed/tokenize taskText, rank, return top-K names.search(query: string, scopedTools: ToolDoc[], k: number): Promise<string[]>— same, used bymcp_load.src/services/tools/ToolRouter.ts, subscription wiring insrc/services/mcp/McpHub.ts.