Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

mcp: notifications and interrupted calls lose ErrConnectionClosed

クローズ
#1,448 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@Jackmeson1 がすでに取り組んでいます。

2026年10月25日 から。

  • #1449 @Jackmeson1 による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
30/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
go
領域
backend

調査の方向性

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

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

modelcontextprotocol/go-sdk のほかの issue

modelcontextprotocol/go-sdk の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。