mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-17 23:53:24 +02:00
Windows filesystem MCP enhancements (#543)
* fix: comprehensive Windows path handling improvements - Add path-utils module for consistent path handling - Handle Windows paths with spaces via proper quoting - Support Unix-style Windows paths (/c/path) - Support WSL paths (/mnt/c/path) - Add comprehensive test coverage - Fix path normalization for all path formats Closes #447 * tested locally and working now * Add filesystem path utils and tests * Ensure Windows drive letters are capitalized in normalizePath * adding test for gh pr comment * pushing jest and windows testing config * last commit? fixing comments on PR * Fix bin and bump sdk * Remove redundant commonjs version of path-utils and import from ts version * Remove copying cjs file * Remove copying run-server * Remove complex args parsing and do other cleanup * Add missing tools details to Readme * Move utility functions from index to lib * Add more tests and handle very small and very large files edge cases * Finish refactoring and include original security fix comments * On Windows, also check for drive root * Check symlink support on restricted Windows environments * Fix tests * Bump SDK and package version * Clean up --------- Co-authored-by: olaservo <olahungerford@gmail.com> Co-authored-by: adam jones <adamj+git@anthropic.com>
This commit is contained in:
@@ -68,10 +68,19 @@ export function isPathWithinAllowedDirectories(absolutePath: string, allowedDire
|
||||
}
|
||||
|
||||
// Special case for root directory to avoid double slash
|
||||
// On Windows, we need to check if both paths are on the same drive
|
||||
if (normalizedDir === path.sep) {
|
||||
return normalizedPath.startsWith(path.sep);
|
||||
}
|
||||
|
||||
// On Windows, also check for drive root (e.g., "C:\")
|
||||
if (path.sep === '\\' && normalizedDir.match(/^[A-Za-z]:\\?$/)) {
|
||||
// Ensure both paths are on the same drive
|
||||
const dirDrive = normalizedDir.charAt(0).toLowerCase();
|
||||
const pathDrive = normalizedPath.charAt(0).toLowerCase();
|
||||
return pathDrive === dirDrive && normalizedPath.startsWith(normalizedDir.replace(/\\?$/, '\\'));
|
||||
}
|
||||
|
||||
return normalizedPath.startsWith(normalizedDir + path.sep);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user