Skip to content

W1.3 — ToolRouter singleton with index lifecycle and search #20

Description

@edelauna

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions