proposal: ClientOptions.ResourceSubscriptionEndedHandler for observing resource-subscription termination

Abierto
#1,284 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
go

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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).

Lenguaje dominante
Go
Estrellas
5.4k
Forks
623
Merge medio
22 h 10 min
PR fusionados (30 d)
30

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de modelcontextprotocol/go-sdk

Todos los issues de modelcontextprotocol/go-sdk

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.