Skip to content

fix: Resolve Windows ESM path issues in MCP server #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 29, 2025

Conversation

ausboss
Copy link
Contributor

@ausboss ausboss commented Mar 20, 2025

This commit fixes the "Invalid path protocol 'c:'" error when running the MCP server on Windows systems. The error occurred because Node.js ESM imports require proper URL formatting with file:// protocol, which was not being handled correctly for Windows paths.

Changes:

  • Added a createFileURL() helper function to properly convert Windows paths to valid file:// URLs
  • Fixed import path handling in index.ts for setup script loading
  • Updated setup-claude-server.js to use proper URL detection for direct execution
  • Added proper TypeScript Node.js type definitions
  • Updated tsconfig.json to explicitly include Node types
  • Ensured Windows backslashes are properly escaped in JSON config

These changes ensure the MCP server installs and runs correctly on Windows systems while maintaining compatibility with other platforms.

Closes #8

This commit fixes the "Invalid path protocol 'c:'" error when running the MCP server on Windows systems. The error occurred because Node.js ESM imports require proper URL formatting with file:// protocol, which was not being handled correctly for Windows paths.

Changes:
- Added a createFileURL() helper function to properly convert Windows paths to valid file:// URLs
- Fixed import path handling in index.ts for setup script loading
- Updated setup-claude-server.js to use proper URL detection for direct execution
- Added proper TypeScript Node.js type definitions
- Updated tsconfig.json to explicitly include Node types
- Ensured Windows backslashes are properly escaped in JSON config

These changes ensure the MCP server installs and runs correctly on Windows systems while maintaining compatibility with other platforms.

Closes wonderwhy-er#8
@wonderwhy-er
Copy link
Owner

Thanks, I will try to find time over weekend to test this, if it works across systems will merge.
Looks promising.

@wonderwhy-er
Copy link
Owner

What node version are you using?
I tried on my windows laptop with node v22
Running npm install and then setup results with
Capture-windows-node

And no mcp added to Claude

It seems that that experimental option was removed
https://github.com/orgs/nodejs/discussions/54948

What I did was that I tried to run it with the flag, and then if that failed with the flag
That did work
Still need to test on Mac too

@shabbirdudhiya
Copy link

shabbirdudhiya commented Mar 23, 2025

Message:

I encountered the same issue while using Node.js v22.

The error message I received was:
Failed to start server: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'

To resolve this, I manually installed the project by running the following commands:

git clone https://github.com/wonderwhy-er/ClaudeComputerCommander.git
cd ClaudeComputerCommander
npm run setup

After this, it worked successfully.

I tried it in claude:
image

@beingnikhilesh
Copy link

I encountered the same issue when access XAMPP i.e. C:\xampp\htdocs directory...
What changes do we have to make in order for MCP to access these directories...

@wonderwhy-er
Copy link
Owner

I plan to make changes to allow access to other folders in this PR
#16

Currently access is limited to user home dir here
https://github.com/wonderwhy-er/ClaudeDesktopCommander/blob/main/src/tools/filesystem.ts#L25

I think I will remove that and allow any access.
And later will add ability to restrict

@wonderwhy-er
Copy link
Owner

@beingnikhilesh @shabbirdudhiya
I just pushed in new version
Should update itself on restart of claude(though if you instealled trough smithery it may crash on first restart, you need to restart once more)

In new version I commented out folder validation so all disk drives and paths are allowed now

I will allow restriction again when its configurable
For now it unlocks use in different cases

@Samirite83
Copy link

Samirite83 commented Mar 25, 2025

Hello !

FYI I tried to install both way on my windows 11.
Using Node 20.16.0 (with nvm)

If I install with the commande :
npx -y @smithery/cli install @wonderwhy-er/desktop-commander --client claude

I have :

