[PR #3909] [MERGED] Fix/mcp environment inheritance #4460

Closed
opened 2026-02-22 18:35:52 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Mintplex-Labs/anything-llm/pull/3909
Author: @PaoloC68
Created: 5/29/2025
Status: Merged
Merged: 6/3/2025
Merged by: @timothycarambat

Base: masterHead: fix/mcp-environment-inheritance


📝 Commits (3)

  • e7683dd Fix: MCP server environment inheritance across platforms
  • 943c1ae Fix: MCP server environment inheritance across platforms after linting
  • 95cc42f Merge branch 'master' into fix/mcp-environment-inheritance

📊 Changes

1 file changed (+27 additions, -7 deletions)

View changed files

📝 server/utils/MCP/hypervisor/index.js (+27 -7)

📄 Description

Pull Request Type

  • feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 🔨 chore
  • 📝 docs

Relevant Issues

connect #3904, connect #3902, connect #3681, connect #3671, connect #3703

What is in this change?

Problem: MCP servers fail to start when AnythingLLM is launched via GUI on macOS, Docker, and other environments with -32000 Connection closed errors. The root cause is improper environment variable inheritance in the #buildMCPServerENV method.

Root Issues Fixed:

  1. No PATH inheritance for desktop apps: GUI applications get no default PATH, causing npx/node not found errors
  2. Incorrect Docker NODE_PATH: Points to node binary (/usr/bin/node) instead of modules directory (/usr/local/lib/node_modules)
  3. Missing base environment: When no user env specified, method returns empty object instead of essential PATH/NODE_PATH

Evidence:

  • GUI Launch: PATH=/usr/bin:/bin:/usr/sbin:/sbin (missing /usr/local/bin) → MCP fails
  • CLI Launch: PATH=/usr/local/bin:/usr/local/Cellar/node/23.11.0/bin:/usr/bin:/bin → MCP works

Solution:

  • Always provide base environment with proper PATH/NODE_PATH inheritance
  • Fixed Docker NODE_PATH to point to correct modules directory
  • Preserve user environment variable overrides
  • Maintain backward compatibility

User Experience Improvement:
The fix enables clean, natural MCP configurations without shell workarounds:

Now Works:

{
  "mcpServers": {
    "brave-search": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-brave-search"],
      "env": { "BRAVE_API_KEY": "your-api-key" }
    }
  }
}

Developer Validations

  • I ran yarn lint from the root of the repo & committed changes
  • Relevant documentation has been updated
  • I have tested my code functionality
  • Docker build succeeds locally

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Mintplex-Labs/anything-llm/pull/3909 **Author:** [@PaoloC68](https://github.com/PaoloC68) **Created:** 5/29/2025 **Status:** ✅ Merged **Merged:** 6/3/2025 **Merged by:** [@timothycarambat](https://github.com/timothycarambat) **Base:** `master` ← **Head:** `fix/mcp-environment-inheritance` --- ### 📝 Commits (3) - [`e7683dd`](https://github.com/Mintplex-Labs/anything-llm/commit/e7683ddb205c540fc550668d02ec7fde97418f8c) Fix: MCP server environment inheritance across platforms - [`943c1ae`](https://github.com/Mintplex-Labs/anything-llm/commit/943c1ae2c647ca506d1dd87093015e70a92ae5fd) Fix: MCP server environment inheritance across platforms after linting - [`95cc42f`](https://github.com/Mintplex-Labs/anything-llm/commit/95cc42f73e26124922b19aab8684230e1a31a272) Merge branch 'master' into fix/mcp-environment-inheritance ### 📊 Changes **1 file changed** (+27 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `server/utils/MCP/hypervisor/index.js` (+27 -7) </details> ### 📄 Description ### Pull Request Type - [ ] ✨ feat - [x] 🐛 fix - [ ] ♻️ refactor - [ ] 💄 style - [ ] 🔨 chore - [ ] 📝 docs ### Relevant Issues connect #3904, connect #3902, connect #3681, connect #3671, connect #3703 ### What is in this change? **Problem:** MCP servers fail to start when AnythingLLM is launched via GUI on macOS, Docker, and other environments with `-32000 Connection closed` errors. The root cause is improper environment variable inheritance in the `#buildMCPServerENV` method. **Root Issues Fixed:** 1. **No PATH inheritance for desktop apps**: GUI applications get no default PATH, causing `npx`/`node` not found errors 2. **Incorrect Docker NODE_PATH**: Points to node binary (`/usr/bin/node`) instead of modules directory (`/usr/local/lib/node_modules`) 3. **Missing base environment**: When no user `env` specified, method returns empty object instead of essential PATH/NODE_PATH **Evidence:** - GUI Launch: `PATH=/usr/bin:/bin:/usr/sbin:/sbin` (missing `/usr/local/bin`) → MCP fails - CLI Launch: `PATH=/usr/local/bin:/usr/local/Cellar/node/23.11.0/bin:/usr/bin:/bin` → MCP works **Solution:** - Always provide base environment with proper PATH/NODE_PATH inheritance - Fixed Docker NODE_PATH to point to correct modules directory - Preserve user environment variable overrides - Maintain backward compatibility **User Experience Improvement:** The fix enables clean, natural MCP configurations without shell workarounds: **✅ Now Works:** ```json { "mcpServers": { "brave-search": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-brave-search"], "env": { "BRAVE_API_KEY": "your-api-key" } } } } ``` ### Developer Validations <!-- All of the applicable items should be checked. --> - [x] I ran `yarn lint` from the root of the repo & committed changes - [ ] Relevant documentation has been updated - [x] I have tested my code functionality - [x] Docker build succeeds locally --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-22 18:35:52 -05:00
yindo closed this issue 2026-02-22 18:35:52 -05:00
yindo changed title from [PR #3909] Fix/mcp environment inheritance to [PR #3909] [MERGED] Fix/mcp environment inheritance 2026-06-05 15:18:40 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#4460