Skip to content

fix(mcp): read string commands from opencode.json and pass environment on first connect - #4552

Merged
reachjalil merged 2 commits into
devfrom
fix/local-mcp-first-connect
Sep 10, 2026
Merged

reachjalil merged 2 commits into
devfrom
fix/local-mcp-first-connect

Conversation

@reachjalil

Copy link
Copy Markdown
Member

Problem

Two ways a local MCP breaks the first time someone uses it:

  1. Blank Settings page on a valid-looking config. People copy servers from Claude Desktop or Cursor, where the shape is command: "python3", args: ["server.py"]. OpenWork read command as if it were already an array, so the Settings route threw inside render and the whole page went white (Settings page renders blank/white when a local MCP server uses string command (config.command?.some is not a function) #3372, [Bug]: Windows: hard throw in getComputerUseMcpCommand() crashes desktop renderer (blank screen) on 0.17.30 and 0.17.32 #2908). The user cannot even reach the list to fix or remove the entry.
  2. "MCP error -32000: Connection closed" on first connect. When OpenWork connects a local server without the OpenWork server path, the hot-add call that actually spawns the process carried the command but not its resolved environment. The file on disk was correct, so the same server connected fine after a restart, which made the failure look intermittent.

Change

  • apps/app/src/app/mcp.ts: parseMcpServersFromContent normalizes a string command plus optional args into one command list. Array commands and remote entries pass through unchanged; an empty string command is dropped rather than spawned. Every downstream reader (Settings, the connections store, the MCP view) sees one shape.
  • apps/app/src/react-app/domains/connections/store.ts: the local hot-add config forwards environment the same way the remote branch already forwards headers and oauth.

Verification

  • pnpm --filter @openwork/app typecheck — passed.
  • bun test --isolate tests/mcp-oauth-status-synchronization.test.ts (apps/app) — 14 passed, 0 failed (3 new: string command with args becomes one list; array and remote entries unchanged and unknown types dropped; empty string command dropped).

Verdict: Incomplete

No evals/specs journey seeds a workspace opencode.json with a local MCP and opens Settings → Connections, so the blank-page recovery is proven at the parser boundary only. Missing: an app journey that seeds a string-command entry and asserts the Settings page lists it. Manual repro: add "docs": { "type": "local", "command": "python3", "args": ["-m", "http.server"] } under mcp in a workspace's opencode.json, open Settings → Connections, and confirm the page renders with the entry listed.

…t on first connect

Users who paste a Claude Desktop or Cursor style server into opencode.json
(command: "python3", args: [...]) got a blank Settings page, because every
reader assumed command was already an array. The parser now reads both shapes
into one command list so the server appears in the list and can be edited or
removed.

Connecting a local MCP without the OpenWork server forwarded the command but
not its resolved environment to the hot-add call that actually spawns the
process, so a server that needs an environment variable failed on its first
connect and only worked after an engine restart. The hot-add config now
carries the same environment that is written to the file.
@vercel

vercel Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
openwork-den Ready Ready Preview Sep 6, 2026 6:37am UTC
openwork-diagnostics Ready Ready Preview Sep 6, 2026 6:37am UTC
openwork-landing Ready Ready Preview, v0 Sep 6, 2026 6:37am UTC
1 Skipped Deployment
Project Deployment Actions Updated
openwork-app Ignored Ignored Preview Sep 6, 2026 6:37am UTC

@vercel
vercel Bot temporarily deployed to Preview – openwork-diagnostics September 6, 2026 06:11 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-landing September 6, 2026 06:11 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-den September 6, 2026 06:11 Inactive
diff-warden[bot]
diff-warden Bot previously approved these changes Sep 6, 2026

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (bd4911b7a89fcb92001dd7f0e3eb6652c9231590). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

…er command shape

A person who copies a server from Claude Desktop or Cursor writes
command: "python3", args: [...] into opencode.json. The journey writes that
entry beside an array-command server and a remote server, opens Settings ->
Library -> MCPs, and asserts all three are listed, the page stayed rendered,
and Technical details shows the folded command line.

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (b1237658d53ec93eb70fc29e0cb9c8a238df6ebd). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

This branch was successfully deployed

4 active (1 outdated) deployments
Preview – openwork-landing — b1237658 Deployed Sep 6, 2026 by vercel[bot]
Preview – openwork-den — b1237658 Deployed Sep 6, 2026 by vercel[bot]
Preview – openwork-diagnostics — b1237658 Deployed Sep 6, 2026 by vercel[bot]
Preview – openwork-app — bd4911b7 Deployed Sep 6, 2026 by vercel[bot]
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.

1 participant