mcp: notifications and interrupted calls lose ErrConnectionClosed
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
The issue describes errors in the notification sending path and JSON-RPC reader of the mcp package; start by reading Client.Connect and the call retirement logic. Run the provided main.go repro to observe closed=false eof=true. The fix should translate closing errors to mcp.ErrConnectionClosed preserving causes with %w, but a linked PR already implements this.
索引モデルが issue の本文から書いたものです。
説明
Problem
Client.Connect documents that calls or notifications return an error wrapping mcp.ErrConnectionClosed when the server closes the connection.
Two cases lose that classification:
- A notification sent after the client observes server closure.
- An outstanding call interrupted when the server process exits.
A subsequent call matches ErrConnectionClosed, but its underlying EOF is no longer reachable with errors.Is.
Expected behavior
For these connection-termination errors, errors.Is(err, mcp.ErrConnectionClosed) should return true while preserving the underlying cause.
Ordinary context cancellation, JSON-RPC error responses, and result-decoding errors should retain their existing classification.
Reproduction
SDK: commit 2e00768cd.
Go: go1.27.3 linux/amd64.
OS: Ubuntu 22.04.2 LTS.
Save this as main.go in a separate module using that SDK revision and run go run .. The program starts a copy of itself as a stdio server. Its tool exits the server process before returning a response.
package main
import (
"context"
"errors"
"fmt"
"io"
"os"
"os/exec"
"time"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
func main() {
ctx := context.Background()
impl := &mcp.Implementation{Name: "repro", Version: "v0.0.1"}
if len(os.Args) > 1 && os.Args[1] == "server" {
s := mcp.NewServer(impl, nil)
mcp.AddTool(s, &mcp.Tool{Name: "exit"}, func(context.Context, *mcp.CallToolRequest, struct{}) (*mcp.CallToolResult, any, error) {
os.Exit(3)
return nil, nil, nil
})
check(s.Run(ctx, &mcp.StdioTransport{}))
return
}
exe, err := os.Executable()
check(err)
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
cs, err := mcp.NewClient(impl, nil).Connect(ctx,
&mcp.CommandTransport{Command: exec.Command(exe, "server")}, nil)
check(err)
defer cs.Close()
for _, name := range []string{"interrupted call", "next call"} {
_, err := cs.CallTool(ctx, &mcp.CallToolParams{Name: "exit"})
check(ctx.Err())
report(name, err)
}
report("notification", cs.NotifyProgress(ctx,
&mcp.ProgressNotificationParams{ProgressToken: "p"}))
}
func check(err error) {
if err != nil {
panic(err)
}
}
func report(name string, err error) {
fmt.Printf("%s: closed=%t eof=%t\n", name,
errors.Is(err, mcp.ErrConnectionClosed), errors.Is(err, io.EOF))
}
On the affected revision:
interrupted call: closed=false eof=true
next call: closed=true eof=false
notification: closed=false eof=true
All three operations should report closed=true eof=true.
Root cause
The notification sending path returns the internal JSON-RPC closing error without translating it to mcp.ErrConnectionClosed.
The JSON-RPC reader retires outstanding calls with the raw read error. Those errors bypass the MCP call path's closing-error translation. That translation also formats the underlying error with %v, losing its identity.
The fix should mark calls where reader termination retires them, translate notification closing errors, and preserve causes with %w. Mapping EOF values alone would misclassify result-decoding errors.
The change was drafted with AI assistance (OpenAI Codex, reviewed with Claude Code).
🤖 Generated with Claude Code
- 主要言語
- Go
- スター
- 5.3k
- フォーク
- 606
- 平均マージ
- 1日 16時間
- マージ済み PR(30日)
- 72
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelcontextprotocol/go-sdk のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
modelcontextprotocol/go-sdk#1444 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
Session-lifecycle bookkeeping logs at info, spamming multiple log lines per request on stateless streamable HTTP対応中かも @anneheartrecord が 60 日前に担当しました。 オープンP3
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
modelcontextprotocol/go-sdk#1204 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensions対応中かも @ajuijas が 226 日前に担当しました。 オープンneeds investigation
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
modelcontextprotocol/go-sdk#745 · コメント 13 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
internal/json: Unmarshal allocates a 32 KiB stream buffer on every call対応中かも @raveesh-me が 1 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
modelcontextprotocol/go-sdk#1453 ·
メンテナーはふだん 1 日以内に返信
-
auth/extauth: ClientCredentialsHandler does not send the resource parameter対応中かも @shlee1223 が 2 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 25/100
modelcontextprotocol/go-sdk#1450 ·
メンテナーはふだん 1 日以内に返信
modelcontextprotocol/go-sdk の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 1/5 1〜3時間 初心者へのやさしさ 76/100
superplanehq/superplane#9007 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
yetone/magpie#3905 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信