Skip to content

Conversation

olaservo
Copy link
Member

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

  • Server: filesystem
  • Changes to: Path normalization utilities (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:

  • Input: /mnt/c/Users/username/folder
  • Broken behavior: Converted to C:\Users\username\folder
  • Result: ENOENT: no such file or directory because Windows paths don't work inside WSL

This regression broke existing Claude Desktop configurations that rely on running the filesystem server through WSL.

Changes Made

src/filesystem/path-utils.ts:

  1. convertToWindowsPath() function:

    • WSL paths (/mnt/...) are now never converted regardless of platform
    • Unix-style Windows paths (/c/...) are only converted when running on Windows (process.platform === 'win32')
  2. normalizePath() function:

    • Updated path detection logic to always preserve WSL paths
    • On non-Windows platforms, all absolute paths starting with / are treated as Unix paths
    • Forward slash to backslash conversion only happens on Windows platform

src/filesystem/__tests__/path-utils.test.ts:

How Has This Been Tested?

  • All 133 unit tests pass (added 1 new test)
  • Platform-specific tests verify behavior on both Windows (win32) and Linux platforms

Breaking Changes

No

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follows MCP security best practices
  • I have updated the server's README accordingly
  • I have tested this with an LLM client
  • My code follows the repository's style guidelines
  • New and existing tests pass locally (all 133 tests passing)
  • I have added appropriate error handling (No new error handling needed - paths are now correctly preserved)
  • I have documented all environment variables and configuration options (No new env vars/config)

Additional context

This fix assumes that WSL paths (/mnt/...) should never be converted because:

  1. Inside WSL: They work correctly with Node.js fs operations
  2. On Windows: They don't exist anyway, so preserving them doesn't cause harm

@olaservo olaservo requested a review from Copilot October 14, 2025 13:27
Copy link

@Copilot Copilot AI left a 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.

Comment on lines +46 to +53
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]\//))
);
Copy link

Copilot AI Oct 14, 2025

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.

Comment on lines +231 to +238
afterEach(() => {
// Restore platform after each test
Object.defineProperty(process, 'platform', {
value: originalPlatform,
writable: true,
configurable: true
});
});
Copy link

Copilot AI Oct 14, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WSL path conversion bug in v2025.8.18+ causes ENOENT errors

1 participant