Repository navigation
Add McpServerToolFilter for MCP servers - #7201
Open
ZhangDT-sky wants to merge 1 commit into
Open
ZhangDT-sky wants to merge 1 commit into
ZhangDT-sky wants to merge 1 commit into
Conversation
Introduce `McpServerToolFilter`, an `Ordered` SPI consulted for every `tools/list` request, and wire the ordered chain into the sync and async builders of both the stateful and stateless MCP servers. A tool hidden by a filter is omitted from listings only: it stays reachable through `tools/call`, so authorization still belongs in the tool handler. The SPI documents this and the tests pin it down. See spring-projects#7192 Signed-off-by: ZhangDT-sky <485918776@qq.com>
This was referenced Oct 28, 2026
Open
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.
Description
Introduce
McpServerToolFilter, anOrderedSPI consulted for everytools/listrequest, and wire the ordered chain into the sync and async builders of both the stateful and stateless MCP servers.A tool hidden by a filter is omitted from listings only: it stays reachable through
tools/call, so authorization still belongs in the tool handler. The SPI documents this and the tests pin it down.Filters are consulted in
Orderedorder and combined with AND semantics, short-circuiting at the first rejection. The async path offloads the chain off the reactor event loop, since an implementation may perform blocking work such as a security decision.Scope
This covers "hide what this caller cannot call", the common denominator of the issues consolidated in #7192. It does not cover the rest of #7192:
McpSyncListFilterreturns a boolean; theToolis fixed when the specification is builttools/callMethodand its beanThose require the
McpSyncToolRepositoryextension point from modelcontextprotocol/java-sdk#1170, released as the2.2.0-M1pre-release. It ownslist/find/callbehind one per-request context, which is the shape the remaining asks need. Building a filter hook that a wrapper would silently bypass seemed worse than shipping the part that works on the current SDK.Notes for review
McpSyncServerCustomizer,McpAsyncServerCustomizer,McpStatelessSyncServerCustomizerandMcpStatelessAsyncServerCustomizerall expose the builder, soaddToolFilteris already reachable from them. But they are four distinct types, so a caller filtering per request would need one bean per mode, the same filter logic duplicated in each, and prior knowledge of which mode the application runs in. This SPI keeps it to a single bean covering all four.McpTransportContextandMcpSchema.Toolrather than a tool specification. That keeps a single extension point for all four server flavors, and covers tools registered through@McpToolas well as through@Tool/ToolCallback, which produce different specification types.spring-ai-mcp, next to the client-sideMcpToolFilterit mirrors.McpServerToolFilterAdapterTestscovers the chain; end-to-endtools/listassertions run against both the stateless and the stateful WebFlux server, each also asserting that the hidden tool still executes.Per-Caller Tool Filteringsection inmcp-annotations-server.adoc.See #7192