use pulseengine_mcp_protocol::Implementation;
use std::collections::HashMap;
use uuid::Uuid;
#[derive(Debug, Clone)]
pub struct RequestContext {
pub request_id: Uuid,
pub metadata: HashMap<String, String>,
pub client_info: Option<Implementation>,
pub authenticated_user: Option<String>,
pub roles: Vec<String>,
}
impl RequestContext {
pub fn new() -> Self {
Self {
request_id: Uuid::new_v4(),
metadata: HashMap::new(),
client_info: None,
authenticated_user: None,
roles: vec![],
}
}
pub fn with_id(request_id: Uuid) -> Self {
Self {
request_id,
metadata: HashMap::new(),
client_info: None,
authenticated_user: None,
roles: vec![],
}
}
pub fn with_client_info(mut self, client_info: Implementation) -> Self {
self.client_info = Some(client_info);
self
}
pub fn with_user(mut self, user: impl Into<String>) -> Self {
self.authenticated_user = Some(user.into());
self
}
pub fn with_role(mut self, role: impl Into<String>) -> Self {
self.roles.push(role.into());
self
}
pub fn with_metadata(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.metadata.insert(key.into(), value.into());
self
}
pub fn get_metadata(&self, key: &str) -> Option<&String> {
self.metadata.get(key)
}
pub fn has_role(&self, role: &str) -> bool {
self.roles.contains(&role.to_string())
}
pub fn is_authenticated(&self) -> bool {
self.authenticated_user.is_some()
}
}
impl Default for RequestContext {
fn default() -> Self {
Self::new()
}
}