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

MCP Servers Don't Work with NVM #64

Open
combdn opened this issue Nov 26, 2024 · 44 comments
Open

MCP Servers Don't Work with NVM #64

combdn opened this issue Nov 26, 2024 · 44 comments
Labels
bug Something isn't working

Comments

@combdn
Copy link

combdn commented Nov 26, 2024

Problem

When using NVM (Node Version Manager), the standard installation and usage instructions for MCP servers don't work. The app tries to use an incorrect Node and fails.

Workaround

  1. Avoid npx, install packages globally.
  2. Use absolute paths to both the Node executable and server script.

Example:

{  
  "mcpServers": {
    "puppeteer": {
      "command": "/Users/username/.nvm/versions/node/v22.11.0/bin/node",
      "args": [
        "/Users/username/.nvm/versions/node/v22.11.0/lib/node_modules/@modelcontextprotocol/server-puppeteer/dist/index.js"
      ]
    }
  }
}

OS: macOS 15.1.1 (24B91)

@mckaywrigley
Copy link

mckaywrigley commented Nov 26, 2024

I also ran into issues with the recommended npx setup, and I was able to successfully reproduce this workaround - fixes it completely.

MCPs now install and attach correctly within Claude Desktop.

@lborgav
Copy link

lborgav commented Nov 27, 2024

This workaround works fine

@adam91holt
Copy link

I can confirm this is working for me too.

You may have a different node.js version installed so just do the following for puppeteer as an example

npm i -g @modelcontextprotocol/server-puppeteer
cd /Users/YOUR_USERNAME/.nvm/versions/node
ls
>>> v14.17.6        v16.19.0        v18.14.0        v18.20.4

Then I ended up with this and it works sweet!

{
  "mcpServers": {
    "puppeteer": {
      "command": "/Users/YOUR_USERNAME/.nvm/versions/node/v18.20.4/bin/node",
      "args": [
        "/Users/YOUR_USERNAME/.nvm/versions/node/v18.20.4/lib/node_modules/@modelcontextprotocol/server-puppeteer/dist/index.js"
      ]
    }
  }
}

@jspahrsummers
Copy link
Member

The challenge with NVM is that it seems to mostly work by installing a very complicated shell function into your shell profile. It'd be great if we could figure out your preferred Node version via NVM, but I haven't found a good way to do that—open to ideas!

@jspahrsummers jspahrsummers added the bug Something isn't working label Nov 27, 2024
@jspahrsummers
Copy link
Member

jspahrsummers commented Nov 27, 2024

Cross-linking: see #40 for Windows workaround steps as well

@lolochka
Copy link

lolochka commented Dec 4, 2024

Unfortunately, the issue is still reproducible on Mac with nvm installed.

OS: macOS 15.1.1
Claude: 0.7.5
Locally I have checked that all packages are available with inputted paths.

The SQlite server is working correctly, but tools for server-filesystem doesn't appear

My settings

{
  "mcpServers": {
    "sqlite": {
      "command": "uvx",
      "args": ["mcp-server-sqlite", "--db-path", "/Users/user/test.db"]
    },
    "filesystem": {
      "command": "/Users/user/.nvm/versions/node/v22.11.0/bin/node",
      "args": [
        "-y",
        "/Users/user/.nvm/versions/node/v22.11.0/lib/node_modules/@modelcontextprotocol/server-filesystem/dist/index.js",
        "/Users/user/claude"
      ]
    }
  }
}

@mlaugharn
Copy link

suggestion: the same way that there is the mcpServers field, can there also be an eg mcpShell field? Or maybe a shell or source key per individual server, eg "shell": "source /Users/user/mcp.sh" ? Might introduce 'too much' flexibility but it could make mcp more usable/transparent to tinker with.

@daaain
Copy link

daaain commented Dec 8, 2024

I was struggling to get MCP working yesterday, the error messages in the logs were unhelpful, and the most confusing of all is that it just started working today. This might not be the repo for this request, but it would be really useful if it was explicily documented which shell Claude Desktop is using to start the MCP services.

To your question @jspahrsummers, wouldn't nvm alias default work?

@jspahrsummers
Copy link
Member

Unfortunately no, the environment for GUI apps is completely different from what you see on the command line.

@daaain
Copy link

daaain commented Dec 9, 2024

Unfortunately no, the environment for GUI apps is completely different from what you see on the command line.

Ah right, I had a look and to answer my own question, assuming that Claude Desktop's Electron implementation uses the MCP TS SDK, it's node:child_process spawn with shell: false.

