Local MCPs fail to start - stdin closes immediately after spawn #5729

Closed
opened 2026-02-16 17:56:06 -05:00 by yindo · 0 comments
Owner

Originally created by @yanosh-k on GitHub (Jan 14, 2026).

Originally assigned to: @thdxr on GitHub.

Description

Local MCPs that worked in v1.1.16 fail to connect in v1.1.17 and later (tested with v1.1.19). When attempting to enable a local MCP via /mcp menu, the MCP shows as "failed" instead of "connected".

Environment:

Installation Method: npm (npm install in /srv/ai/open_code/)
Execution Method: Direct invocation of /srv/ai/open_code/node_modules/.bin/opencode
Node Version: v24.13.0 (installed via snap at /snap/bin/node)

Findings:

When starting the MCP server with NODE_DEBUG=* and DEBUG=*, I get the following in the logs:

STREAM 135231: read undefined
STREAM 135231: need readable true

while the command for starting the MCP server exits with code 0.

This leads me to believe that the following is happening with the MCP server:

  1. Loads successfully
  2. Starts listening on stdin
  3. Immediately receives undefined (EOF) when trying to read from stdin
  4. Exits cleanly with code 0

Probably indicating that OpenCode is closing stdin before the MCP server can read from it, or not properly piping stdin to the MCP server process.

Analyzing the code changes between v1.1.16 and v1.1.17:

  • In v1.1.16:
    The postinstall.mjs script called symlinkBinary() which created a direct symlink from .bin/opencode to the native Bun binary at node_modules/opencode-linux-x64/bin/opencode
  • In v1.1.17:
    The symlinkBinary() call was removed
    The Node.js wrapper script at node_modules/opencode-ai/bin/opencode is now used instead
    This wrapper uses child_process.spawnSync() with stdio: "inherit"

When executed via the wrapper script:

  • Node.js wrapper spawns the native Bun binary with spawnSync(..., { stdio: "inherit" })
  • The Bun binary attempts to spawn MCP subprocesses via StdioClientTransport
  • The MCP subprocess receives EOF on stdin immediately and exits

The stdio inheritance chain appears to break somewhere between:

  • Node.js wrapper → Bun binary → MCP subprocess

The MCPs can be enabled correctly when:

  • Running the native Bun opencode binary directly (bypassing the Node.js wrapper) - /srv/ai/open_code/node_modules/opencode-linux-x64/bin/opencode
  • Running the MCP command manually from a terminal (terminal keeps stdin open)

Plugins

No response

OpenCode version

v1.1.17

Steps to reproduce

  1. Install opencode v1.1.17 with npm: npm install opencode-ai@1.1.17
  2. Configure a local MCP in ~/.config/opencode/opencode.json:
{
  "mcp": {
    "playwright-cdp": {
      "type": "local",
      "command": [
        "node",
        "/srv/ai/mcp/playwright/node_modules/@playwright/mcp/cli.js",
        "--cdp-endpoint=http://localhost:9222"
      ],
      "enabled": false
    }
  }
}
  1. Start opencode: /srv/ai/open_code/node_modules/.bin/opencode
  2. Type /mcp to open the MCP management menu
  3. Toggle the status of playwright-cdp from disabled to enabled

Screenshot and/or share link

Image

Operating System

Ubuntu 24.04

Terminal

Gnome Terminal

Originally created by @yanosh-k on GitHub (Jan 14, 2026). Originally assigned to: @thdxr on GitHub. ### Description Local MCPs that worked in v1.1.16 fail to connect in v1.1.17 and later (tested with v1.1.19). When attempting to enable a local MCP via /mcp menu, the MCP shows as "failed" instead of "connected". **Environment:** _Installation Method:_ npm (npm install in /srv/ai/open_code/) _Execution Method:_ Direct invocation of /srv/ai/open_code/node_modules/.bin/opencode _Node Version:_ v24.13.0 (installed via snap at /snap/bin/node) **Findings:** When starting the MCP server with NODE_DEBUG=* and DEBUG=*, I get the following in the logs: ``` STREAM 135231: read undefined STREAM 135231: need readable true ``` while the command for starting the MCP server exits with code 0. This leads me to believe that the following is happening with the MCP server: 1. Loads successfully 2. Starts listening on stdin 3. Immediately receives undefined (EOF) when trying to read from stdin 4. Exits cleanly with code 0 Probably indicating that OpenCode is closing stdin before the MCP server can read from it, or not properly piping stdin to the MCP server process. **Analyzing the code changes between v1.1.16 and v1.1.17:** - In v1.1.16: The postinstall.mjs script called symlinkBinary() which created a direct symlink from .bin/opencode to the native Bun binary at node_modules/opencode-linux-x64/bin/opencode - In v1.1.17: The symlinkBinary() call was removed The Node.js wrapper script at node_modules/opencode-ai/bin/opencode is now used instead This wrapper uses child_process.spawnSync() with stdio: "inherit" When executed via the wrapper script: - Node.js wrapper spawns the native Bun binary with spawnSync(..., { stdio: "inherit" }) - The Bun binary attempts to spawn MCP subprocesses via StdioClientTransport - The MCP subprocess receives EOF on stdin immediately and exits The stdio inheritance chain appears to break somewhere between: - Node.js wrapper → Bun binary → MCP subprocess The MCPs can be enabled correctly when: - Running the native Bun opencode binary directly (bypassing the Node.js wrapper) - `/srv/ai/open_code/node_modules/opencode-linux-x64/bin/opencode` - Running the MCP command manually from a terminal (terminal keeps stdin open) ### Plugins _No response_ ### OpenCode version v1.1.17 ### Steps to reproduce 1. Install opencode v1.1.17 with npm: npm install opencode-ai@1.1.17 3. Configure a local MCP in ~/.config/opencode/opencode.json: ``` { "mcp": { "playwright-cdp": { "type": "local", "command": [ "node", "/srv/ai/mcp/playwright/node_modules/@playwright/mcp/cli.js", "--cdp-endpoint=http://localhost:9222" ], "enabled": false } } } ``` 4. Start opencode: /srv/ai/open_code/node_modules/.bin/opencode 5. Type /mcp to open the MCP management menu 6. Toggle the status of playwright-cdp from disabled to enabled ### Screenshot and/or share link <img width="560" height="228" alt="Image" src="https://github.com/user-attachments/assets/a09d0efb-6d25-47ba-afc8-11f9d484edfa" /> ### Operating System Ubuntu 24.04 ### Terminal Gnome Terminal
yindo added the bug label 2026-02-16 17:56:06 -05:00
yindo closed this issue 2026-02-16 17:56:07 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#5729