[v2] Expose per-request stream end (onRequestStreamEnd) in RequestOptions for custom long-lived requests

未關閉
#3,060 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
68/100
Issue 類型
功能
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
typescript
領域
api, backend

研究方向

Start by reading RequestOptions in packages/core-internal/src/shared/protocol.ts and the transport.send(...) call in _requestWithSchemaViaCodec; compare how Client.listen() forwards onRequestStreamEnd. Check the existing tests for protocol requests and stream transports, then add coverage showing a request can detect its response stream ending before a JSON-RPC response. Done means the callback or chosen rejection behavior is exposed through request options and tested, while transports without per-request streams continue to work.

由索引模型根據 Issue 內容生成。

描述

v1 v2
Summary

Protocol.request() gives callers no way to learn that the per-request response stream ended. The client transport already supports this: TransportSendOptions.onRequestStreamEnd, which StreamableHTTPClientTransport fires when a request's SSE response ends. But only Client.listen() uses it (it calls transport.send() directly). RequestOptions has no equivalent, and _requestWithSchemaViaCodec passes requestSignal to transport.send() but not onRequestStreamEnd.

Why it matters

Extensions that define long-lived streaming requests can't detect a dead stream promptly. One example is events/stream from the Events extension (SEP-3415, see #2945). If the server restarts mid-stream, the POST's SSE body ends without a JSON-RPC response. The pending request then waits for its timeout, or for an application-level heartbeat watchdog. In @mastra/mcp we detect this through a 30s heartbeat window, so it takes up to 60s. subscriptions/listen gets immediate detection because it uses the transport option directly.

This is the request-level counterpart of #2739, which covers non-streaming requests left pending when their SSE response ends.

Proposal

Add an option to RequestOptions, for example onRequestStreamEnd?: () => void, and forward it to transport.send() the same way requestSignal is forwarded. Alternatively, reject the pending request with a distinct error when its stream ends before a response arrives. Transports with no per-request stream (stdio, InMemory) would keep ignoring it, as they do today.

Versions

We hit this on @modelcontextprotocol/[email protected]. It's still present on main (c05225a6): see RequestOptions in packages/core-internal/src/shared/protocol.ts and the transport.send(...) call in _requestWithSchemaViaCodec.

主要語言
TypeScript
星號
13.8k
分支
2.5k
平均合併
6 天 23 小時
30 天內合併 PR
2

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

modelcontextprotocol/typescript-sdk 的其他 Issue

查看 modelcontextprotocol/typescript-sdk 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。