feat(router): support runtime disabling of tools#809
Open
lutz-grex wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
feat(router): support runtime disabling of tools#809lutz-grex wants to merge 1 commit intomodelcontextprotocol:mainfrom
lutz-grex wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
Add methods to disable/enable tools at runtime. Disabled tools are hidden from listing, lookup, and execution, including in composed routers. Closes modelcontextprotocol#477
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.
Add methods to disable/enable tools at runtime.
Disabled tools are hidden from listing, lookup,
and execution, including in composed routers.
Closes #477
Motivation and Context
Users of the
#[tool]+#[tool_handler]macro system had no way to disable specific tools at runtime. The only workaround was manually implementingServerHandler, losing all macro convenience, or usingremove_routewhich permanently destroys the tool.This change adds reversible disable/enable support directly to
ToolRouter, composing naturally with the existing macro workflow:How Has This Been Tested?
test_tool_routers.rscovering:disable, enable, builder pattern, merge preservation,
remove cleanup, pre-disable before add, iterator
filtering, and full invisibility across all query methods
cargo test -p rmcp)disable_routeandenable_routedo not compile on the baseline and workcorrectly after the change
cargo clippy --all-targets --all-featurescleancargo +nightly fmt --allcleanBreaking Changes
has_routenow returnsfalsefor disabled tools (previouslyit only checked map membership). Code relying on
has_routeto test structural presence regardless of enabled state should
use
is_disabledinstead. TheToolRouterstruct is#[non_exhaustive], so adding the privatedisabledfield isnot a breaking change.
Types of changes
Checklist
Additional context
Three files changed:
crates/rmcp/src/handler/server/router/tool.rs— corefeature:
disabledHashSet field, disable/enable/is_disabled/with_disabled methods, updated list_all/call/get/has_route
/merge/remove_route/IntoIterator
crates/rmcp/src/handler/server/router.rs— one-line fix:transparent_when_not_founddispatch now checksis_disabledso disabled tools cannot leak through to the inner service
crates/rmcp/tests/test_tool_routers.rs— 9 new tests