Skip to main content

mcp_memory/
config.rs

1use crate::errors::Result;
2
3#[derive(Debug, Clone)]
4pub struct Config {
5    pub memory_file_path: String,
6}
7
8impl Config {
9    pub fn from_args(args: &super::Args) -> Result<Self> {
10        let memory_file_path = args
11            .memory_file
12            .clone()
13            .or_else(|| std::env::var("MEMORY_FILE_PATH").ok())
14            .unwrap_or_else(|| "memory.mcpmem".to_string());
15
16        Ok(Config { memory_file_path })
17    }
18}
19
20impl Default for Config {
21    fn default() -> Self {
22        Self {
23            memory_file_path: "memory.mcpmem".to_string(),
24        }
25    }
26}
27
28#[cfg(test)]
29mod tests {
30    use super::*;
31    use clap::Parser;
32    use crate::Args;
33
34    #[test]
35    fn test_config_defaults() {
36        let args = Args::parse_from(&["mcp-memory"]);
37        let cfg = Config::from_args(&args).unwrap();
38        assert_eq!(cfg.memory_file_path, "memory.mcpmem");
39    }
40
41    #[test]
42    fn test_config_custom_path() {
43        let args = Args::parse_from(&["mcp-memory", "--memory-file", "/tmp/test.jsonl"]);
44        let cfg = Config::from_args(&args).unwrap();
45        assert_eq!(cfg.memory_file_path, "/tmp/test.jsonl");
46    }
47}