fix(desktop): wrap MCP commands with wsl.exe when WSL mode is enabled#28147
Closed
herjarsa wants to merge 3 commits into
Closed
fix(desktop): wrap MCP commands with wsl.exe when WSL mode is enabled#28147herjarsa wants to merge 3 commits into
herjarsa wants to merge 3 commits into
Conversation
When the desktop app runs on Windows with WSL mode enabled, MCP 'local' commands configured in opencode.json reference Linux executables that dont exist in the Windows sidecar environment. This causes MCP servers to appear disconnected in the desktop UI while working correctly in the CLI (which runs inside WSL). The fix adds two changes: 1. In packages/desktop/src/main/server.ts: pass OPENCODE_WSL_ENABLED=true to the sidecar process when WSL is configured 2. In packages/opencode/src/mcp/index.ts: in connectLocal(), detect WSL mode and wrap the MCP command with wsl.exe -e so it executes inside WSL where the expected Linux environment exists
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #28159
Type of change
What does this PR do?
When the desktop app runs on Windows with WSL mode enabled, MCP 'local' commands configured in opencode.json reference Linux executables that do not exist in the Windows sidecar environment. This causes MCP servers to appear disconnected in the desktop UI while working correctly in the CLI (which runs inside WSL).
Root cause: The desktop spawns a sidecar via Electron's
utilityProcess.forkwhich runs natively on Windows. MCP commands that expect a Linux/WSL environment fail because the executables literally do not exist on the Windows filesystem.Fix: Two changes that make MCP commands execute inside WSL when WSL mode is active:
packages/desktop/src/main/server.ts:createSidecarEnv()now readsgetWslConfig()and setsOPENCODE_WSL_ENABLED=truein the sidecar's environment variables when WSL is enabled.packages/opencode/src/mcp/index.ts: InconnectLocal(), checks forprocess.platform === "win32" && process.env.OPENCODE_WSL_ENABLED === "true". When WSL mode is detected, wraps the command withwsl.exe -eso it runs inside the default WSL distribution where the expected environment exists.wsl.exeautomatically handles Windows-to-WSL path mapping, so the working directory is preserved as-is.How did you verify your code works?
process.platform === "win32"(no effect on macOS/Linux)Checklist