proposal: ClientOptions.ResourceSubscriptionEndedHandler for observing resource-subscription termination

オープン
#1,284 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
go

調査の方向性

Start by reviewing ClientOptions, ResourceSubscriptionEndedRequest, and the resource-subscription lifecycle described in the issue, then compare the behavior with related issue #1283. Done means the exported API shape and callback semantics are approved, including handling of client-initiated versus remote termination, before implementation begins.

索引モデルが issue の本文から書いたものです。

説明

Motivation

#1283 fixes a bug where a resource subscription whose subscriptions/listen stream ends (server teardown, revoked resource, dropped connection) leaves a stale internal entry, so a bare re-Subscribe no-ops. That PR clears the subscription silently so re-Subscribe re-opens it, with no new exported API.

Silent cleanup, though, gives the application no way to observe that a subscription ended or to react to it — reconnect with its own backoff, surface a UI state, stop retrying. Today a client gets no signal at all when a live subscription dies underneath it.

Proposed API

type ClientOptions struct {
    // ...
    // ResourceSubscriptionEndedHandler is called (under SEP-2575) when the
    // subscriptions/listen stream backing a Subscribe ends for a reason other
    // than a client-initiated Unsubscribe or Close.
    ResourceSubscriptionEndedHandler func(context.Context, *ResourceSubscriptionEndedRequest)
}

// ResourceSubscriptionEndedRequest describes a resource subscription whose
// SEP-2575 subscriptions/listen stream has ended without a client-initiated
// Unsubscribe or Close.
type ResourceSubscriptionEndedRequest struct {
    URI      string // the resource whose subscription ended
    Err      error  // the terminating error, or nil on a graceful listen result
    Graceful bool   // whether it ended with a normal result rather than an error
}

Semantics

  • Opt-in. A nil handler keeps the #1283 behavior exactly: the subscription is cleared silently and a bare re-Subscribe re-opens it.
  • The SDK does not auto-resubscribe — a permanently revoked URI would hot-loop. The application owns retry/backoff and may call Subscribe again for the URI from within the handler. This is safe: the entry is cleared before the handler fires, and a per-subscription generation guard makes re-subscribe-from-callback (and an Unsubscribe→Subscribe race) well-defined.
  • Fires only for non-client-initiated ends; Unsubscribe and Close do not invoke it.

Cross-SDK context

The python and typescript SDKs already surface subscription-termination signals to callers (python raises on subscription loss / ends the async iteration; typescript reports a close reason distinguishing local vs graceful vs remote). This proposal gives Go clients an equivalent, idiomatic callback.

Process

This adds exported API (ResourceSubscriptionEndedHandler, ResourceSubscriptionEndedRequest), so per CONTRIBUTING it goes through the proposal process — filing ahead of a PR. A working implementation already exists (it was the original form of #1283, before the behavior fix was split out to land without new API); happy to open the PR once the shape is approved.

Related: #1283 (behavior-only fix, no new exported API).

主要言語
Go
スター
5.4k
フォーク
623
平均マージ
22時間 10分
マージ済み PR(30日)
30

環境構築

Codespaces で開く

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

はじめの一歩

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

modelcontextprotocol/go-sdk のほかの issue

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

似ている issue

Go の issue をもっと見る

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

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