Skip to content

Conversation

@Rexarrior
Copy link
Contributor

@Rexarrior Rexarrior commented May 13, 2025

Related GitHub Issue

Closes: #3346

Description

This PR introduces a new feature allowing users to toggle whether an individual MCP (Model Context Protocol) tool is included in the context provided to the AI model. This gives users finer-grained control over which tools the AI can see and potentially use.

The changes include:

  • Core Logic (McpHub.ts):
    • Added a disabledForPromptTools array to the MCP server configuration in mcp.json (both project and global).
    • Implemented toggleToolEnabledForPrompt method to add/remove tool names from this disabledForPromptTools list.
    • Modified fetchToolsList to populate an enabledForPrompt boolean on each tool object based on whether it's in the disabledForPromptTools list.
  • Prompt Generation (mcp-servers.ts):
    • Updated the prompt section generation to filter tools based on the new tool.enabledForPrompt flag.
    • Add related instruction in create-mcp-server prompt (set to [])
  • Webview Communication (webviewMessageHandler.ts, WebviewMessage.ts):
    • Added a new toggleToolEnabledForPrompt message type and handler to facilitate communication between the webview UI and the extension backend.
  • Shared Types (mcp.ts):
    • Added enabledForPrompt?: boolean to the McpTool type.
  • UI (McpToolRow.tsx, mcp.json i18n):
    • Added a new toggle switch UI component in the MCP server settings for each tool.
    • This switch allows users to enable/disable a tool's inclusion in the prompt.
    • Added new i18n string for the toggle's title.

Test Procedure

Unit Tests:

  • McpHub.test.ts:
    • add tool to disabledForPromptTools list when enabling
    • remove tool from disabledForPromptTools list when disabling
    • initialize disabledForPromptTools if it does not exist
  • Manual testing
    • tool not included in prompt, when disabled
    • tool included in prompt when enabled
    • default is enabled

