Skip to content

fix(desktop): wrap MCP commands with wsl.exe when WSL mode is enabled#28147

Closed
herjarsa wants to merge 3 commits into
anomalyco:devfrom
herjarsa:fix/wsl-mcp-disconnect
Closed

fix(desktop): wrap MCP commands with wsl.exe when WSL mode is enabled#28147
herjarsa wants to merge 3 commits into
anomalyco:devfrom
herjarsa:fix/wsl-mcp-disconnect

Conversation

@herjarsa
Copy link
Copy Markdown

@herjarsa herjarsa commented May 18, 2026

Issue for this PR

Closes #28159

Type of change

  • Bug fix

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.fork which 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:

  1. packages/desktop/src/main/server.ts: createSidecarEnv() now reads getWslConfig() and sets OPENCODE_WSL_ENABLED=true in the sidecar's environment variables when WSL is enabled.

  2. packages/opencode/src/mcp/index.ts: In connectLocal(), checks for process.platform === "win32" && process.env.OPENCODE_WSL_ENABLED === "true". When WSL mode is detected, wraps the command with wsl.exe -e so it runs inside the default WSL distribution where the expected environment exists. wsl.exe automatically handles Windows-to-WSL path mapping, so the working directory is preserved as-is.

How did you verify your code works?

  • Verified LSP diagnostics pass on both modified files (zero errors)
  • Verified the environment propagation chain: Desktop store -> createSidecarEnv() -> utilityProcess.fork() env -> sidecar process.env -> MCP connectLocal() detection
  • Verified the fix only activates on process.platform === "win32" (no effect on macOS/Linux)
  • Ran MCP lifecycle tests (20 passed, 1 pre-existing timeout flake unrelated to these changes)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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
@herjarsa herjarsa requested a review from adamdotdevin as a code owner May 18, 2026 10:10
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels May 18, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label May 18, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

Desktop: MCP servers appear disconnected when WSL mode is enabled

2 participants