use filesystem_mcp_rust::{FilesystemServer, McpRequest};
use std::io::{self, BufRead};
use std::env;
fn main() {
let mut server = FilesystemServer::new();
let args: Vec<String> = env::args().collect();
let allowed_dirs = if args.len() > 1 {
args[1..].join(";")
} else {
".".to_string()
};
server.allowed_directories = allowed_dirs.split(';')
.map(|s| {
let path = std::path::PathBuf::from(s);
if path == std::path::PathBuf::from(".") {
match std::env::current_dir() {
Ok(current_dir) => current_dir,
Err(_) => path
}
} else {
path
}
})
.collect();
let stdin = io::stdin();
for line in stdin.lock().lines() {
let line = match line {
Ok(line) => line,
Err(e) => {
eprintln!("Error reading input: {}", e);
continue;
}
};
let request: McpRequest = match serde_json::from_str(&line) {
Ok(req) => req,
Err(e) => {
eprintln!("Error parsing JSON: {}", e);
continue;
}
};
let response = server.handle_request(request);
if let Some(response) = response {
println!("{}", serde_json::to_string(&response).unwrap());
}
}
}