Skip to content
New issue

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

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

Already on GitHub? # to your account

Make SDK work on Windows without additional arguments #101

Open
JonasHelming opened this issue Dec 19, 2024 · 4 comments
Open

Make SDK work on Windows without additional arguments #101

JonasHelming opened this issue Dec 19, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@JonasHelming
Copy link

Is your feature request related to a problem? Please describe.
We experienced that to start MCP servers via the SDK on Windows, you need to start a command interpreter (e.g. cmd.exe) as the server command in order for path lookups to work as expected
e.g. like this:

"filesystem": {
    "command": "cmd",
    "args": ["/C", "npx -y @modelcontextprotocol/server-filesystem /Users/YOUR_USERNAME/Desktop"],
    "env": {
      "CUSTOM_ENV_VAR": "custom-value"
    }
  }

Describe the solution you'd like

Would be nice to hide this in the client SDK to hide the complexity from the user, at least with a sensible default for Windows.

Describe alternatives you've considered
none

Additional context
We have documented this work around for our users: https://theia-ide.org/docs/user_ai/#mcp-integration
See also: https://eclipsesource.com/blogs/2024/12/19/theia-ide-and-theia-ai-support-mcp/

@JonasHelming JonasHelming added the enhancement New feature or request label Dec 19, 2024
@aiqlcom
Copy link

aiqlcom commented Dec 21, 2024

I also encounter the same issue, and I noticed that there is an ongoing pull request addressing it: #95

This pull request aims to replace spawn with cross-spawn to resolve the issue.

ad6ea75#diff-cf9cf0e16fe93b95e6cc378c616f4cf5e884677337106dec23f740caee8707c3R1-R2

My workaround:

I am currently employing an alternative method as a temporary workaround to address this issue:

return new Promise((resolve, reject) => {
this._process = spawn(
this._serverParams.command,
this._serverParams.args ?? [],
{
env: this._serverParams.env ?? getDefaultEnvironment(),
stdio: ["pipe", "pipe", this._serverParams.stderr ?? "inherit"],
shell: false,
signal: this._abortController.signal,
windowsHide: process.platform === "win32" && isElectron(),
}
);

On Linux or macOS, shell: true is usually not required because command-line tools (such as npx) are typically standalone executables.

However, on Windows, shell: true is necessary to ensure that commands are executed correctly through the command interpreter.

Thus, I replaced it with shell: process.platform === "win32" ? true : false to temporarily avoid this issue.

@jspahrsummers jspahrsummers added bug Something isn't working and removed enhancement New feature or request labels Jan 2, 2025
@dinhphieu
Copy link

dinhphieu commented Feb 16, 2025

I spent hours today trying to figure out why I kept getting this

I use different shells, wsl, cygwin, etc. so it was hard to pinpoint the issue at first

Error: spawn npx ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at processTicksAndRejections (node:internal/process/task_queues:90:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn npx',
  path: 'npx',
  spawnargs: [ '-y', '@modelcontextprotocol/server-github' ]
}

I'm also patching shell: true with https://pnpm.io/cli/patch (or https://www.npmjs.com/package/patch-package) to temporarily address this, hope it gets fixed soon

@jspahrsummers
Copy link
Member

I replaced it with shell: process.platform === "win32" ? true : false to temporarily avoid this issue.

We used to have it enabled, but it was removed in #55 (cc @anaisbetts) because it creates terminal windows unnecessarily. Are you seeing the same?

@aiqlcom
Copy link

aiqlcom commented Feb 20, 2025

I replaced it with shell: process.platform === "win32" ? true : false to temporarily avoid this issue.

We used to have it enabled, but it was removed in #55 (cc @anaisbetts) because it creates terminal windows unnecessarily. Are you seeing the same?

I haven't observed this ‘terminal windows’ issue myself. After switching to 'true', I didn't notice any significant negative impacts. However, this is something we should be mindful of, as different frameworks/shells or environments might yield varying observations.

Would it be possible to make this parameter configurable as an input parameter during Client initialization? This way, even if the default value doesn't suit some developers' current frameworks, they could customize the parameter to better adapt to their specific systems/frameworks.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants