feat: add exclude and excludeRegex support for tool selectors#1963
feat: add exclude and excludeRegex support for tool selectors#1963majiayu000 wants to merge 5 commits intoenvoyproxy:mainfrom
Conversation
Add Exclude and ExcludeRegex fields to MCPToolFilter to support exclusion-based tool filtering. Exclude rules take precedence over include rules (deny-wins model). Signed-off-by: majiayu000 <1835304752@qq.com>
Signed-off-by: majiayu000 <1835304752@qq.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1963 +/- ##
==========================================
- Coverage 84.22% 82.29% -1.93%
==========================================
Files 128 156 +28
Lines 17828 18479 +651
==========================================
+ Hits 15016 15208 +192
- Misses 1868 2328 +460
+ Partials 944 943 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: majiayu000 <1835304752@qq.com>
|
Related Documentation 4 document(s) may need updating based on files changed in this PR: Envoy's Space 2025-10-02-mcp-implementation
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces Exclude and ExcludeRegex fields for tool filtering, which is a great enhancement. The changes are well-implemented across the API, controller, and proxy layers, with comprehensive tests and documentation updates. I've identified one high-severity issue related to an unintended side effect in the configuration comparison logic and a medium-severity issue regarding code duplication. Overall, this is a solid contribution.
- Clone regex slices before sorting in sameTools to avoid in-place mutation side effects on configuration objects - Extract compileRegexps helper to deduplicate include/exclude regex compilation logic Signed-off-by: majiayu000 <1835304752@qq.com>
Add unit tests for sameTools covering different exclude keys, different include/exclude regexps, and exclude regexp ordering. Signed-off-by: majiayu000 <1835304752@qq.com>
Description
Add
ExcludeandExcludeRegexfields toMCPToolFilterfor exclusion-based tool filtering, complementing the existingInclude/IncludeRegexfields. Exclude rules take precedence over include rules (deny-wins semantics).Fixes #1921
Changes
Modified across 4 layers:
api/v1alpha1/mcp_route.go): New fields withMaxItems=32validation. CEL rules enforce mutual exclusivity within include/exclude pairs and require at least one field set.internal/filterapi/mcpconfig.go): Mirror fields inMCPToolSelector.internal/mcpproxy/config.go): Compiled exclude map + regexps.allows()checks excludes first for short-circuit denial.internal/controller/gateway.go): Field mapping from CRD to filterapi.Test Plan
allows(): exclude-only, excludeRegex-only, include+exclude combo, include+excludeRegex comboLoadConfigtests for exclude parsing and invalid regex error handlingmake precommitandmake testpass