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