pub struct RedactedUrl<'a>(pub &'a str);Expand description
Debug-formats a URL with userinfo credentials and query string hidden, keeping the scheme, host, and path readable.
A URL can carry a secret two ways: user:pass@host userinfo, or a
?api_key=...-style query parameter. Both are stripped; everything else
(scheme, host, path) is left intact since it’s the most useful part of a
URL for telling two server entries apart in a log.
This is deliberately parse-free (mcp-core does not depend on the url
crate) rather than a strict parser: if the input doesn’t contain ://, if
the scheme before it contains a character that is never valid in a URI
scheme, or if userinfo redaction would be ambiguous (see below), the whole
input is treated as unparseable and redacted in full — mirroring the
discard-on-parse-failure rule mcp-execution-cli already applies when
deriving a server ID from a URL. Ambiguity arises when the authority
terminator (the first /, ?, or # after the scheme) lands inside
unencoded userinfo rather than at a true authority boundary — e.g. an
unencoded / in a password — which would otherwise let the userinfo
escape redaction entirely. Detected by checking whether an @ still
appears after that terminator.
§Examples
A URL with userinfo and a query string has both hidden, while the host and path stay readable:
use mcp_execution_core::RedactedUrl;
let url = "https://user:sk-secret@api.example.com/mcp?token=sk-secret";
let debug_output = format!("{:?}", RedactedUrl(url));
assert!(!debug_output.contains("sk-secret"));
assert!(debug_output.contains("api.example.com/mcp"));A plain URL with neither is unchanged:
use mcp_execution_core::RedactedUrl;
let url = "https://api.example.com/mcp";
let debug_output = format!("{:?}", RedactedUrl(url));
assert_eq!(debug_output, "https://api.example.com/mcp");Tuple Fields§
§0: &'a strTrait Implementations§
Source§impl<'a> Clone for RedactedUrl<'a>
impl<'a> Clone for RedactedUrl<'a>
Source§fn clone(&self) -> RedactedUrl<'a>
fn clone(&self) -> RedactedUrl<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more