You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Users with Node version managers installed (particularly Fast Node Manager - fnm) are experiencing issues when setting up Model Context Protocol (MCP) servers. When attempting to use simple MCP server configurations like:
This error indicates that the system cannot find the npx executable, despite it being available when using the terminal directly.
Root Cause Analysis
The issue appears to be caused by two factors in the MCP server implementation:
Insufficient Environment Variable Passing: The code only passes the PATH environment variable to the child process, but node version managers like fnm require additional environment variables to function correctly.
Lack of Shell Context: Commands aren't being executed in a shell context, which is necessary for proper path resolution with node version managers.
When using node version managers, the shell setup scripts modify not just the PATH but often set other environment variables that are necessary for proper operation. Additionally, they may rely on shell features for executable resolution.
Suggested Fix
The issue could be resolved with two key changes to the src/services/mcp/McpHub.ts file, specifically in the connectToServer method where the StdioClientTransport is configured:
Pass All Environment Variables: Change the environment configuration to inherit all environment variables from the parent process (VSCode):
// Current implementationconsttransport=newStdioClientTransport({command: config.command,args: config.args,env: {
...config.env,
...(process.env.PATH ? {PATH: process.env.PATH} : {}),// ...(process.env.NODE_PATH ? { NODE_PATH: process.env.NODE_PATH } : {}),},stderr: "pipe",// necessary for stderr to be available})// Proposed implementation// Create the environment object, merging PATH properly if presentconstmergedEnv={ ...process.env};// Start with all parent env vars// Merge in config env vars, with special handling for PATHif(config.env){Object.entries(config.env).forEach(([key,value])=>{if(key.toUpperCase()==='PATH'&&process.env.PATH){// For PATH, append the user config to the existing pathmergedEnv[key]=`${process.env.PATH}${path.delimiter}${value}`;}else{// For other env vars, use the config valuemergedEnv[key]=value;}});}consttransport=newStdioClientTransport({command: config.command,args: config.args,env: mergedEnv,stderr: "pipe",// necessary for stderr to be availableshell: true,// Use shell to execute the command, which helps with PATH resolution})
Enable Shell Execution: Add shell: true to ensure commands run in a shell context (already included in the proposed implementation above)
Steps to reproduce
Have a node version manager installed
Configure a MCP server according to anthropic's example.
Roo think's it can fix the issue, as written in the block above.
It might be better to have a check box in the mcp config area to allow the user to execute using the vs code shell context or without it. Might have unexpected issues for some users if the code changes proposed by my Roo instance are just plugged in.
The text was updated successfully, but these errors were encountered:
Which version of the app are you using?
v3.7.6
Which API Provider are you using?
Anthropic
Which Model are you using?
Claude 3.7 Sonnet
What happened?
Issue Description
Users with Node version managers installed (particularly Fast Node Manager - fnm) are experiencing issues when setting up Model Context Protocol (MCP) servers. When attempting to use simple MCP server configurations like:
They encounter the following error:
This error indicates that the system cannot find the
npx
executable, despite it being available when using the terminal directly.Root Cause Analysis
The issue appears to be caused by two factors in the MCP server implementation:
Insufficient Environment Variable Passing: The code only passes the
PATH
environment variable to the child process, but node version managers like fnm require additional environment variables to function correctly.Lack of Shell Context: Commands aren't being executed in a shell context, which is necessary for proper path resolution with node version managers.
When using node version managers, the shell setup scripts modify not just the
PATH
but often set other environment variables that are necessary for proper operation. Additionally, they may rely on shell features for executable resolution.Suggested Fix
The issue could be resolved with two key changes to the
src/services/mcp/McpHub.ts
file, specifically in theconnectToServer
method where theStdioClientTransport
is configured:shell: true
to ensure commands run in a shell context (already included in the proposed implementation above)Steps to reproduce
spawn npx ENOENT spawn npx ENOENT
Relevant API REQUEST output
Additional context
Roo think's it can fix the issue, as written in the block above.
It might be better to have a check box in the mcp config area to allow the user to execute using the vs code shell context or without it. Might have unexpected issues for some users if the code changes proposed by my Roo instance are just plugged in.
The text was updated successfully, but these errors were encountered: