-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
How are you running AnythingLLM?
Desktop
What happened?
Bug Description
MCP servers fail to start when AnythingLLM is launched via the GUI application, but work correctly when launched from the command line. All MCP servers report the error:
Failed to start MCP server: [server-name] [-32000] MCP error -32000: Connection closed
Are there known steps to reproduce?
Bug Report: MCP Servers Fail to Start When Launched via GUI on macOS
Environment
- OS: macOS (Darwin)
- AnythingLLM Version: [Version 1.8.1-r2 (1.8.1-r2)]
- Node.js: v23.11.0 (installed via Homebrew)
- Installation Method: Desktop App
Bug Description
MCP servers fail to start when AnythingLLM is launched via the GUI application, but work correctly when launched from the command line. All MCP servers report the error:
Failed to start MCP server: [server-name] [-32000] MCP error -32000: Connection closed
Root Cause
The GUI application launches with a severely restricted environment that lacks access to Node.js binaries:
GUI Environment:
PATH: /usr/bin:/bin:/usr/sbin:/sbin
NODE_PATH: (empty)
PWD: /
which node: (not found)
which npx: (not found)
Command Line Environment:
PATH: /usr/local/bin:/usr/local/Cellar/node/23.11.0/bin:/usr/bin:/bin:/usr/sbin:/sbin
NODE_PATH: /usr/local/lib/node_modules
node: /usr/local/bin/node
npx: /usr/local/bin/npx
Steps to Reproduce
- Install Node.js via Homebrew
- Configure MCP servers in AnythingLLM with standard configuration:
{ "mcpServers": { "jetbrains": { "command": "/usr/local/bin/npx", "args": ["-y", "@jetbrains/mcp-proxy"], "env": { "MCP_ACTIVE": "true", "NODE_PATH": "/usr/local/lib/node_modules", "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" } } } } - Launch AnythingLLM via GUI → MCP servers fail
- Launch AnythingLLM via command line (
./AnythingLLM) → MCP servers work
Workaround
Use shell wrappers instead of direct npx commands:
{
"mcpServers": {
"jetbrains": {
"command": "/bin/sh",
"args": [
"-c",
"export PATH='/usr/local/bin:/usr/local/Cellar/node/23.11.0/bin:/usr/bin:/bin:/usr/sbin:/sbin' && export NODE_PATH='/usr/local/lib/node_modules' && export MCP_ACTIVE='true' && /usr/local/bin/npx -y @jetbrains/mcp-proxy"
]
},
"brave-search": {
"command": "/bin/sh",
"args": [
"-c",
"export PATH='/usr/local/bin:/usr/local/Cellar/node/23.11.0/bin:/usr/bin:/bin:/usr/sbin:/sbin' && BRAVE_API_KEY=YOUR_API_KEY /usr/local/bin/npx -y @modelcontextprotocol/server-brave-search"
]
}
}
}Expected Behavior
MCP servers should start successfully regardless of whether AnythingLLM is launched via GUI or command line.
Proposed Solution
The Electron app should inherit or properly set up the user's shell environment when launching MCP server processes. Consider:
- Environment Inheritance: Ensure the app inherits the user's full shell environment
- PATH Detection: Automatically detect common Node.js installation paths (
/usr/local/bin, Homebrew paths, etc.) - Better Error Messages: Provide more specific error messages when Node.js binaries aren't found
- Documentation: Add troubleshooting section for environment-related MCP issues
Additional Context
This is a common issue with Electron applications on macOS where GUI apps don't inherit the terminal's environment. The env parameter in MCP server configurations appears to be insufficient for npx to function properly in the restricted GUI environment.
Labels: bug, macos, mcp, electron, desktop-app