Manual Testing Steps:

  1. Navigate to the Roo MCP settings page in VS Code.
  2. For a connected MCP server with multiple tools:
    a. Locate the new toggle switch next to each tool (it might look like a slider).
    b. Verify Initial State: Observe the initial state of the toggles.
    c. Toggle Off: Click the toggle for a specific tool to disable its inclusion in the prompt.
    i. Check the corresponding mcp.json file (either project's .roo/mcp.json or global MCP settings) to ensure the tool's name is added to the disabledForPromptTools array for that server.
    ii.Verify that when a prompt is generated that would normally include MCP tools, this specific tool is now omitted from the context.
    d. Toggle On: Click the toggle again for the same tool to re-enable its inclusion in the prompt.
    i. Check the mcp.json file again to ensure the tool's name is removed from the disabledForPromptTools array.
    ii. Verify the tool is now included in the prompt context.
  3. Test with both project-level (.roo/mcp.json) and global MCP configurations if applicable.
  4. Ensure the "Always Allow" checkbox functionality remains independent and unaffected.

Type of Change

  • 🐛 Bug Fix: Non-breaking change that fixes an issue.
  • New Feature: Non-breaking change that adds functionality.
  • 💥 Breaking Change: Fix or feature that would cause existing functionality to not work as expected.
  • ♻️ Refactor: Code change that neither fixes a bug nor adds a feature.
  • 💅 Style: Changes that do not affect the meaning of the code (white-space, formatting, etc.).
  • 📚 Documentation: Updates to documentation files.
  • ⚙️ Build/CI: Changes to the build process or CI configuration.
  • 🧹 Chore: Other changes that don't modify src or test files.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Code Quality:
    • My code adheres to the project's style guidelines.
    • There are no new linting errors or warnings (npm run lint).
    • All debug code (e.g., console.log) has been removed.
  • Testing:
    • New and/or updated tests have been added to cover my changes.
    • All tests pass locally (npm test).
    • The application builds successfully with my changes.
  • Branch Hygiene: My branch is up-to-date (rebased) with the main branch.
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Changeset: A changeset has been created using npm run changeset if this PR includes user-facing changes or dependency updates.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

Before:
[Link to Before Screenshot/Video - e.g., showing the MCP tool row without the new toggle]
image

After:
[Link to After Screenshot/Video - e.g., showing the MCP tool row WITH the new toggle, and demonstrating its on/off states]
image

Documentation Updates

  • No documentation updates are required. (The UI change is self-explanatory within the settings page).

Additional Notes

This feature enhances user control over the AI's context, potentially improving relevance and reducing token usage by excluding unnecessary tools from prompts.


Important

Add toggle feature for MCP tool visibility in AI prompts, with updates to core logic, UI, and tests.

  • Core Logic (McpHub.ts):
    • Added disabledForPromptTools array in mcp.json for tool management.
    • Implemented toggleToolEnabledForPrompt to manage tool visibility in prompts.
    • Updated fetchToolsList to set enabledForPrompt flag.
  • Prompt Generation (mcp-servers.ts):
    • Modified prompt generation to filter tools by enabledForPrompt.
  • Webview Communication (webviewMessageHandler.ts, WebviewMessage.ts):
    • Added toggleToolEnabledForPrompt message type for UI-backend communication.
  • Shared Types (mcp.ts):
    • Added enabledForPrompt to McpTool type.
  • UI (McpToolRow.tsx, mcp.json i18n):
    • Added toggle switch for tool inclusion in prompts.
    • Updated i18n strings for toggle functionality.
  • Tests (McpHub.test.ts):
    • Added tests for enabling/disabling tools in prompts and initializing disabledForPromptTools.

This description was created by Ellipsis for 765157e0ed73cefff3af36d18eaf19ebbe858155. You can customize this summary. It will automatically update as commits are pushed.

@changeset-bot
Copy link

changeset-bot bot commented May 13, 2025

🦋 Changeset detected

Latest commit: 34da2f07f094e315fe2fed3899f9bf7a8475b314

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
roo-cline Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels May 13, 2025
@hannesrudolph hannesrudolph moved this from New to PR [Pre Approval Review] in Roo Code Roadmap May 14, 2025
@Rexarrior Rexarrior changed the title add toggle for disable mcp server tool from prompt feature: add toggle for disable mcp server tool from prompt May 15, 2025
@Rexarrior
Copy link
Contributor Author

Guys, should i do something more here?

@hannesrudolph hannesrudolph moved this from New to PR [Pre Approval Review] in Roo Code Roadmap May 20, 2025
@hannesrudolph hannesrudolph moved this from PR [Needs Review] to TEMP in Roo Code Roadmap May 26, 2025
@daniel-lxs daniel-lxs moved this from TEMP to PR [Needs Review] in Roo Code Roadmap May 27, 2025
@daniel-lxs
Copy link
Member

Hey @Rexarrior, Thank you for your contribution.
I apologize for taking so long to review your PR, we are trying to review PRs sooner.

@daniel-lxs
Copy link
Member

I really like this, works without any issues.

The only thing I would suggest for improvement is the naming of disabledForPromptTools. Consider renaming it to excludedFromPromptTools as it would be more semantically accurate (tools are excluded from the prompt, not disabled) and would avoid double negatives in the code logic.

I made the switch look more like the one in McpView.tsx.

Other than that this looks good to me.

@daniel-lxs daniel-lxs moved this from PR [Needs Preliminary Review] to PR [Needs Review] in Roo Code Roadmap May 28, 2025
@daniel-lxs daniel-lxs moved this from PR [Needs Review] to PR [Changes Requested] in Roo Code Roadmap May 28, 2025
@daniel-lxs daniel-lxs moved this from PR [Changes Requested] to PR [Needs Prelim Review] in Roo Code Roadmap Jun 2, 2025
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Needs Review] in Roo Code Roadmap Jun 19, 2025
@mrubens
Copy link
Collaborator

mrubens commented Jun 20, 2025

Is the test failure legit?

@daniel-lxs
Copy link
Member

@mrubens
No, it seems to be unrelated

@daniel-lxs daniel-lxs force-pushed the very-clean-mcp-tool-toggle branch from 23b08da to e757bd4 Compare June 20, 2025 21:54
@daniel-lxs
Copy link
Member

daniel-lxs commented Jun 20, 2025

@mrubens
I rebased and everything looks good.

@mrubens mrubens merged commit d99ae58 into RooCodeInc:main Jun 20, 2025
10 checks passed
@github-project-automation github-project-automation bot moved this from PR [Pre Approval Review] to Done in Roo Code Roadmap Jun 20, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Jun 20, 2025
cte pushed a commit that referenced this pull request Jun 24, 2025
* add toggle for disable mcp server tool from prompt

* languages

* fix error message

* Update src/core/prompts/instructions/create-mcp-server.ts

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>

* fix build

* typo

* refactor: make the switch style consistent

* respect review

* refactor: improve layout and styling in McpToolRow component

* fix: update new mcp tests

* tailwind css for disabledTool swipper

* id locale (from main)

* fix: improve error message for updating tool settings

* fix: specify type for serverConfigData as Record<string, any>

* fix: enhance UI layout and improve accessibility for tool controls

* fix: migrate jest.Mock to vitest Mock type

* Update .changeset/slimy-years-smell.md

* fix: replace enabled switch with button

---------

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
Co-authored-by: Daniel <[email protected]>
Co-authored-by: Daniel Riccio <[email protected]>
Co-authored-by: Matt Rubens <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer PR - Needs Review size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

MCP server tool on\off toggle

4 participants