mcp: local server not restarted after transport error
维护者通常 1 天内回复
@nexxeln 已经在做这个了。
开始于 2026年10月4日。
评估
这个 Issue 还没有评估数据。
描述
Summary
When a local (stdio) MCP server process exits unexpectedly while a session is already connected, OpenCode logs a single mcp transport error warning and never restarts it. The server's tools silently disappear from the agent's tool list for the remainder of the session. Only an unrelated event — a write to the OpenCode config file, or starting a new session — causes the server to be spawned again.
Environment
- opencode version: v2.0.22 (channel
latest) - OS: Windows_NT 10.0.26200.9550 (win32 x64)
- Terminal: Windows Terminal (
WT_SESSIONset),TERM=xterm-256color - Shell:
C:\WINDOWS\system32\cmd.exe - Install/channel: latest (npm
@opencode/cli) - Active plugins: none configured in
opencode.json
Reproduction
- Configure a local stdio MCP server that stays alive after
initialize, for example:{ "mcp": { "servers": { "playwright": { "type": "local", "command": ["C:\\Program Files\\nodejs\\node.exe", "C:\\path\\to\\mcp\\cli.js"] } } } } - Have OpenCode sessions open in two or more directories, so several connections to the same server are spawned (one per directory).
- Kill the MCP server process from outside OpenCode. A realistic trigger is another OpenCode session running a broad process cleanup such as:
AnyGet-Process node,msedge -ErrorAction SilentlyContinue | Where-Object { $_.StartTime -gt (Get-Date).AddMinutes(-25) } | ForEach-Object { try { $_.Kill() } catch {} }taskkill, service restart of a parent process, or OOM kill should behave the same way. - Observe that the MCP tools are no longer offered to the agent, and that nothing brings them back.
Expected Behavior
A local MCP server whose process exits unexpectedly should be restarted automatically (ideally with backoff and a cap on retries), so its tools remain available. At minimum, a crash while connected should be retried the same way an initial connect failure is.
Actual Behavior
One warning is logged per connection and then nothing:
timestamp=2026-10-04T20:48:21.035Z level=WARN message="mcp transport error" server=playwright error="MCP server process exited with code 255" role=server directory="<project-a>" connectionID=<id>
timestamp=2026-10-04T20:48:21.051Z level=WARN message="mcp transport error" server=playwright error="MCP server process exited with code 255" role=server directory="<project-b>" connectionID=<id>
timestamp=2026-10-04T20:48:21.067Z level=WARN message="mcp transport error" server=playwright error="MCP server process exited with code 255" role=server directory="<project-c>" connectionID=<id>
timestamp=2026-10-04T20:48:21.082Z level=WARN message="mcp transport error" server=playwright error="MCP server process exited with code 255" role=server directory="<project-d>" connectionID=<id>
timestamp=2026-10-04T20:48:21.099Z level=WARN message="mcp transport error" server=playwright error="MCP server process exited with code 255" role=server directory="<home>" connectionID=<id>
No mcp connected line follows, and no retry is attempted. The agent's tool list loses every tool from that server and does not recover on its own.
Notes on scope and contrast:
- The shared background service was not restarted during this occurrence (same PID and start time before and after), so this is specific to MCP child processes rather than a service restart.
- Retry-on-startup does appear to exist: an earlier
mcp connect failedwas followed by a successfulmcp connectedroughly 35 seconds later. What is missing is retry-on-crash for a server that was already connected. - Writing to the global config file causes all connections to be torn down and respawned immediately (
mcp connected ... tools=25for every directory within ~2s), which currently works as an accidental recovery trigger.
Additional Context
- Frequency: 4 occurrences within roughly 40 minutes in one session. Always reproducible when the child process is killed.
- Exit code was
255in every occurrence, consistent with an external kill rather than a crash inside the server. The MCP server itself worked correctly when spawned manually:initializesucceeded,tools/listreturned 25 tools, andtools/call browser_navigatesucceeded. - An earlier, separate failure mode was also observed and is believed to be a different issue: when the command was
npx -y <package>, several connections spawned at once raced on the package manager's shared install cache and died withENOTEMPTY ... InstallFailed extracting tarball. Working around it by pre-installing the package and using an absolute path made startup reliable. Mentioned here only for context. - Workarounds currently used: write to the global
opencode.jsonto force a respawn, oropencode service restart. Both are indirect — the first mutates configuration as a side effect. - Suggested direction (if this is a bug rather than intended behavior): treat
mcp transport errorlike a failed connect and re-enter the spawn/retry path, ideally with exponential backoff and a cap so a permanently broken server does not spin.
- 主要语言
- TypeScript
- 星标
- 221k
- 派生
- 29.6k
- 平均合并
- 5 小时 22 分钟
- 30 天内合并 PR
- 531
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
anomalyco/opencode 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
anomalyco/opencode#59052 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
anomalyco/opencode#59040 · 1 条评论 ·
维护者通常 1 天内回复
-
reproduced
难度 2/5 1-3 小时 新手友好度 69/100
anomalyco/opencode#58981 · 2 条评论 ·
维护者通常 1 天内回复
-
triaging
难度 2/5 1-3 小时 新手友好度 65/100
anomalyco/opencode#58821 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
anomalyco/opencode#58774 · 1 条评论 ·
维护者通常 1 天内回复
查看 anomalyco/opencode 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
outline/outline#14348 · 1 条评论 ·
维护者通常 1 天内回复
-
bug needs-triage
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
[Bug]: Agent import retains quotes in .env API keys followed by inline comments可能已有人在做 @yxr-2025 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
awslabs/visual-asset-management-system#804 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
dsh-market/dsh-market#1027 · 1 条评论 ·
维护者通常 1 天内回复