Skip to content

W1.4 — mcp_load tool, threshold gate, and Task.attachedMcpToolNames #21

Description

@edelauna

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.

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