@@ -38,6 +38,7 @@ if (args.length === 0) {
38
38
console . error ( " 1. Command-line arguments (shown above)" ) ;
39
39
console . error ( " 2. MCP roots protocol (if client supports it)" ) ;
40
40
console . error ( "At least one directory must be provided by EITHER method for the server to operate." ) ;
41
+ console . error ( "Note: Directories will be validated at startup but operations will be retried at runtime." ) ;
41
42
}
42
43
43
44
// Store allowed directories in normalized and resolved form
@@ -58,22 +59,33 @@ let allowedDirectories = await Promise.all(
58
59
} )
59
60
) ;
60
61
61
- // Validate that all directories exist and are accessible
62
- await Promise . all ( allowedDirectories . map ( async ( dir ) => {
63
- try {
64
- const stats = await fs . stat ( dir ) ;
65
- if ( ! stats . isDirectory ( ) ) {
66
- console . error ( `Error: ${ dir } is not a directory` ) ;
67
- process . exit ( 1 ) ;
62
+ // Validate directories at startup - log warnings if path is not accessible at startup.
63
+ // Directory accessibility may change between startup and runtime.
64
+ const validatedDirectories = await Promise . all (
65
+ allowedDirectories . map ( async ( dir ) => {
66
+ try {
67
+ const stats = await fs . stat ( dir ) ;
68
+ if ( stats . isDirectory ( ) ) {
69
+ console . log ( `Directory accessible: ${ dir } ` ) ;
70
+ return dir ;
71
+ } else if ( stats . isFile ( ) ) {
72
+ console . warn ( `${ dir } is a file, not a directory - skipping` ) ;
73
+ return null ;
74
+ } else {
75
+ // Include symlinks/special files - they might become directories when NAS/VPN reconnects
76
+ console . warn ( `${ dir } is not a directory (${ stats . isSymbolicLink ( ) ? 'symlink' : 'special file' } )` ) ;
77
+ return dir ;
78
+ }
79
+ } catch ( error ) {
80
+ // Include inaccessible paths - they might become accessible when storage/network reconnects
81
+ console . warn ( `Directory not accessible: ${ dir } - ${ error instanceof Error ? error . message : String ( error ) } ` ) ;
82
+ return dir ;
68
83
}
69
- } catch ( error ) {
70
- console . error ( `Error accessing directory ${ dir } :` , error ) ;
71
- process . exit ( 1 ) ;
72
- }
73
- } ) ) ;
84
+ } )
85
+ ) . then ( results => results . filter ( ( dir ) : dir is string => dir !== null ) ) ;
74
86
75
87
// Initialize the global allowedDirectories in lib.ts
76
- setAllowedDirectories ( allowedDirectories ) ;
88
+ setAllowedDirectories ( validatedDirectories ) ;
77
89
78
90
// Schema definitions
79
91
const ReadTextFileArgsSchema = z . object ( {
0 commit comments