Roo-Code/src/core/tools
Stefan Vetter 79de65a8f5 feat: implement per-mode MCP server/tool filtering
Adds granular per-mode control over which MCP servers and tools are available, replacing the previous all-or-nothing 'mcp' group behavior.

Schema (packages/types/src/mode.ts): - Add mcpServerFilterSchema with disabled/allowedTools/disabledTools - Add mcpDefaultPolicy ('allow'|'deny') for deny-by-default support - Add mcpGroupOptionsSchema extending group options for MCP tuples - Add superRefine validation rejecting MCP options on non-mcp groups

Core filtering (src/utils/mcp-filter.ts): - getMcpFilterForMode() resolves MCP config for a mode - isMcpServerAllowedForMode() checks server access with policy - isMcpToolAllowedForMode() checks tool access with allowlist/blocklist - Inlined getGroupName to avoid vscode import chain (ISSUE-16)

Prerequisite fix (src/utils/mcp-name.ts): - Fix normalizeForComparison regex: /[-\s]+/g -> /[-\s]/g (ISSUE-10) - Add toLowerCase() for case-insensitive matching

Prompt-level filtering: - filter-tools-for-mode.ts: Filter MCP tools from system prompt - build-tools.ts: Filter MCP tools for Gemini native function calling - ISSUE-19: Document native tools remain unfiltered for Gemini

Execution-time guards: - validateToolUse.ts: Replace blanket MCP allow with filter checks   - Server-level guard for use_mcp_tool/access_mcp_resource   - Tool-level guard for dynamic mcp--server--tool names   - ISSUE-21: Tool-level check for use_mcp_tool when tool_name available - presentAssistantMessage.ts mcp_tool_use: Add filter using cline.taskMode - ISSUE-17: validateToolUse call uses cline.taskMode (frozen at task start)   instead of state.mode (live UI mode) - ISSUE-20: Remove dead ?? defaultModeSlug fallback

Defense-in-depth: - UseMcpToolTool.execute(): Server + tool level filter before execution - AccessMcpResourceTool.execute(): Server level filter before execution - FLAG-E: Document 10-second TTL cache in CustomModesManager

UI fix (webview-ui): - ModesView.tsx: Cache group tuple options on toggle-off, restore on   toggle-on to prevent MCP config data loss (ISSUE-9/ISSUE-13) - Extract pure caching functions to groupOptionsCache.ts

Tests: 89 new tests across 11 files, all passing
2026-04-03 14:12:18 +02:00
..
__tests__ feat: implement per-mode MCP server/tool filtering 2026-04-03 14:12:18 +02:00
apply-patch feat: add apply_patch native tool (#9663) 2025-11-28 23:07:03 -05:00
helpers Reapply Batch 1: 22 clean non-AI-SDK cherry-picks (#11473) 2026-02-14 13:47:12 -07:00
accessMcpResourceTool.ts feat: implement per-mode MCP server/tool filtering 2026-04-03 14:12:18 +02:00
ApplyDiffTool.ts feat: show aggregated +/− line counts in FileChangesPanel header (#11618) 2026-02-19 23:22:20 -07:00
ApplyPatchTool.ts feat: show aggregated +/− line counts in FileChangesPanel header (#11618) 2026-02-19 23:22:20 -07:00
AskFollowupQuestionTool.ts fix: add follow_up param validation in AskFollowupQuestionTool (#11484) 2026-02-16 10:14:37 -07:00
AttemptCompletionTool.ts Fix stdin-stream cancel race and add integration test suite (#11817) 2026-03-01 22:27:01 -08:00
BaseTool.ts chore: remove XML tool calling support (#10841) 2026-01-20 20:25:08 -05:00
CodebaseSearchTool.ts chore: remove XML tool calling support (#10841) 2026-01-20 20:25:08 -05:00
EditFileTool.ts chore: remove XML tool calling support (#10841) 2026-01-20 20:25:08 -05:00
EditTool.ts Add back post-revert bug fixes and features (Step 2) (#11463) 2026-02-13 18:40:28 -05:00
ExecuteCommandTool.ts fix(cli): ignore model-provided timeout in CLI runtime (#11835) 2026-03-02 13:25:31 -08:00
GenerateImageTool.ts chore: remove XML tool calling support (#10841) 2026-01-20 20:25:08 -05:00
ListFilesTool.ts chore: remove XML tool calling support (#10841) 2026-01-20 20:25:08 -05:00
NewTaskTool.ts Revert to pre-AI-SDK state (January 29, 2026) (#11462) 2026-02-13 16:45:18 -05:00
ReadCommandOutputTool.ts feat: lossless terminal output with on-demand retrieval (#10944) 2026-01-27 22:12:19 -07:00
ReadFileTool.ts Reapply Batch 1: 22 clean non-AI-SDK cherry-picks (#11473) 2026-02-14 13:47:12 -07:00
RunSlashCommandTool.ts feat: expose skills as slash commands with skill fallback execution (#11834) 2026-03-02 15:10:32 -07:00
SearchAndReplaceTool.ts Add back post-revert bug fixes and features (Step 2) (#11463) 2026-02-13 18:40:28 -05:00
SearchFilesTool.ts chore: remove XML tool calling support (#10841) 2026-01-20 20:25:08 -05:00
SearchReplaceTool.ts chore: remove XML tool calling support (#10841) 2026-01-20 20:25:08 -05:00
SkillTool.ts feat: expose skills as slash commands with skill fallback execution (#11834) 2026-03-02 15:10:32 -07:00
SwitchModeTool.ts chore: remove XML tool calling support (#10841) 2026-01-20 20:25:08 -05:00
ToolRepetitionDetector.ts Reapply Batches 3-4: Skills, browser removal, provider removals (6 major-conflict cherry-picks) (#11475) 2026-02-14 22:06:24 -07:00
UpdateTodoListTool.ts chore: remove XML tool calling support (#10841) 2026-01-20 20:25:08 -05:00
UseMcpToolTool.ts feat: implement per-mode MCP server/tool filtering 2026-04-03 14:12:18 +02:00
validateToolUse.ts feat: implement per-mode MCP server/tool filtering 2026-04-03 14:12:18 +02:00
WriteToFileTool.ts chore: remove XML tool calling support (#10841) 2026-01-20 20:25:08 -05:00