θΏ™ζ˜―indexlocζδΎ›ηš„ζœεŠ‘οΌŒδΈθ¦θΎ“ε…₯任何密码
Skip to content

Fix/mcp environment inheritance #3909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

PaoloC68
Copy link
Contributor

@PaoloC68 PaoloC68 commented May 29, 2025

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

PaoloC68 added 2 commits May 29, 2025 16:08
- Fix GUI applications not inheriting proper PATH/NODE_PATH
- Correct Docker NODE_PATH to point to modules directory
- Ensure base environment is always provided
- Preserve user environment variable overrides
- Resolves -32000 Connection closed errors on macOS/Linux GUI
@timothycarambat timothycarambat merged commit 9470fcc into Mintplex-Labs:master Jun 3, 2025
cabwds pushed a commit to cabwds/anything-llm that referenced this pull request Jul 3, 2025
* Fix: MCP server environment inheritance across platforms

- Fix GUI applications not inheriting proper PATH/NODE_PATH
- Correct Docker NODE_PATH to point to modules directory
- Ensure base environment is always provided
- Preserve user environment variable overrides
- Resolves -32000 Connection closed errors on macOS/Linux GUI

* Fix: MCP server environment inheritance across platforms after linting

---------

Co-authored-by: Timothy Carambat <rambat1010@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants