Skip to content

fix(filesystem): ensure bare Windows drive letters normalize to root#3434

Merged
olaservo merged 2 commits intomodelcontextprotocol:mainfrom
Chelebii:fix/filesystem-windows-drive-normalization
Mar 16, 2026
Merged

fix(filesystem): ensure bare Windows drive letters normalize to root#3434
olaservo merged 2 commits intomodelcontextprotocol:mainfrom
Chelebii:fix/filesystem-windows-drive-normalization

Conversation

@Chelebii
Copy link
Contributor

@Chelebii Chelebii commented Mar 1, 2026

Description

Currently,
ormalizePath('C:') returns C:. on Windows instead of C:. This behavior comes from Node's path.normalize() which interprets a bare drive letter as the current directory on that drive. This can break downstream path validation logic in the filesystem MCP server.

This PR ensures that bare Windows drive letters (e.g., C:, D:) are consistently normalized to the drive root by appending a path separator before calling path.normalize().

Key Changes

  • Modified
    ormalizePath in src/filesystem/path-utils.ts to detect bare drive letters on Windows.
  • Appends path.sep to these specific paths before normalization.

Related Issues

Fixes #3418

Previously,
ormalizePath('C:') returned C:. on Windows, which could break path validation.
By appending a separator before normalization for bare drive letters, we ensure they
consistently resolve to the drive root (e.g., C:\).

Fixes modelcontextprotocol#3418
Copy link
Member

@olaservo olaservo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix itself is correct and well-placed — nice work! The regex ^[a-zA-Z]:$ precisely matches bare drive letters, the process.platform guard keeps it inert on non-Windows, and the placement after backslash normalization but before path.normalize() is exactly right.

However, there's one issue that needs to be fixed before this can merge:

UTF-8 BOM introduced on line 1

The diff shows:

-import path from "path";
+import path from "path";

The replacement line starts with U+FEFF (UTF-8 Byte Order Mark), which wasn't in the original file. This was likely introduced by your editor. It will pollute git blame and is inconsistent with the rest of the codebase. Please re-save src/filesystem/path-utils.ts as UTF-8 without BOM and force-push.

Optional suggestion: Consider adding a test case for the bare drive letter fix in src/filesystem/__tests__/path-utils.test.ts, using the platform-mocking pattern already established in the existing WSL tests.

Once the BOM is removed, this is a clean merge. Thanks for the contribution!


Reviewed with the assistance of Claude Code (claude-opus-4-6). Claims were independently verified against the Node.js test suite and source code.

@Chelebii
Copy link
Contributor Author

Addressed, thanks. I removed the UTF-8 BOM from \src/filesystem/path-utils.ts\ and force-pushed the branch. I also added a test covering bare Windows drive-letter normalization to the drive root on Windows. Verified with: \
pm test -- tests/path-utils.test.ts\.

Copy link
Member

@olaservo olaservo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both issues from the initial review are addressed:

  1. BOM removed — verified at the byte level, file now starts cleanly with import
  2. Test addednormalizes bare Windows drive letters to the drive root on Windows covers C:C:\ and d:D:\, correctly placed inside the WSL path handling describe block which has afterEach platform restoration. Test passes on CI.

Fix logic is correct: precise regex (^[a-zA-Z]:$), platform-guarded, placed after backslash normalization and before path.normalize().

LGTM — thanks for the quick update @Chelebii!


Reviewed with the assistance of Claude Code (claude-opus-4-6). BOM removal verified via raw byte inspection; test correctness verified against CI results.

@olaservo olaservo merged commit b60eca1 into modelcontextprotocol:main Mar 16, 2026
16 of 19 checks passed
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.

fix(filesystem): normalizePath returns 'C:.' for bare Windows drive letters

2 participants