filesystem-mcp-rust 0.0.1

A Model Context Protocol (MCP) server for advanced filesystem operations with file handling capabilities
Documentation
use filesystem_mcp_rust::{FilesystemServer, McpRequest};
use std::io::{self, BufRead};
use std::env;

fn main() {
    let mut server = FilesystemServer::new();
    
    // Parse command line arguments
    let args: Vec<String> = env::args().collect();
    
    // Default to current directory if no arguments provided
    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 the path is ".", resolve it to the current working directory
            if path == std::path::PathBuf::from(".") {
                match std::env::current_dir() {
                    Ok(current_dir) => current_dir,
                    Err(_) => path
                }
            } else {
                path
            }
        })
        .collect();

    // Don't print startup message - MCP expects only JSON communication
    // 不要打印启动消息 - MCP 只期望 JSON 通信
    
    let stdin = io::stdin();
    for line in stdin.lock().lines() {
        let line = match line {
            Ok(line) => line,
            Err(e) => {
                // Only print errors to stderr, not stdout
                eprintln!("Error reading input: {}", e);
                continue;
            }
        };
        
        // Parse the JSON-RPC request
        let request: McpRequest = match serde_json::from_str(&line) {
            Ok(req) => req,
            Err(e) => {
                // Only print errors to stderr, not stdout
                eprintln!("Error parsing JSON: {}", e);
                continue;
            }
        };
        
        let response = server.handle_request(request);
        if let Some(response) = response {
            // Always output valid JSON to stdout
            println!("{}", serde_json::to_string(&response).unwrap());
        }
    }
}