@combdn
Copy link
Author

combdn commented Dec 9, 2024

In the meantime, I have migrated from NVM to mise, and now, if I start the Claude app from my shell (open -a Claude), it can correctly use node and npm (it didn’t work with NVM). That might be a workaround for some people with the same problem.

PS Apple seems to have removed an option to set up the environment for the GUI apps through the launch agents. But I'm not sure. I didn’t dive too deep into it.

@daaain
Copy link

daaain commented Dec 9, 2024

I was going to say check if path.join(process.env.HOME, '.nvm/nvm-exec') exists and if so, use it, but then also realised that path won't be the same for Windows and the config JSON doesn't specify if the MCP server is Node or Python and using npx -y is just a convention, so can't assume anything.

Feels like the current implementation is in a bit of an uncanny valley between being very open for people to run whatever they want while also very limited by the GUI spawned non-shell process 🤔 I'm wondering if offering the option to either use bundled runtimes for simplicity or running in a full shell for flexibility would be useful? That's what Mac Git GUIs I've used have been doing to solve similar issues. Or WASM 😅

Or actually, maybe having a separate daemon process to make this easier, especially if there are plans to integrate Claude deeper for computer use?

Edit: actually, ~/.nvm/alias/default is a simple text file with the NVM default node version, so if it exists then it can be used to construct a platform dependent path to the Node binary.

BTW MCPs stopped working with my Claude Desktop again, the errors in logs suggest it might be a command argument concat issue?

mcp-server-webresearch.log:

ERROR: You must supply a command.

Execute binaries from npm packages.

  npx [options] <command>[@version] [command-arg]...
...

mcp-server-filesystem.log

command not found: /Users/dain/Desktop

With the config:

{
  "globalShortcut": "",
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/Users/dain/Desktop"
      ]
    },
    "webresearch": {
      "command": "npx",
      "args": ["-y", "@mzxrai/mcp-webresearch"]
    }
  }
}

@lynnbright
Copy link

lynnbright commented Dec 10, 2024

This workaround works for me. Thanks a lot! 🙏
Here's how I successfully installed the MCP servers.

Environment

  • macOS 14.3
  • Claude 0.7.5

Installation Steps

  1. Check your Node.js version:
node -v
# Example output: v18.17.0
  1. Clone and set up the repository:
git clone <repository-url>
cd <repository-name>
npm install
npm run build
npm link

Configure claude_desktop_config.json

Locate Required Paths

  1. Find your Node.js executable path:
cd ~/.nvm/versions/node
ls  # List available Node versions
cd v18.17.0/bin  # Replace with your version
pwd  # Copy this path + /node for the command field
# Example output: /Users/lynnbright/.nvm/versions/node/v18.17.0/bin/node
  1. Find the built file path:
cd ~/.nvm/versions/node/v18.17.0/lib/node_modules/linear-mcp-server/build
pwd  # Copy this path + /index.js for the args field
# Example output: /Users/lynnbright/.nvm/versions/node/v18.17.0/lib/node_modules/linear-mcp-server/build/index.js

Example Configuration

{
  "mcpServers": {
    "sqlite": {
      "command": "uvx",
      "args": [
        "mcp-server-sqlite",
        "--db-path",
        "/Users/lynnbright/test.db"
      ]
    },
    "linear": {
      "command": "/Users/lynnbright/.nvm/versions/node/v18.17.0/bin/node",
      "args": [
        "/Users/lynnbright/.nvm/versions/node/v18.17.0/lib/node_modules/linear-mcp-server/build/index.js"
      ],
      "env": {
        "LINEAR_API_KEY": "lin_api_xxxx"
      }
    },
    "notion": {
      "command": "/Users/lynnbright/.nvm/versions/node/v18.17.0/bin/node",
      "args": [
        "/Users/lynnbright/.nvm/versions/node/v18.17.0/lib/node_modules/notion/build/index.js"
      ],
      "env": {
        "NOTION_API_TOKEN": "ntn_xxxxx"
      }
    }
  }
}

Final Step

Restart Claude Desktop.

CleanShot 2024-12-10 at 12 32 46@2x

@laulauland
Copy link

