Adopting `with`- style accessors as part of the Transport APIs

Abierto
#126 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

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

Línea de trabajo

Start by reading the existing Transport API entry points for connect(), send(), and receive(), then compare them with the proposed withClient closure flow. Done means a bootstrap can manage the connection for the closure, expose sending and incoming messages there, and close and clean up when the closure returns.

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

Descripción

enhancement

Is your feature request related to a problem? Please describe.
The current Transport APIs require the user to call connect() to establish a connection. From this point, the user has to manually track whether or not the connection is still alive, by handling any errors thrown by send or receive.

If a user wants to correctly handle error cases, this leads to more complexity in their implementations.

Describe the solution you'd like
In the Swift on Server ecosystem, we've adopted a with- style pattern, which compliments prior art in Swift's standard library. In there, we have a "bootstrap" for each transport that can be configured with the intended behavior of a transport connection.

let bootstrap = MCPTransportBootstrap()

A bootstrap connects in a with- style function call like so:

bootstrap.withClient { send, messages in
  try await send(SomeToolCall())

  for try await message in messages {
    // Handle incoming traffic
  }
}

Returning out of the withClient scope closes and cleans up the connection.
This pattern can be wrapped in more domain specific use cases like a request/response style flow in the higher level APIs.

Lenguaje dominante
Swift
Estrellas
1.6k
Forks
270
Merge medio
2 d 7 h
PR fusionados (30 d)
15

Preparar el entorno

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/swift-sdk

Todos los issues de modelcontextprotocol/swift-sdk

Issues similares

Más issues de Swift

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.