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

未关闭
#126 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
30/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
swift

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Swift
星标
1.6k
派生
270
平均合并
2 天 7 小时
30 天内合并 PR
15

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

modelcontextprotocol/swift-sdk 的其他 Issue

查看 modelcontextprotocol/swift-sdk 的全部 Issue

相似的 Issue

更多 Swift Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。