FNM (https://github.com/Schniz/fnm) doesn't work either but the workaround worked!

@mearleycf
Copy link

In the meantime, I have migrated from NVM to mise, and now, if I start the Claude app from my shell (open -a Claude), it can correctly use node and npm (it didn’t work with NVM). That might be a workaround for some people with the same problem.

PS Apple seems to have removed an option to set up the environment for the GUI apps through the launch agents. But I'm not sure. I didn’t dive too deep into it.

This is the way. Mise is an infinitely better tool than NVM.

@gannonh
Copy link
Contributor

gannonh commented Dec 20, 2024

Interesting. Btw, the NVM issue goes away if you're only managing 1 version of node. I discovered this inadvertently setting up a new machine. Will check out Mise. First I've heard of it.

@serverlesspolska
Copy link

serverlesspolska commented Dec 27, 2024

This is the way. Mise is an infinitely better tool than NVM.

Even if it is. Nevertheless, nvm is very popular, and it would be nice if it were supported by Claude MCP.

@zaphodtx
Copy link

The challenge with NVM is that it seems to mostly work by installing a very complicated shell function into your shell profile. It'd be great if we could figure out your preferred Node version via NVM, but I haven't found a good way to do that—open to ideas!

Same goes for Volta (volta.sh).

@ycjcl868
Copy link

ycjcl868 commented Jan 1, 2025

Same issue with fnm(https://github.com/Schniz/fnm) Node.js version manager, when using node or npx:

spawn node 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:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn node',
  path: 'node',
  spawnargs: [Array]
}

@rgarcia
Copy link

rgarcia commented Jan 10, 2025

Potentially easier workaround that I don't think has been mentioned yet--place a script somewhere like /usr/local/bin/npx-for-claude:

#!/bin/zsh
source ~/.zshrc
exec npx "$@"

Then chmod +x /usr/local/bin/npx-for-claude. Might need to riff on it if you use bash, but this works for me. Now I can do something like this in my config:

{
  "mcpServers": {
    "everything": {
      "command": "npx-for-claude",
      "args": ["-y", "@modelcontextprotocol/server-everything"]
    }
  }
}

Have only tested that this works with fnm. Not sure about nvm.

@Ranteck
Copy link

Ranteck commented Jan 13, 2025

the issue still happening. I fix it doing this

      "command": "C:\\nvm4w\\nodejs\\node.exe",
      "args": [
        "C:/Users/USERNAME/Documents/MCPServer/node_modules/@modelcontextprotocol/server-memory/dist/index.js"
      ]
    },```

@dhodun dhodun unpinned this issue Jan 14, 2025
@T1T4N
Copy link

T1T4N commented Jan 23, 2025

I followed @rgarcia's workaround and for me on macOS it was enough that the wrapper script just includes the following lines:

#!/usr/bin/env bash

export PATH="/opt/homebrew/bin:$PATH"
exec npx "$@"

Also tested the same wrapper script with pnpm from corepack, worked wonderfully.

@TomExMachina
Copy link

TomExMachina commented Mar 5, 2025

Try this one: https://github.com/ihor-sokoliuk/mcp-searxng

I can't for the life of me get it working with nvm. I tried the command proxying of node and npx, sourcing .zshrc, absolute paths, global install, manually building ahead of time.

@MarcusQuirino
Copy link

@rgarcia worked for me. macbook air M1 with FNM and zsh

@Ranteck
Copy link

Ranteck commented Mar 5, 2025

@rgarcia worked for me. macbook air M1 with FNM and zsh

it works without problem in macbook but in windows is another thing

@rededge-ian
Copy link

For anyone who is using Volta for node version management, the workaround in the OP should work when paired with volta which:

  1. First, change the command from npx and instead use the full path to node, which you can find by running volta which node.
  2. Install the mcp package globally (e.g. npm install -g figma-mcp)
  3. Run volta which [package] to get their real path to use as the first argument under args. This will result in something like the following:
{
  "mcpServers": {
    "figma-mcp": {
      "command": "/Users/username/.volta/tools/image/node/20.18.3/bin/node",
      "args": [
        "/Users/username/.volta/tools/image/packages/figma-mcp/bin/figma-mcp"
      ],
      "env": {
        "FIGMA_API_KEY": ""
      }
    }
  }
}

(Note that if you did not want to have to update this for each new version of node, for step 1 you could instead use a variant of @T1T4N's solution with a shell script which sets the VOLTA_HOME and PATH env variables to the correct paths.)

@intertwine
Copy link

For Volta on OS X (15.4) and Claude Desktop (v0.8.0), using the full path to Volta's npx resolved my MCP connection timeout errors

In ~/Library/Application\ Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "filesystem": {
      "command": "/Users/username/.volta/bin/npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/Users/username/dirA/",
        "/Users/username/dirB/"
      ]
    },
    "brave-search": {
      "command": "/Users/username/.volta/bin/npx",
      "args": ["-y", "@modelcontextprotocol/server-brave-search"],
      "env": {
        "BRAVE_API_KEY": "<API_KEY>"
      }
    }
  }
}

@renanwilliam
Copy link

There is no way to make the @rgarcia work using an Intel Mac. But using the workaround of installing packages globally works fine.

@drewjs
Copy link

drewjs commented Mar 7, 2025

#!/usr/bin/env bash

fnm exec --using=default npx "$@"

If you're using fnm the above script worked well for my setup. Just add to "/usr/local/bin" and make sure you chmod +x accordingly. You can replace "default" with a specific version (eg. --using=20) if you want to always run MCP servers with a specific version of node/npm

@riemannzeta
Copy link

riemannzeta commented Mar 9, 2025

Confirming that this issue and the reported workaround still exist as of today with Claude Desktop 0.8.0 running on macOS Sequoia 15.3.1.

Using the claude_desktop_config.json suggested in the walkthrough results in the following errors in mcp-server-filesystem.log:

npm
 ERR! Invalid dependency type requested: alias

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/mfmartin/.npm/_logs/2025-03-09T18_51_33_223Z-debug.log
Install for @modelcontextprotocol/server-filesystem@latest failed with code 1

and the content of /Users/mfmartin/.npm/_logs/2025-03-09T18_51_33_223Z-debug.log shows that Claude Desktop is defaulting to an old version of node when it attempts to install @modelcontextprotocol/server-filesystem:

1 verbose cli [ '/Users/mfmartin/.nvm/versions/node/v10.13.0/bin/node',
1 verbose cli   '/Users/mfmartin/.nvm/versions/node/v10.13.0/lib/node_modules/npm/bin/npm-cli.js',
1 verbose cli   'install',
1 verbose cli   '@modelcontextprotocol/server-filesystem@latest',

When run from command line, npx works fine:

mfmartin@m1a ~ % npx -y @modelcontextprotocol/server-filesystem /Users/mfmartin/Desktop /Users/mfmartin/Downloads
Secure MCP Filesystem Server running on stdio
Allowed directories: [ '/Users/mfmartin/Desktop', '/Users/mfmartin/Downloads' ]

Presumably working fine because it's running off the nvm default alias 23.9.0. I tried in vain to figure out how to override whatever Claude Desktop was calling with environment variables (like NODE_PATH) with weird intermittent success.

But the reported workaround of running the server using node and the server index.js from an absolute path resolved the error:

{
  "mcpServers": { 
	"filesystem": {
	  "command": "/Users/mfmartin/.nvm/versions/node/v23.9.0/bin/node",
	  "args": [
	    "/Users/mfmartin/.nvm/versions/node/v23.9.0/lib/node_modules/@modelcontextprotocol/server-filesystem/dist/index.js",
	    "/Users/mfmartin/Desktop",
	    "/Users/mfmartin/Downloads"
	  ]
	}
  }
}

@Livshitz
Copy link

Livshitz commented Mar 9, 2025

the reason it's not working as expecting is that the App is using **spawn** ${command} ${arguments}, meaning it's starting a new process and not as a new shell process (which contains all your env, nvm, etc).
use this simple solution:

"filesystem": {
    "command": "bash",
    "args": [
        "-c",
        "npx @modelcontextprotocol/server-filesystem ~/Downloads"
    ]
}

@riemannzeta
Copy link

the reason it's not working as expecting is that the App is using **spawn** ${command} ${arguments}, meaning it's starting a new process and not as a new shell process (which contains all your env, nvm, etc). use this simple solution:

"filesystem": {
    "command": "bash",
    "args": [
        "-c",
        "npx @modelcontextprotocol/server-filesystem ~/Downloads"
    ]
}

That sounds very plausible. For whatever reason, this workaround doesn't seem to work for me.

@tonihintikka
Copy link

{
"mcpServers": {
"puppeteer": {
"command": "/Users/username/.nvm/versions/node/v22.11.0/bin/node",
"args": [
"/Users/username/.nvm/versions/node/v22.11.0/lib/node_modules/@modelcontextprotocol/server-puppeteer/dist/index.js"
]
}
}
}

Thanks for this! I took couple of hours to debug how to get mcp server work and this was the solution with macosx if you are using nvm. You need to give direct path to command and the node module.

@siawyoung
Copy link

Anyone who's struggling with this but with n instead of nvm, this worked for me:

{
  "mcpServers": {
    "filesystem": {
      "command": "zsh",
      "args": [
        "-c",
        "export PATH=/Users/<username>/n/bin:$PATH; npx @modelcontextprotocol/server-filesystem <folder1> <folder2>"
      ]
    }
  }
}

@jonigl
Copy link

jonigl commented Mar 17, 2025

Based on @rgarcia and @T1T4N's comments, I used this:

Create /usr/local/bin/npx-for-claude:

#!/usr/bin/env bash
export PATH="/Users/YOUR-USERNAME/.nvm/versions/node/YOUR-NODE-VERSION/bin:$PATH"
exec npx "$@"

Make executable: chmod +x /usr/local/bin/npx-for-claude then configure:

{
    "mcpServers": {
        "filesystem": {
            "command": "npx-for-claude",
            "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/dir"]
        }
    }
}

Works perfectly with NVM installations! 🚀

@bobtista
Copy link

None of these workarounds worked for me, but I'm able to just use the previous version "@modelcontextprotocol/[email protected]"

@miekassu
Copy link

this worked for me #64 (comment)

@xfarana-rakbank
Copy link

xfarana-rakbank commented Mar 25, 2025

"filesystem": {
      "command": "/Users/username/.nvm/versions/node/v22.14.0/bin/npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/Users/username/Desktop",
        "/Users/username/Downloads"
      ],
      "env": {
        "PATH": "/Users/username/.nvm/versions/node/v22.14.0/bin:/usr/local/bin:/usr/bin:/bin",
        "NODE_PATH": "/Users/username/.nvm/versions/node/v22.14.0/lib/node_modules"
      }
    }

This works for me until nvm is resolved here replace node version with whatever you are using and username obviously and it should work out of the box.

@ajoslin103
Copy link

ajoslin103 commented Mar 26, 2025

using the version of npx I want nvm use lts/jod && which npx I am able to use this config

{
  "mcpServers": {
    "playwright": {
      "command": "~/.nvm/versions/node/v22.14.0/bin/npx",
      "args": [
        "@playwright/mcp@latest"
      ]
    }
}

@comatory
Copy link

comatory commented Apr 2, 2025

For fnm @drewjs 's comment helped a lot.

Just for completeness sake, this is what the configuration for Claude Desktop looks like now (using filesystem as an example):

{
  "mcpServers": {
    "filesystem": {
      "type": "stdio",
      "command": "/usr/local/bin/load_npx_from_fnm.sh",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/Users/comatory/Downloads"
      ]
    }
  }
}

@kitar
Copy link

kitar commented Apr 2, 2025

Thanks @jonigl, your snippet was super helpful! 🙌
Just a small tweak — this version should work even if the Node version changes:

/usr/local/bin/npx-for-claude:

#!/usr/bin/env bash
NODE_VERSIONS_DIR="$HOME/.nvm/versions/node"
LATEST_NODE_VERSION=$(ls -v "$NODE_VERSIONS_DIR" | grep "^v" | sort -V | tail -n 1)
export PATH="$NODE_VERSIONS_DIR/$LATEST_NODE_VERSION/bin:$PATH"
exec npx "$@"

It's been working on my end — will keep testing it out :)

@vitto32
Copy link

vitto32 commented Apr 3, 2025

I've noticed that the PATH env the MCP receives has ALL the .nvm/versions in alphabetical order and then the node version the MCP can use is usually the OLDEST one.

The MCP I want to use is in python and launches node internally so I cannot just change the command arg in the config.

I solved it by creating a fake node version zero (/Users/[user]/.nvm/versions/node/v0.0.0) that points to the latest version.

@jessehouwing
Copy link

jessehouwing commented Apr 3, 2025

I ran into this issue trying to use fnm too and found a workaround in nvs to run the MCP server, this works like a charm!

Example:

"servers": {
    "playwright": {
        "command": "nvs",
        "args": ["exec", "22.14.0", "npx", "-y", "@playwright/mcp@latest"]
    },
    "github": {
        "command": "nvs",
        "args": ["exec", "22.14.0", "npx", "-y", "@modelcontextprotocol/server-github"],
        "env": {
            "GITHUB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>"
        }
    }
}

Blogged here: https://jessehouwing.net/vscode-running-mcp-using-node-version/

@lonecruisader
Copy link

the npx way worked for me by just deleting the ~/.nvm folder, for Claude Desktop Mac. You can try this if you aren't actively using nvm for development

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