pub enum NameFilter {
PassAll,
AllowList(Vec<CompiledPattern>),
DenyList(Vec<CompiledPattern>),
}Expand description
A name-based allow/deny filter.
Patterns support two syntaxes:
- Glob (default):
*matches any sequence,?matches one character. - Regex (
re:prefix): e.g.re:^list_.*$uses theregexcrate.
Regex patterns are compiled once at config parse time.
Variants§
PassAll
No filtering – everything passes.
AllowList(Vec<CompiledPattern>)
Only items matching at least one pattern are allowed.
DenyList(Vec<CompiledPattern>)
Items matching any pattern are denied.
Implementations§
Source§impl NameFilter
impl NameFilter
Sourcepub fn allow_list(patterns: impl IntoIterator<Item = String>) -> Result<Self>
pub fn allow_list(patterns: impl IntoIterator<Item = String>) -> Result<Self>
Build an allow-list filter from raw pattern strings.
Patterns prefixed with re: are compiled as regular expressions;
all others are treated as glob patterns.
§Errors
Returns an error if any re: pattern contains invalid regex syntax.
Sourcepub fn deny_list(patterns: impl IntoIterator<Item = String>) -> Result<Self>
pub fn deny_list(patterns: impl IntoIterator<Item = String>) -> Result<Self>
Build a deny-list filter from raw pattern strings.
Patterns prefixed with re: are compiled as regular expressions;
all others are treated as glob patterns.
§Errors
Returns an error if any re: pattern contains invalid regex syntax.
Sourcepub fn allows(&self, name: &str) -> bool
pub fn allows(&self, name: &str) -> bool
Check if a capability name is allowed by this filter.
Supports glob patterns (*, ?) and regex patterns (re: prefix).
Exact strings match themselves.
§Examples
use mcp_proxy::config::NameFilter;
let filter = NameFilter::deny_list(["delete".to_string()]).unwrap();
assert!(filter.allows("read"));
assert!(!filter.allows("delete"));
let filter = NameFilter::allow_list(["read".to_string()]).unwrap();
assert!(filter.allows("read"));
assert!(!filter.allows("write"));
assert!(NameFilter::PassAll.allows("anything"));
// Glob patterns
let filter = NameFilter::allow_list(["*_file".to_string()]).unwrap();
assert!(filter.allows("read_file"));
assert!(filter.allows("write_file"));
assert!(!filter.allows("query"));
// Regex patterns
let filter = NameFilter::allow_list(["re:^list_.*$".to_string()]).unwrap();
assert!(filter.allows("list_files"));
assert!(!filter.allows("get_files"));Trait Implementations§
Source§impl Clone for NameFilter
impl Clone for NameFilter
Source§fn clone(&self) -> NameFilter
fn clone(&self) -> NameFilter
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for NameFilter
impl RefUnwindSafe for NameFilter
impl Send for NameFilter
impl Sync for NameFilter
impl Unpin for NameFilter
impl UnsafeUnpin for NameFilter
impl UnwindSafe for NameFilter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more