-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Resolve filesystem issue where WSL paths are incorrectly converted to Windows format #2851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Resolve filesystem issue where WSL paths are incorrectly converted to Windows format #2851
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a filesystem bug where WSL paths (/mnt/c/...
) were incorrectly converted to Windows format (C:\...
), causing ENOENT errors when running the filesystem server inside WSL. The fix ensures WSL paths are preserved in their original format since they work correctly with Node.js filesystem operations within the WSL environment.
- Prevents conversion of WSL paths to Windows format on all platforms
- Adds platform-aware path conversion logic for Unix-style Windows paths
- Adds comprehensive test coverage for the WSL path handling scenario
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/filesystem/path-utils.ts | Updated path normalization logic to preserve WSL paths and make Unix-style path conversion platform-dependent |
src/filesystem/tests/path-utils.test.ts | Added platform-aware tests and specific test case reproducing issue #2795 |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
const isUnixPath = p.startsWith('/') && ( | ||
// Always preserve WSL paths (/mnt/c/, /mnt/d/, etc.) | ||
p.match(/^\/mnt\/[a-z]\//i) || | ||
// On non-Windows platforms, treat all absolute paths as Unix paths | ||
(process.platform !== 'win32') || | ||
// On Windows, preserve Unix paths that aren't Unix-style Windows paths (/c/, /d/, etc.) | ||
(process.platform === 'win32' && !p.match(/^\/[a-zA-Z]\//)) | ||
); |
Copilot
AI
Oct 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The complex boolean logic with multiple conditions makes this code difficult to read and maintain. Consider extracting this into separate helper functions like isWSLPath()
, shouldPreserveAsUnixPath()
, etc., to improve readability and testability.
Copilot uses AI. Check for mistakes.
afterEach(() => { | ||
// Restore platform after each test | ||
Object.defineProperty(process, 'platform', { | ||
value: originalPlatform, | ||
writable: true, | ||
configurable: true | ||
}); | ||
}); |
Copilot
AI
Oct 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Mocking process.platform
by directly modifying the property can be unreliable and may affect other tests. Consider using a proper mocking library like jest.spyOn or creating a platform abstraction layer that can be easily mocked.
Copilot uses AI. Check for mistakes.
Fixes #2795
Description
This PR fixes a bug introduced in v2025.8.18 where WSL paths (
/mnt/c/...
) were being incorrectly converted to Windows format (C:\...
), causing ENOENT errors when running the filesystem server inside WSL.The root cause was in the path normalization logic that assumed WSL paths should be converted to Windows format. However, when Node.js runs inside WSL (via
wsl npx ...
), it uses Linux filesystem APIs that require Linux-style paths. Windows-style paths don't work with Node.js fs operations inside WSL.Server Details
path-utils.ts
)Motivation and Context
When users run Claude Desktop on Windows and configure it to use the filesystem server via WSL (e.g.,
wsl npx @modelcontextprotocol/server-filesystem /mnt/c/Users/...
), the server was converting the WSL paths to Windows format, causing them to become inaccessible:/mnt/c/Users/username/folder
C:\Users\username\folder
ENOENT: no such file or directory
because Windows paths don't work inside WSLThis regression broke existing Claude Desktop configurations that rely on running the filesystem server through WSL.
Changes Made
src/filesystem/path-utils.ts
:convertToWindowsPath()
function:/mnt/...
) are now never converted regardless of platform/c/...
) are only converted when running on Windows (process.platform === 'win32'
)normalizePath()
function:/
are treated as Unix pathssrc/filesystem/__tests__/path-utils.test.ts
:How Has This Been Tested?
win32
) and Linux platformsBreaking Changes
No
Types of changes
Checklist
Additional context
This fix assumes that WSL paths (
/mnt/...
) should never be converted because: