Skip to content
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

npx-related mcp server failed to load on nvm env #436

Open
donghao1393 opened this issue Dec 28, 2024 · 2 comments
Open

npx-related mcp server failed to load on nvm env #436

donghao1393 opened this issue Dec 28, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@donghao1393
Copy link

donghao1393 commented Dec 28, 2024

Describe the bug
I am using fish on macos. Previously node was installed by brew and mcp on claude desktop works fine. but it's failed since I got node from fish verion nvm.

To Reproduce
Steps to reproduce the behavior:

$ brew uninstall node
$ fisher install jorgebucaran/nvm.fish
$ nvm use lts
$ node --version
  npm --version
  npx --version
v22.12.0
10.9.0
10.9.0
$ bash
bash-3.2$ node --version
v22.12.0
bash-3.2$ npm --version
10.9.0
bash-3.2$ npx --version
10.9.0
$ zsh
(base) donghao@Dongs-MacBook-Air ~ % node --version
v22.12.0
(base) donghao@Dongs-MacBook-Air ~ % npm --version
10.9.0
(base) donghao@Dongs-MacBook-Air ~ % npx --version
10.9.0

Expected behavior
mcp servers should be loaded successful.

Logs

2024-12-28T19:16:03.934Z [error] Error in MCP connection to server filesystem: Error: spawn npx ENOENT
2024-12-28T19:16:03.935Z [error] Could not start MCP server filesystem: Error: spawn npx ENOENT
2024-12-28T19:16:03.936Z [error] Error in MCP connection to server memory: Error: spawn npx ENOENT
2024-12-28T19:16:03.936Z [error] Could not start MCP server memory: Error: spawn npx ENOENT
2024-12-28T19:16:03.936Z [info] Connected to MCP server git!
2024-12-28T19:16:03.937Z [error] Error in MCP connection to server github: Error: spawn npx ENOENT
2024-12-28T19:16:03.937Z [error] Could not start MCP server github: Error: spawn npx ENOENT

Additional context
it resume to work after switching to brew version node

$ nvm uninstall lts
$ brew install node
@donghao1393 donghao1393 added the bug Something isn't working label Dec 28, 2024
@donghao1393
Copy link
Author

same issue like:

@donghao1393 donghao1393 changed the title npx-related mcp server failed to load npx-related mcp server failed to load on nvm env Dec 28, 2024
@donghao1393
Copy link
Author

donghao1393 commented Dec 29, 2024

MCP Server Commands PATH Environment Investigation Report

Issue Description

The MCP Server Commands environment cannot directly access Node.js executables installed via nvm, unless they are symlinked to the /opt/homebrew/bin directory.

Current Workaround

Currently, we're using symbolic links to make Node.js commands accessible:

# Create symbolic links from nvm-installed Node.js to Homebrew bin directory
ln -s ~/.local/share/nvm/v22.12.0/bin/npx /opt/homebrew/bin/npx
ln -s ~/.local/share/nvm/v22.12.0/bin/npm /opt/homebrew/bin/npm
ln -s ~/.local/share/nvm/v22.12.0/bin/node /opt/homebrew/bin/node

# Verify the links
$ ls -l /opt/homebrew/bin/npx
lrwxr-xr-x@ 1 donghao  admin  48 Dec 29 10:50 /opt/homebrew/bin/npx -> /Users/donghao/.local/share/nvm/v22.12.0/bin/npx

While this workaround is functional, it's not an ideal solution as it requires manual intervention and maintenance.

Investigation Process

1. Initial Environment Analysis

Checked current shell and environment settings:

$ echo $0
/bin/sh

$ env
SHELL=/opt/homebrew/bin/fish
PATH=/Users/donghao/.npm/_npx/d597531c0c0615ae/node_modules/.bin:/node_modules/.bin:/Users/donghao/.local/share/nvm/v22.12.0/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin:/usr/local/bin:/opt/homebrew/bin:/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin

2. Homebrew Path Investigation

Analyzed Homebrew's installation script to understand how it manages PATH:

  1. Downloaded and examined the install script:
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Key findings from install.sh:
  • For Apple Silicon Macs, uses /opt/homebrew as HOMEBREW_PREFIX
  • Automatically adds itself to shell configuration files
  • Uses brew shellenv to set up environment variables
  1. Checked brew shellenv output:
$ brew shellenv
export HOMEBREW_PREFIX="/opt/homebrew";
export HOMEBREW_CELLAR="/opt/homebrew/Cellar";
export HOMEBREW_REPOSITORY="/opt/homebrew";
PATH="/opt/homebrew/bin:/opt/homebrew/sbin:$PATH"; export PATH;

3. Environment Configuration Attempts

  1. Checked home directory location:
$ echo $HOME
/Users/donghao
  1. Examined existing profile file:
$ cat ~/.profile
. "$HOME/.cargo/env"
  1. Added nvm path to profile:
$ echo 'export PATH="/Users/donghao/.local/share/nvm/v22.12.0/bin:$PATH"' >> ~/.profile
  1. Checked Cargo's environment setup:
$ cat ~/.cargo/env
#!/bin/sh
case ":${PATH}:" in
    *:"$HOME/.cargo/bin":*)
        ;;
    *)
        export PATH="$HOME/.cargo/bin:$PATH"
        ;;
esac

4. Configuration Verification

  1. Modified the ~/.profile file to include both nvm and cargo paths:
# Current content of ~/.profile
export PATH="/Users/donghao/.local/share/nvm/v22.12.0/bin:$PATH"
. "$HOME/.cargo/env"
  1. Tested direct PATH access:
$ echo $PATH
# Shows PATH without new additions
  1. Tested profile sourcing:
$ source ~/.profile
$ echo $PATH
/Users/donghao/.cargo/bin:/Users/donghao/.local/share/nvm/v22.12.0/bin:/Users/donghao/.npm/_npx/d597531c0c0615ae/node_modules/.bin:/node_modules/.bin:/Users/donghao/.local/share/nvm/v22.12.0/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin:/usr/local/bin:/opt/homebrew/bin:/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin

Technical Findings

  1. The service environment:

    • Runs under /bin/sh
    • Has access to /opt/homebrew/bin by default
    • Does not appear to load user shell configurations
  2. Shell configuration files:

    • .profile modifications are not automatically loaded
    • Homebrew's path is consistently available
    • Similar tools (like Rust/Cargo) use comparable PATH modification approaches

Questions for Developers

  1. Service Configuration:

    • How is the MCP Server Commands service initiated?
    • Is there a way to load user environment configurations at service startup?
    • Can we configure additional PATH entries at the service level?
  2. Environment Management:

    • Is there a preferred method for extending PATH in this environment?
    • Should there be a standardized way to handle tool-specific paths?

Possible Solutions

  1. Service-level configuration:

    • Add capability to specify additional PATH entries in service configuration
    • Implement proper environment loading during service startup
  2. Standardized path management:

    • Create a central location for tool paths
    • Implement automatic PATH management for installed tools
  3. Documentation improvement:

    • Document the current limitations
    • Provide clear instructions for path management

Next Steps

We seek developers' input on:

  1. The preferred approach for handling tool paths
  2. Whether environment loading can be improved
  3. If any of the proposed solutions align with the project's direction

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

No branches or pull requests

1 participant