Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/tools/mcp/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ use crate::tools::mcp::config::McpServerConfig;
/// Per-request timeouts can override the default via `.timeout()` on
/// the request builder.
fn oauth_http_client() -> Result<&'static reqwest::Client, AuthError> {
static CLIENT: std::sync::OnceLock<Result<reqwest::Client, String>> =
static CLIENT: std::sync::OnceLock<Result<reqwest::Client, AuthError>> =
std::sync::OnceLock::new();
CLIENT
.get_or_init(|| {
reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.redirect(reqwest::redirect::Policy::none())
.build()
.map_err(|e| e.to_string())
.map_err(|e| AuthError::Http(e.to_string()))
})
.as_ref()
.map_err(|e| AuthError::Http(e.clone()))
.map_err(Clone::clone)
}

/// Log a debug message when a discovery/auth response is a redirect.
Expand All @@ -57,7 +57,7 @@ fn log_redirect_if_applicable(url: &str, response: &reqwest::Response) {
}

/// OAuth authorization error.
#[derive(Debug, thiserror::Error)]
#[derive(Debug, Clone, thiserror::Error)]
pub enum AuthError {
#[error("Server does not support OAuth authorization")]
NotSupported,
Expand Down Expand Up @@ -1511,6 +1511,17 @@ mod tests {
}
}

#[test]
fn test_auth_error_clone_preserves_http_variant_and_payload() {
let original = AuthError::Http("builder failed".to_string());
let cloned = original.clone();

match cloned {
AuthError::Http(message) => assert_eq!(message, "builder failed"), // safety: test assertion in #[cfg(test)] module; not production panic path
other => panic!("expected AuthError::Http variant, got {other:?}"),
}
}

// --- New tests for well-known URI construction ---

#[test]
Expand Down
Loading