feat: add allowedTools whitelist support to MCP server config#11423
feat: add allowedTools whitelist support to MCP server config#11423roomote[bot] wants to merge 1 commit intomainfrom
Conversation
Adds an optional allowedTools field to MCP server configuration that acts as a whitelist for tools. When specified, only tools in the allowedTools list are enabled. The disabledTools blacklist further filters from the allowed set. When not specified, behavior is unchanged (all tools are allowed). Closes #11259
Clean implementation overall. The
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
| // If allowedTools whitelist is specified, only those tools are enabled. | ||
| // Then disabledTools blacklist further filters from the allowed set. | ||
| const tools = (response?.tools || []).map((tool) => { | ||
| const isWhitelisted = allowedToolsList === undefined || allowedToolsList.includes(tool.name) |
There was a problem hiding this comment.
allowedToolsList is read from raw JSON (line 1007), not from Zod-validated config, so null is a possible value if a user writes "allowedTools": null in their config file. Strict equality === undefined won't catch null, causing null.includes(tool.name) to throw a TypeError. The outer try/catch swallows it but returns an empty tools list with no user-facing feedback. The adjacent disabledTools reading defensively uses || [] for the same reason. Using loose equality here keeps both code paths consistent.
| const isWhitelisted = allowedToolsList === undefined || allowedToolsList.includes(tool.name) | |
| const isWhitelisted = allowedToolsList == null || allowedToolsList.includes(tool.name) |
Fix it with Roo Code or mention @roomote and request a fix.
Related GitHub Issue
Closes: #11259
Description
This PR attempts to address Issue #11259 by adding an optional
allowedToolswhitelist to MCP server configuration. Feedback and guidance are welcome.Key implementation details:
allowedToolsas an optional field in theBaseConfigSchema(Zod schema) alongside the existingdisabledToolsallowedToolsis specified, only tools in the whitelist are enabled (enabledForPrompt: true)allowedToolsis not specified, all tools are enabled (backward compatible)disabledToolsblacklist further filters from the allowed set (whitelist wins as primary gate, blacklist narrows)enabledForPromptExample config:
{ "mcpServers": { "my-server": { "command": "node", "args": ["server.js"], "allowedTools": ["tool1", "tool3"], "disabledTools": ["tool3"] } } }In this case, only
tool1would be enabled (tool3 is whitelisted but then blacklisted, tool2 is not whitelisted).Test Procedure
allowedToolsmeans all tools allowed)allowedTools+disabledToolsbehaviorallowedToolsarray disables all toolscd src && npx vitest run services/mcp/__tests__/McpHub.spec.tsPre-Submission Checklist
Documentation Updates
Additional Notes
Files changed:
src/services/mcp/McpHub.ts: AddedallowedToolsto schema, config reading, andenabledForPromptlogicsrc/services/mcp/__tests__/McpHub.spec.ts: Added 4 test cases for whitelist behavior