stdio: responses to already-received requests are dropped when stdin EOF arrives first (one-shot pipes get no output)
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
internal/jsonrpc2/conn.go から始め、508/543 行付近の read loop、672–682/693ff 付近の processResult、707–719/749ff 付近の write、141–145/158–162 付近の shuttingDown を読みます。one-shot pipe の再現を実行し、stdin が遅延するケースと比較します。stdin EOF より前に受信したリクエストへのレスポンスが、接続が閉じられる前に書き込まれれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Summary
A stdio server driven by a one-shot pipe — stdin closes right after the last request — writes no responses at all, even though every request was received intact and stdout is perfectly writable. The read-side EOF marks the connection as shutting down, and the shutdown check then refuses the write of responses the handlers have already computed. Holding stdin open a fraction of a second longer makes every response appear, so this is purely a shutdown-ordering issue, not lost input.
Versions
github.com/modelcontextprotocol/go-sdkv1.6.1 (latest release; the relevant code is unchanged onmainas of filing)- Go 1.26, darwin/arm64 (same behavior on linux)
Reproduction
Minimal server:
package main
import (
"context"
"log"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
func main() {
s := mcp.NewServer(&mcp.Implementation{Name: "repro", Version: "0.0.1"}, nil)
if err := s.Run(context.Background(), &mcp.StdioTransport{}); err != nil {
log.Fatal(err)
}
}
Driver:
REQS='{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"t","version":"0"}}}
{"jsonrpc":"2.0","method":"notifications/initialized"}
{"jsonrpc":"2.0","id":2,"method":"tools/list"}'
# One-shot pipe: stdin closes immediately after the last request.
printf '%s\n' "$REQS" | ./repro | grep -c '"id"'
# => 0 (no responses at all; 100% reproducible)
# Same requests, stdin held open 0.3s after the last one.
{ printf '%s\n' "$REQS"; sleep 0.3; } | ./repro | grep -c '"id"'
# => 2 (both responses arrive)
Mechanism (internal/jsonrpc2/conn.go; line numbers are v1.6.1, with main as of 2026-07-08 in parentheses)
- The pipe closes; the read loop gets
io.EOFand records it:s.readErr = err— conn.go:508 (main: 543). - Handlers for the already-received requests finish and try to respond:
processResult→c.write(...)— conn.go:672–682 (main: 693ff). writefirst checkss.shuttingDown(ErrServerClosing)— conn.go:707–719 (main: 749ff) — andshuttingDownreturns an error wheneverreadErr != nil— conn.go:141–145 (main: 158–162) — so the computed response is discarded even though the writer is healthy.
The readErr branch's own comment explains its intent — "we cannot read new call requests, and cannot read responses to our outgoing calls" — both about the read side. Refusing writes of responses to requests that were already read goes beyond that intent.
Why this matters
Any one-shot or batch caller of a stdio MCP server gets empty output: shell scripting, smoke tests in CI, printf | server probes while debugging. Persistent clients that keep stdin open (every real MCP host) are unaffected, which makes the failure look like the caller's bug — it cost us a while to trace it into the connection state machine.
Expected behavior
Read-side EOF should stop accepting new requests, but responses to requests already received should drain to the writer before the connection reports closed (the common half-close contract: EOF on input, flush output, then exit).
Workaround we use
Keep stdin open briefly after the final request (sleep 0.3 before closing the pipe), or drive the server through a persistent client.
- 主要言語
- Go
- スター
- 5.4k
- フォーク
- 623
- 平均マージ
- 22時間 10分
- マージ済み PR(30日)
- 30
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelcontextprotocol/go-sdk のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
modelcontextprotocol/go-sdk#1557 ·
メンテナーはふだん 1 日以内に返信
-
Streamable HTTP (2026-07-28): tools/call with an out-of-range number in arguments fails because extractName decodes Arguments into any再び着手できるかも @beiryu が 10 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
modelcontextprotocol/go-sdk#1534 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensions再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンneeds investigation
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
modelcontextprotocol/go-sdk#745 · コメント 13 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 18/100
modelcontextprotocol/go-sdk#1555 ·
メンテナーはふだん 1 日以内に返信
-
mcp: 2026-07-28 client runs elicitation and sampling handlers for standalone server requests再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
modelcontextprotocol/go-sdk#1552 ·
メンテナーはふだん 1 日以内に返信
modelcontextprotocol/go-sdk の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
apache/dubbo-admin#1659 ·
メンテナーはふだん 8 日以内に返信
-
taskmanager: a failed v1alpha1 backup leaves the partial backup behind対応中かも @arshil42 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100