feat: per-mode MCP server allowlist (allowedMcpServers)#12019
Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
Draft
feat: per-mode MCP server allowlist (allowedMcpServers)#12019roomote-v0[bot] wants to merge 1 commit intomainfrom
roomote-v0[bot] wants to merge 1 commit intomainfrom
Conversation
Add an optional allowedMcpServers field to ModeConfig that acts as a whitelist for MCP servers on a per-mode basis. When defined, only the listed MCP servers tools are injected for that mode. When omitted or empty, all enabled MCP servers are included (preserving current behavior). This addresses context bloat and tool limit issues when running multiple MCP servers with models that have strict tool limits (e.g. 128-tool limit). Changes: - packages/types/src/mode.ts: Add allowedMcpServers to modeConfigSchema - src/core/prompts/tools/native-tools/mcp_server.ts: Accept allowedMcpServers filter - src/core/task/build-tools.ts: Pass allowedMcpServers from mode config - src/core/prompts/system.ts: Filter MCP capabilities in system prompt Closes #12004
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related GitHub Issue
Closes: #12004
Description
This PR attempts to address Issue #12004 by adding an optional
allowedMcpServersfield toModeConfigthat acts as a per-mode allowlist for MCP servers. Feedback and guidance are welcome.How it works:
allowedMcpServersis defined on a mode config (e.g. in.roomodes), only MCP servers whose names are in the list will have their tools injected for that mode.allowedMcpServersis omitted or empty, all enabled MCP servers are included -- preserving current default behavior.Key implementation details:
packages/types/src/mode.ts): AddedallowedMcpServers: z.array(z.string()).optional()tomodeConfigSchema.src/core/prompts/tools/native-tools/mcp_server.ts):getMcpServerTools()now accepts an optionalallowedMcpServersparameter and filters the server list before building tool definitions.src/core/task/build-tools.ts): Resolves the current mode config and passesallowedMcpServerstogetMcpServerTools().src/core/prompts/system.ts): The MCP capabilities section now respectsallowedMcpServers-- if none of the allowed servers exist, the MCP capabilities message is omitted.Configuration example:
{ "customModes": [ { "slug": "database-architect", "name": "Database Architect", "roleDefinition": "You manage the database schema...", "groups": ["read", "edit", "mcp"], "allowedMcpServers": ["postgres-mcp", "redis-mcp"] } ] }Design decisions:
mcpServersconfig (same name shown in the UI).Test Procedure
modeConfigSchemainpackages/types/src/__tests__/mode.test.tsverifying the newallowedMcpServersfield (valid arrays, empty arrays, undefined, non-string rejection).getMcpServerTools()insrc/core/prompts/tools/native-tools/__tests__/mcp_server.spec.tscovering allowlist filtering (undefined passthrough, empty array passthrough, selective filtering, no-match, single server).Pre-Submission Checklist
.roomodesconfiguration may need updating to mention the newallowedMcpServersfield.Documentation Updates
allowedMcpServersfield in custom mode configuration.Additional Notes
Interactively review PR in Roo Code Cloud