Skip to main content

ai_agent/services/mcp/
auth.rs

1// Source: /data/home/swei/claudecode/openclaudecode/src/types/generated/events_mono/common/v1/auth.ts
2//! MCP Authentication module
3
4use serde::{Deserialize, Serialize};
5
6/// MCP authentication config
7#[derive(Debug, Clone, Default, Serialize, Deserialize)]
8pub struct AuthConfig {
9    pub enabled: bool,
10    pub auth_type: Option<String>,
11    pub token: Option<String>,
12}
13
14/// MCP OAuth configuration
15#[derive(Debug, Clone, Default, Serialize, Deserialize)]
16pub struct OAuthConfig {
17    pub client_id: Option<String>,
18    pub client_secret: Option<String>,
19    pub redirect_uri: Option<String>,
20    pub scopes: Vec<String>,
21}
22
23/// Get MCP auth headers
24pub fn get_auth_headers(config: &AuthConfig) -> std::collections::HashMap<String, String> {
25    let mut headers = std::collections::HashMap::new();
26
27    if let Some(token) = &config.token {
28        headers.insert("Authorization".to_string(), format!("Bearer {}", token));
29    }
30
31    headers
32}
33
34/// Check if auth is required for an MCP server
35pub fn is_auth_required(config: &AuthConfig) -> bool {
36    config.enabled && config.auth_type.is_some()
37}