Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

filesystem: expandHome() does not handle Windows backslash separator (~\path)

Aperta Adatta ai principianti
#5,180 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@BOHAOYUAN ci sta già lavorando.

Dal 20/10/2026.

  • #1 di @BOHAOYUAN — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript
Ambito
backend

Direzione di ricerca

Leggi src/filesystem/path-utils.ts e src/filesystem/roots-utils.ts, dove l’issue mostra i controlli per l’espansione della tilde. Confronta come vengono gestiti i percorsi ~/ e ~\, poi cerca i test che coprono expandHome e l’espansione dei percorsi radice. Il lavoro è completato quando i percorsi Windows con tilde e barra rovesciata vengono espansi nella directory home e i casi esistenti continuano a funzionare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug server-filesystem v2
Which server?

filesystem (@modelcontextprotocol/server-filesystem)

Server version

latest (v2/main)

How did you run the server?

npx (npm package)

Transport

stdio

Protocol era

Modern (2026-07-28)

MCP client and version

Claude Desktop / MCP Inspector

Operating system and runtime

Windows 11 / Windows Server, Node.js v20+ / v22+

Server configuration
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "~\\projects"]
    }
  }
}
Steps to reproduce
  1. Run @modelcontextprotocol/server-filesystem on Windows.
  2. Supply an allowed directory argument or path with native Windows backslash tilde notation, e.g., ~\projects or ~\Documents\notes.txt.
  3. expandHome in src/filesystem/path-utils.ts executes:
    export function expandHome(filepath: string): string {
        if (filepath.startsWith("~/") || filepath === "~") {
            return path.join(os.homedir(), filepath.slice(1));
        }
        return filepath;
    }
    
    And similarly in src/filesystem/roots-utils.ts:
    if (rawPath.startsWith("~/") || rawPath === "~") { ... }
    
Expected behavior

On Windows platforms, tilde followed by a backslash (~\) is the natural path separator convention when invoking CLI commands or passing configurations (e.g. ~\workspace). expandHome should recognize both ~/ and ~\ prefixes and expand them to os.homedir().

Actual behavior

Because the condition strictly checks .startsWith("~/"), any path formatted with backslashes (such as ~\projects or ~\\projects) fails to match. expandHome returns the raw string unchanged.

Downstream, path.resolve() interprets ~ as a literal directory name relative to the current working directory (e.g. C:\current\dir\~\projects), causing directory validation to fail with:
Access denied - Path does not exist or is outside allowed directories

Logs or error output
Node.js REPL test:
> const path = require('path');
> const os = require('os');
> function expandHome(p) { if (p.startsWith('~/') || p === '~') return path.join(os.homedir(), p.slice(1)); return p; }

> expandHome('~/test')
'C:\\Users\\User\\test'   // OK (POSIX slash)

> expandHome('~\\test')
'~\\test'                 // Fails to expand Windows backslash
Already prototyped a fix?

Update expandHome in src/filesystem/path-utils.ts and roots-utils.ts to recognize ~\:

export function expandHome(filepath: string): string {
    if (filepath === "~" || filepath.startsWith("~/") || filepath.startsWith("~\\")) {
        return path.join(os.homedir(), filepath.slice(1));
    }
    return filepath;
}
Before you submit
  • I searched existing issues and this is not a duplicate.
  • This is not a security vulnerability report (those go through the private advisory form).
Lingua principale
TypeScript
Stelle
91.4k
Fork
11.8k
Merge medio
7h 36m
PR unite (30g)
126

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di modelcontextprotocol/servers

Tutte le issue di modelcontextprotocol/servers

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.