[GH-ISSUE #3703] [FEAT]: Environment Variable Management for MCP Servers for WSL command #2387

Closed
opened 2026-02-22 18:29:27 -05:00 by yindo · 1 comment
Owner

Originally created by @suzuki-shm on GitHub (Apr 23, 2025).
Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/3703

What would you like to see?

Thank you for continuously implementing advanced features! I'm excited to see the new MCP client functionality in AnythingLLM.

I have tried out the new MCP server feature in AnythingLLM and wanted to share some observations.

Environment Variable Management

Currently, AnythingLLM may not support the env property in MCP server configurations.

The official MCP specification doesn’t include an env field, but tools like Claude Desktop and the VSCode extension allow us to declare environment variables directly in the JSON config for runtime use and within args.

As a result, users must pass environment variables as command-line arguments in args, and there’s no mechanism to inject them into the runtime environment itself.

In many MCP server repositories (e.g., mcp-servers), JSON examples leverage the env property extensively. By adding support for env in AnythingLLM, users could copy & paste existing MCP JSON configs without modification. It improves usability and adoption for MCP scenarios.

Thank you for considering this enhancement!

Appendix: Debug message at AnythingLLM Desktop

Case1: Try to use env property

{
  "mcpServers": {
    "github": {
      "command": "C:\\Windows\\System32\\wsl.exe",
      "args": [
        "bash",
        "-c",
        "/usr/bin/docker run -i --rm -e GITHUB_PERSONAL_ACCESS_TOKEN ghcr.io/github/github-mcp-server"
      ],
      "anythingllm": {
        "autoStart": true
      },
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "MY_GITHUB_ACCESS_TOKEN"
      }
    }
  }
}

Result: Failed (MCP error -32000: Connection closed)

[backend] info: [r] Attempting to start MCP server: github
time="2025-04-23T11:44:56Z" level=fatal msg="GITHUB_PERSONAL_ACCESS_TOKEN not set"

Case2: Embed environment variable to args

{
  "mcpServers": {
    "github": {
      "command": "C:\\Windows\\System32\\wsl.exe",
      "args": [
        "bash",
        "-c",
        "/usr/bin/docker run -i --rm -e GITHUB_PERSONAL_ACCESS_TOKEN=MY_GITHUB_ACCESS_TOKEN ghcr.io/github/github-mcp-server"
      ],
      "anythingllm": {
        "autoStart": true
      }
    }
  }
}

Result: Success

[backend] info: [r] Attempting to start MCP server: github
GitHub MCP Server running on stdio
[backend] info: [r] Successfully started 1 MCP servers: ["github"]

Originally created by @suzuki-shm on GitHub (Apr 23, 2025). Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/3703 ### What would you like to see? Thank you for continuously implementing advanced features! I'm excited to see the new MCP client functionality in AnythingLLM. I have tried out the new MCP server feature in AnythingLLM and wanted to share some observations. # Environment Variable Management Currently, AnythingLLM may not support the env property in MCP server configurations. The official MCP specification doesn’t include an env field, but tools like Claude Desktop and the VSCode extension allow us to declare environment variables directly in the JSON config for runtime use and within args. As a result, users must pass environment variables as command-line arguments in args, and there’s no mechanism to inject them into the runtime environment itself. In many MCP server repositories (e.g., [mcp-servers](https://github.com/modelcontextprotocol/servers/tree/main)), JSON examples leverage the env property extensively. By adding support for env in AnythingLLM, users could copy & paste existing MCP JSON configs without modification. It improves usability and adoption for MCP scenarios. Thank you for considering this enhancement! ## Appendix: Debug message at AnythingLLM Desktop ### Case1: Try to use env property ``` { "mcpServers": { "github": { "command": "C:\\Windows\\System32\\wsl.exe", "args": [ "bash", "-c", "/usr/bin/docker run -i --rm -e GITHUB_PERSONAL_ACCESS_TOKEN ghcr.io/github/github-mcp-server" ], "anythingllm": { "autoStart": true }, "env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "MY_GITHUB_ACCESS_TOKEN" } } } } ``` Result: Failed (MCP error -32000: Connection closed) > [backend] info: [r] Attempting to start MCP server: github time="2025-04-23T11:44:56Z" level=fatal msg="GITHUB_PERSONAL_ACCESS_TOKEN not set" ### Case2: Embed environment variable to args ``` { "mcpServers": { "github": { "command": "C:\\Windows\\System32\\wsl.exe", "args": [ "bash", "-c", "/usr/bin/docker run -i --rm -e GITHUB_PERSONAL_ACCESS_TOKEN=MY_GITHUB_ACCESS_TOKEN ghcr.io/github/github-mcp-server" ], "anythingllm": { "autoStart": true } } } } ``` Result: Success > [backend] info: [r] Attempting to start MCP server: github GitHub MCP Server running on stdio [backend] info: [r] Successfully started 1 MCP servers: ["github"]
yindo added the enhancementfeature request labels 2026-02-22 18:29:27 -05:00
yindo closed this issue 2026-02-22 18:29:27 -05:00
Author
Owner

@timothycarambat commented on GitHub (Apr 23, 2025):

We do handle env in the config?
See: https://github.com/Mintplex-Labs/anything-llm/blob/da3f97f61d6fb68407c24b4edabe912f62cd76e0/server/utils/MCP/hypervisor/index.js#L245C3-L275C4

Which then calls this function and looks for an env key in the server block and if any keys are present, will append the env to the entire config.

Actually, i realized you are using WSL, so this is on Desktop and its worth noting that since MCP uses env only on the spawned process those vars are not passed to the WSL container!. See this thread

That is the issue and why passing the -e flag on the command works, but env does not. The whole command is passed to the WSL container, but the env are local to the process running the WSL command, not the container iteself

@timothycarambat commented on GitHub (Apr 23, 2025): We do handle `env` in the config? See: https://github.com/Mintplex-Labs/anything-llm/blob/da3f97f61d6fb68407c24b4edabe912f62cd76e0/server/utils/MCP/hypervisor/index.js#L245C3-L275C4 Which then [calls this function ](https://github.com/Mintplex-Labs/anything-llm/blob/da3f97f61d6fb68407c24b4edabe912f62cd76e0/server/utils/MCP/hypervisor/index.js#L220-L237) and looks for an `env` key in the server block and if any keys are present, will append the `env` to the entire config. Actually, i realized you are using WSL, so this is on Desktop and its worth noting that since MCP uses `env` only on the `spawned` process those vars are _not passed to the WSL container!_. See this [thread](https://github.com/microsoft/vscode/issues/245045) That is the issue and why passing the `-e` flag on the command works, but `env` does not. The whole command is passed to the WSL container, but the `env` are local to the process _running the WSL command, not the container iteself_
yindo changed title from [FEAT]: Environment Variable Management for MCP Servers for WSL command to [GH-ISSUE #3703] [FEAT]: Environment Variable Management for MCP Servers for WSL command 2026-06-05 14:46:16 -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#2387