Skip to content

mcp command fails on Windows: fileURLToPath returns POSIX path /C:/... causing C:\C:\ doubling #101

Open

Description

@jiaweing

Bug

expect mcp crashes on Windows with:

Error: Cannot find module 'C:\C:\Users\...\expect-cli\dist\browser-mcp.js'

Root cause

In dist/index.js, the mcp command spawns browser-mcp.js using:

let v = fileURLToPath(new URL('./browser-mcp.js', import.meta.url))
// then: execFileSync(process.execPath, [v], ...)

On Windows, fileURLToPath returns a POSIX-style path /C:/Users/.../browser-mcp.js instead of C:\Users\...\browser-mcp.js. When this is passed as a CLI argument to node.exe, Windows interprets /C:/... relative to the current drive root, producing C:\C:\....

Repro

npm install -g expect-cli
echo '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1"}},"id":1}' | expect mcp

Environment

  • OS: Windows 11
  • Node.js: v22.22.2
  • expect-cli: 0.1.3
  • Shell: Git Bash (bash via MINGW64)

Fix suggestion

Wrap the path with a Windows path normalization before passing to execFileSync:

import { fileURLToPath } from 'node:url';
import path from 'node:path';

let v = path.resolve(fileURLToPath(new URL('./browser-mcp.js', import.meta.url)));

path.resolve will normalize /C:/... → C:\... on Windows.

This blocks Claude Code MCP integration on Windows entirely — the MCP server can never start.

Activity

  1. jiaweing commented on Apr 22, 2026

    @jiaweing
    Author

    Root cause identified

    The bug is in apps/cli/src/index.tsx line 254:

    const mcpBin = new URL("./browser-mcp.js", import.meta.url).pathname;

    .pathname gives the raw URL path component — on Windows that's /C:/Users/..., not a valid Windows file path. Passing it to node.exe makes Windows resolve it as C:\C:\....

    One-line fix

    const { fileURLToPath } = await import("node:url");
    const mcpBin = fileURLToPath(new URL("./browser-mcp.js", import.meta.url));

    fileURLToPath is the standard Node.js way to convert import.meta.url to a file path — it correctly handles the Windows drive letter.

    I tried opening a PR but the repo is set to collaborators_only for PRs. Fork with the fix is at: https://github.com/jiaweing/expect/tree/fix/windows-mcp-path

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions