pub struct Redactor { /* private fields */ }Expand description
Output redactor that scrubs API keys, tokens, emails, and sensitive JSON keys from MCP tool output. Applies built-in patterns plus optional custom regexes.
Implementations§
Source§impl Redactor
impl Redactor
Sourcepub fn try_new(custom_patterns: &[String]) -> Result<Self, Error>
pub fn try_new(custom_patterns: &[String]) -> Result<Self, Error>
Build a redactor with custom patterns.
§Errors
Returns regex::Error if any custom pattern (or a built-in pattern) fails to compile.
Sourcepub fn new(custom_patterns: &[String]) -> Self
pub fn new(custom_patterns: &[String]) -> Self
Build a redactor with custom patterns, logging a warning and skipping any invalid patterns.
If the built-in redaction patterns fail to compile (a bug), falls back to an empty set and logs an error rather than panicking.
Sourcepub fn redact(&self, input: &str) -> String
pub fn redact(&self, input: &str) -> String
Scrub sensitive data from input using regex patterns and JSON-key matching.
Passes, in order: the value patterns (API keys, bearer tokens, JWTs, emails, … plus any
custom patterns); credential parameters in URLs (?access_token=…, &sig=…); then keys.
Key-based redaction applies to the whole output when it is JSON — including JSON carried
inside its string values (IPC/network bodies are JSON-encoded strings) — and otherwise to
"key": value pairs found in the text. Best effort: see the limits in docs/src/security.md.