这是indexloc提供的服务,不要输入任何密码
Skip to content

[BUG]: MCP Servers Fail to Start When Launched via GUI on macOS #3904

@PaoloC68

Description

@PaoloC68

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

  1. Install Node.js via Homebrew
  2. 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"
          }
        }
      }
    }
  3. Launch AnythingLLM via GUI → MCP servers fail
  4. 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:

  1. Environment Inheritance: Ensure the app inherits the user's full shell environment
  2. PATH Detection: Automatically detect common Node.js installation paths (/usr/local/bin, Homebrew paths, etc.)
  3. Better Error Messages: Provide more specific error messages when Node.js binaries aren't found
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    possible bugBug was reported but is not confirmed or is unable to be replicated.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions