MCPcopy
hub / github.com/modelcontextprotocol/servers / convertToWindowsPath

Function convertToWindowsPath

src/filesystem/path-utils.ts:9–32  ·  view source on GitHub ↗
(p: string)

Source from the content-addressed store, hash-verified

7 * @returns Converted Windows path
8 */
9export function convertToWindowsPath(p: string): string {
10 // Handle WSL paths (/mnt/c/...)
11 // NEVER convert WSL paths - they are valid Linux paths that work with Node.js fs operations in WSL
12 // Converting them to Windows format (C:\...) breaks fs operations inside WSL
13 if (p.startsWith('/mnt/')) {
14 return p; // Leave WSL paths unchanged
15 }
16
17 // Handle Unix-style Windows paths (/c/...)
18 // Only convert when running on Windows
19 if (p.match(/^\/[a-zA-Z]\//) && process.platform === 'win32') {
20 const driveLetter = p.charAt(1).toUpperCase();
21 const pathPart = p.slice(2).replace(/\//g, '\\');
22 return `${driveLetter}:${pathPart}`;
23 }
24
25 // Handle standard Windows paths, ensuring backslashes
26 if (p.match(/^[a-zA-Z]:/)) {
27 return p.replace(/\//g, '\\');
28 }
29
30 // Leave non-Windows paths unchanged
31 return p;
32}
33
34/**
35 * Normalizes path by standardizing format while preserving OS-specific behavior

Callers 2

normalizePathFunction · 0.85
path-utils.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected