From 5ccb90b2a70c794184eb2666aedb96d7eb474789 Mon Sep 17 00:00:00 2001 From: Sean-Kenneth-Doherty Date: Sat, 31 Jan 2026 07:25:54 -0600 Subject: [PATCH] fix(filesystem): gracefully handle unavailable directories on startup Instead of failing entirely when any configured allowed directory is unavailable (e.g., unmounted network volume, disconnected external drive), the server now: - Warns about each unavailable directory and skips it - Continues starting with all available directories - Only fails if NO directories are accessible This makes the filesystem MCP server more resilient for setups involving: - Network shares/NAS devices - External drives - Mounted volumes - Any path that might be temporarily unavailable Fixes #3232 --- src/filesystem/index.ts | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/src/filesystem/index.ts b/src/filesystem/index.ts index 48a599fae1..1944314b30 100644 --- a/src/filesystem/index.ts +++ b/src/filesystem/index.ts @@ -56,19 +56,36 @@ let allowedDirectories = await Promise.all( }) ); -// Validate that all directories exist and are accessible -await Promise.all(allowedDirectories.map(async (dir) => { - try { - const stats = await fs.stat(dir); - if (!stats.isDirectory()) { - console.error(`Error: ${dir} is not a directory`); - process.exit(1); +// Validate directories and filter to only accessible ones +const unavailableDirectories: string[] = []; +const validatedDirectories = await Promise.all( + allowedDirectories.map(async (dir) => { + try { + const stats = await fs.stat(dir); + if (!stats.isDirectory()) { + console.error(`Warning: ${dir} is not a directory, skipping`); + unavailableDirectories.push(dir); + return null; + } + return dir; + } catch (error) { + // Directory doesn't exist or is inaccessible (e.g., unmounted network volume) + console.error(`Warning: Directory ${dir} is not accessible, skipping: ${(error as Error).message}`); + unavailableDirectories.push(dir); + return null; } - } catch (error) { - console.error(`Error accessing directory ${dir}:`, error); - process.exit(1); - } -})); + }) +); + +// Filter out null entries (unavailable directories) +allowedDirectories = validatedDirectories.filter((dir): dir is string => dir !== null); + +// Only fail if NO directories are available +if (allowedDirectories.length === 0) { + console.error("Error: No accessible directories available. At least one directory must be accessible."); + console.error("Unavailable directories:", unavailableDirectories.join(", ")); + process.exit(1); +} // Initialize the global allowedDirectories in lib.ts setAllowedDirectories(allowedDirectories);