-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
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:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/Users/username/Desktop",
"/path/to/other/allowed/dir"
]
}
}
}They encounter the following error:
spawn npx ENOENT spawn npx ENOENT
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
PATHenvironment 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 implementation
const transport = new StdioClientTransport({
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 present
const mergedEnv = { ...process.env }; // Start with all parent env vars
// Merge in config env vars, with special handling for PATH
if (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 path
mergedEnv[key] = `${process.env.PATH}${path.delimiter}${value}`;
} else {
// For other env vars, use the config value
mergedEnv[key] = value;
}
});
}
const transport = new StdioClientTransport({
command: config.command,
args: config.args,
env: mergedEnv,
stderr: "pipe", // necessary for stderr to be available
shell: true, // Use shell to execute the command, which helps with PATH resolution
})- Enable Shell Execution: Add
shell: trueto 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.
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/Users/username/Desktop",
"/path/to/other/allowed/dir"
]
}
}
}
- Receive
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.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status