2025-03-25T14:17:59.588Z [desktop-commander] [info] Initializing server...
2025-03-25T14:17:59.602Z [desktop-commander] [info] Server started and connected successfully
2025-03-25T14:17:59.811Z [desktop-commander] [info] Message from client: {"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"claude-ai","version":"0.1.0"}},"jsonrpc":"2.0","id":0}
Start-Process : Impossible d'ex‚cuter cette commande en raison de l'erreurÿ: Le fichier sp‚cifi‚ est introuvable.
Au caractŠre Ligne:1 : 1

  • Start-Process -Filepath 'C:\Users\corey\OneDrive\Documents\workspace\ ...
  • CategoryInfo : InvalidOperation : (:) [Start-Process], InvalidOperationException
  • FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

2025-03-25T14:18:00.301Z [desktop-commander] [info] Server transport closed
2025-03-25T14:18:00.301Z [desktop-commander] [info] Client transport closed
2025-03-25T14:18:00.301Z [desktop-commander] [info] Server transport closed unexpectedly, this is likely due to the process exiting early. If you are developing this MCP server you can add output to stderr (i.e. console.error('...') in JavaScript, print('...', file=sys.stderr) in python) and it will appear in this log.
2025-03-25T14:18:00.301Z [desktop-commander] [error] Server disconnected. For troubleshooting guidance, please visit our debugging documentation {"context":"connection"}
2025-03-25T14:18:00.301Z [desktop-commander] [info] Client transport closed

If I pull repo :
git clone https://github.com/wonderwhy-er/ClaudeComputerCommander.git cd ClaudeComputerCommander npm run setup

I have :

2025-03-25T14:11:08.973Z [desktopCommander] [info] Message from client: {"jsonrpc":"2.0","method":"notifications/cancelled","params":{"requestId":0,"reason":"Error: MCP error -32001: Request timed out"}}
2025-03-25T14:11:08.974Z [desktopCommander] [info] Client transport closed
2025-03-25T14:11:08.974Z [desktopCommander] [info] Server transport closed
2025-03-25T14:11:08.974Z [desktopCommander] [info] Client transport closed
2025-03-25T14:11:08.974Z [desktopCommander] [info] Server transport closed unexpectedly, this is likely due to the process exiting early. If you are developing this MCP server you can add output to stderr (i.e. console.error('...') in JavaScript, print('...', file=sys.stderr) in python) and it will appear in this log.
2025-03-25T14:11:08.974Z [desktopCommander] [error] Server disconnected. For troubleshooting guidance, please visit our debugging documentation {"context":"connection"}
2025-03-25T14:11:08.979Z [desktopCommander] [info] Server transport closed
2025-03-25T14:11:08.979Z [desktopCommander] [info] Client transport closed

Hope it can helps, i have been trying to install CDC for few days on my windows 11, following your updates.
Thanks for your work !

@shabbirdudhiya
Copy link

@beingnikhilesh @shabbirdudhiya I just pushed in new version Should update itself on restart of claude(though if you instealled trough smithery it may crash on first restart, you need to restart once more)

In new version I commented out folder validation so all disk drives and paths are allowed now

I will allow restriction again when its configurable For now it unlocks use in different cases

Thank you for pushing the new version and commenting out the folder validation. I’ve updated and restarted Claude as you mentioned. However, I’m still facing the same issue when using Node.js v22.
Would you mind double-checking if the recent changes are correctly applied to the repo and confirming whether any additional steps are required on my end?

Appreciate your support and thanks again for your efforts!
image

@beingnikhilesh
Copy link

The New version worked for me. Also if its not working I'd suggest you try the following.

1. Uninstall the MCP. (Go to File --> Settings --> Developer --> desktop-commander (Press the delete icon)) 
2. Install MCP again by running the npx -y @smithery/cli@latest install @wonderwhy-er/desktop-commander --client claude --key 3fe97446-00b1-4ac9-8629-8343dd1ad096. 
3. Restart Claude and it will be detected

If this does not solve the issue. Try the following
Ask the Claude to look into C:\Users\credi\AppData\Local\npm-cache_npx\ directory and fix the limitation by typing the prompt

I need help modifying the desktop-commander MCP to grant Claude access to specific directories that aren't in the default allowed paths. In my case, I need access to [SPECIFY YOUR DIRECTORIES, e.g., C:\xampp, C:\xampp82].

First, help me locate the desktop-commander installation. It should be somewhere in my user profile, likely under AppData more specifically C:\Users\credi\AppData\Local\npm-cache\_npx\ (for windows). Use the search_files function to find it.

Once found, please modify the validation logic in the filesystem.js file to allow access to my specified directories. This will involve:

1. Checking the current allowed directories
2. Updating the allowedDirectories array to include my custom paths
3. Modifying the validatePath function to bypass validation for my specific directories
4. Creating a config.json file if needed
5. Testing access to ensure the changes worked

If the changes don't take effect immediately, please suggest restarting the Claude application as this often resolves permission issues.

Also a huge Thank you to @wonderwhy-er for creating this MCP and also guiding us through his Youtube Channel. I cant express in words how this has helped me as a Pro developer and saved my time. (Also this has made me lazy ;) ).

@serg33v
Copy link
Collaborator

serg33v commented Mar 29, 2025

this PR fixed my problem on windows 10.

{"type":"error","timestamp":"2025-03-29T01:07:44.628Z","message":"Failed to start server: Only URLs with a scheme in: file and data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'"}

@wonderwhy-er wonderwhy-er merged commit 549e982 into wonderwhy-er:main Mar 29, 2025
@wonderwhy-er
Copy link
Owner

Ok I made some changes and merged.
We did remove that experimental flag as it was dropped in Node 18 that is smallest LTS version.
We set 18th node as minimal required to run this MCP for now.

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.

bug for window install
6 participants