Context
This ticket wires the ToolRouter into actual API calls: the threshold gate at task start, the mcp_load escape hatch, and persistence of the attached set.
After this ticket, dynamic loading is functionally live (without the rolling window — that's W1.5).
Closes: RooCodeInc#11990 (strange context bloat — large tools arrays will be a frequent root cause once we look).
Developer Notes
- Add
Task.attachedMcpToolNames: Set<string> (persisted with task state).
build-tools.ts:
- After
ToolScopeFilter produces scopedTools, check scopedTools.length against mcp.dynamicLoad.threshold (default 50; replaces the old MAX_MCP_TOOLS_THRESHOLD = 60).
- If under threshold: existing path.
- If over: call
ToolRouter.attachInitial(taskText, scopedTools, initialK). Initialize Task.attachedMcpToolNames. The API tools array is nativeTools + filter(scopedTools by attachedMcpToolNames) + mcp_load.
- New native tool
mcp_load in src/core/prompts/tools/native-tools/mcp_load.ts:
- Schema:
{ query: string }.
- Handler at
src/core/tools/mcpLoadTool.ts: calls ToolRouter.search(query, scopedTools, searchK), mutates Task.attachedMcpToolNames, returns the new tool names + 1-line descriptions.
- Idempotent: re-attaching an already-attached tool returns the existing list with no churn.
- Remove the
too_many_tools_warning from Task.ts:1957 — the new flow obsoletes it. (UI replacement comes in W2.1.)
- Settings:
mcp.dynamicLoad.threshold (default 50), mcp.dynamicLoad.initialK (default 30), mcp.dynamicLoad.searchK (default 10). Register in the settings schema; surface in MCP settings UI.
- Files:
src/core/task/Task.ts, src/core/task/build-tools.ts, src/core/prompts/tools/native-tools/mcp_load.ts, src/core/tools/mcpLoadTool.ts, packages/types/src/mcp.ts.
- Validation: integration test with 100 mock MCP tools — initial API call has 30 + native +
mcp_load; model calling mcp_load("specific query") adds matching tools; subsequent API call includes them.
Context
This ticket wires the
ToolRouterinto actual API calls: the threshold gate at task start, themcp_loadescape hatch, and persistence of the attached set.After this ticket, dynamic loading is functionally live (without the rolling window — that's W1.5).
Closes: RooCodeInc#11990 (strange context bloat — large
toolsarrays will be a frequent root cause once we look).Developer Notes
Task.attachedMcpToolNames: Set<string>(persisted with task state).build-tools.ts:ToolScopeFilterproducesscopedTools, checkscopedTools.lengthagainstmcp.dynamicLoad.threshold(default 50; replaces the oldMAX_MCP_TOOLS_THRESHOLD = 60).ToolRouter.attachInitial(taskText, scopedTools, initialK). InitializeTask.attachedMcpToolNames. The APItoolsarray isnativeTools + filter(scopedTools by attachedMcpToolNames) + mcp_load.mcp_loadinsrc/core/prompts/tools/native-tools/mcp_load.ts:{ query: string }.src/core/tools/mcpLoadTool.ts: callsToolRouter.search(query, scopedTools, searchK), mutatesTask.attachedMcpToolNames, returns the new tool names + 1-line descriptions.too_many_tools_warningfromTask.ts:1957— the new flow obsoletes it. (UI replacement comes in W2.1.)mcp.dynamicLoad.threshold(default 50),mcp.dynamicLoad.initialK(default 30),mcp.dynamicLoad.searchK(default 10). Register in the settings schema; surface in MCP settings UI.src/core/task/Task.ts,src/core/task/build-tools.ts,src/core/prompts/tools/native-tools/mcp_load.ts,src/core/tools/mcpLoadTool.ts,packages/types/src/mcp.ts.mcp_load; model callingmcp_load("specific query")adds matching tools; subsequent API call includes them.