mcp_context_server/
config.rs1use std::path::PathBuf;
2use std::time::Duration;
3
4const DEFAULT_TOOL_TIMEOUT_SECS: u64 = 30;
6
7#[derive(Debug, Clone)]
9pub struct ServerConfig {
10 pub cache_root: PathBuf,
11 pub tool_timeout: Duration,
12}
13
14impl ServerConfig {
15 pub fn from_env() -> Result<Self, String> {
20 let cache_root = std::env::var("CONTEXT_CACHE_ROOT")
21 .map(PathBuf::from)
22 .map_err(|_| "CONTEXT_CACHE_ROOT environment variable is not set".to_string())?;
23
24 let tool_timeout_secs = match std::env::var("CONTEXT_TOOL_TIMEOUT_SECS") {
25 Ok(val) => val
26 .parse::<u64>()
27 .map_err(|_| "CONTEXT_TOOL_TIMEOUT_SECS must be a positive integer".to_string())?,
28 Err(_) => DEFAULT_TOOL_TIMEOUT_SECS,
29 };
30
31 Ok(Self {
32 cache_root,
33 tool_timeout: Duration::from_secs(tool_timeout_secs),
34 })
35 }
36}