Skip to content
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

MCP: Support servers running within WSL #245045

Closed
gabrielgrant opened this issue Mar 29, 2025 · 3 comments
Closed

MCP: Support servers running within WSL #245045

gabrielgrant opened this issue Mar 29, 2025 · 3 comments
Assignees
Labels
*duplicate Issue identified as a duplicate of another issue(s)

Comments

@gabrielgrant
Copy link

gabrielgrant commented Mar 29, 2025

Does this issue occur when all extensions are disabled?: Yes/No

  • VS Code Version: 1.99.0-insider (user setup)
  • Commit: fbdf6dd
  • OS Version: Windows 11 with Ubuntu in WSL 2
Version: 1.99.0-insider (user setup)
Commit: fbdf6dd0792dfd4183ae3c273b1484d3451e60ab
Date: 2025-03-25T10:15:42.306Z
Electron: 34.3.2
ElectronBuildId: 11161073
Chromium: 132.0.6834.210
Node.js: 20.18.3
V8: 13.2.152.41-electron.0
OS: Windows_NT x64 10.0.22631

Steps to Reproduce:

  1. Add a MCP server that expects to run within WSL. Eg
"brave-search": {
                "command": "docker",
                "args": [
                    "run",
                    "-i",
                    "--rm",
                    "-e",
                    "BRAVE_API_KEY",
                    "mcp/brave-search"
                ],
                "env": {
                    "BRAVE_API_KEY": "***"
                }
            }
  1. Hit refresh 🔁 icon in agent-mode chat
  2. Observe errors:
2025-03-25 11:17:38.637 [info] Starting server brave-search
2025-03-25 11:17:38.637 [info] Connection state: Starting
2025-03-25 11:17:38.649 [info] Starting server from LocalProcess extension host
2025-03-25 11:17:38.673 [info] Connection state: Starting
2025-03-25 11:17:38.675 [info] Connection state: Error spawn docker ENOENT

Despite being in a WSL workspace, it seems VSCode is trying to launch the server on the windows side.

The command works fine within WSL:

$ docker run -i --rm -e BRAVE_API_KEY mcp/brave-search
Unable to find image 'mcp/brave-search:latest' locally
latest: Pulling from mcp/brave-search
38a8310d387e: Pull complete 
796da77e1307: Pull complete 
...

Possible solutions:

  1. default to running the MCP server in whichever environment the user is currently operating
  2. A key in the MCP config allowing specification of which environment in which to run the server

Currently can kinda work around the problem by explicitly specifying the MCP server command as using WSL:

"brave-search": {
                "command": "wsl",
                "args": [
                    "docker",
                    "run",
                    "-i",
                    "--rm",
                    "-e",
                    "BRAVE_API_KEY",
                    "mcp/brave-search"
                ],
                "env": {
                    "BRAVE_API_KEY": "***"
                }
            }

but this still causes issues/added complexity with sharing env vars (that will set the key in the windows env, not in WSL)

2025-03-25 11:39:34.556 [info] Starting server brave-search
2025-03-25 11:39:34.557 [info] Connection state: Starting
2025-03-25 11:39:34.570 [info] Starting server from LocalProcess extension host
2025-03-25 11:39:34.571 [info] Connection state: Starting
2025-03-25 11:39:34.571 [info] Connection state: Running
2025-03-25 11:39:35.330 [warning] [server stderr] Error: BRAVE_API_KEY environment variable is required
2025-03-25 11:39:35.826 [info] Connection state: Error Process exited with code 1

There are probably other WSL-related complexities I haven't yet encountered (work dirs?). Overall, seems important to have a comprehensive story around how MCP+WSL works

@gabrielgrant
Copy link
Author

gabrielgrant commented Mar 29, 2025

Ah, looks like this was already addressed: #243687 (comment)

The solution provided is to configure MCP servers in the WSL env's remote settings, rather than in user settings.

This still doesn't work without some fiddling: while commands are run and env var are set in the WSL env, seems the MCP servers are not launched with my "normal" terminal shell env, so npx managed by nvm isn't found, for example

I dumped info about the env with this simple MCP server entry:

            "env-test": {
                "command": "env",
                "env": {
                    "MY_TEST_ENV_KEY": "hello from env-test MCP server"
                }
            },

Leaving this open as an issue to at least document this story better, if not make technical changes to provide better support

@connor4312
Copy link
Member

We have an tracking nvm support on Windows already 👍

@connor4312 connor4312 added the *duplicate Issue identified as a duplicate of another issue(s) label Mar 31, 2025
@gabrielgrant
Copy link
Author

Are you saying there is another GH issue tracking this? Or that there is an internal tracking issue somewhere?

FWIW was able to pretty effectively work around the issues by running a bash login shell from my user profile (and setting env vars inline)

"mcp": {
        "inputs": [],
        "servers": {
            "fetch": {
                "command": "bash.exe",
                "args": ["--login", "-c", "uvx mcp-server-fetch"]
            },
            "mcp-server-code-runner": {
                "command": "bash.exe",
                "args": [
                    "--login"
                    "-c",
                    "npx -y mcp-server-code-runner",
                ],
            },
            "brave-search": {
                "command": "bash.exe",
                "args": [
                    "--login",
                    "-c"
                    "BRAVE_API_KEY=*** docker run -i --rm -e BRAVE_API_KEY mcp/brave-search"
                ]
            }
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
*duplicate Issue identified as a duplicate of another issue(s)
Projects
None yet
Development

No branches or pull requests

3 participants