[v2] Standalone GET stream is never primed, so notifications sent across closeStandaloneSSEStream() are lost
維護者通常 1 天內回覆
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 35/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 停滯
- 技術堆疊
- typescript
研究方向
Start with handleGetRequest(), replayEvents(), and writePrimingEvent() in the transport code; compare the standalone GET flow with the POST flow. Check the TypeScript and Python GET behavior and the existing transport tests, including reconnect replay. Done means fresh and resumed GET streams prime correctly, concurrent sends preserve event order, and stored priming events are skipped during replay.
由索引模型根據 Issue 內容生成。
描述
What happened?
POST SSE streams open with a priming event (id, plus retry when retryInterval is set). The standalone GET stream doesn't, so until the server sends something on it the client has no event id to resume from. If closeStandaloneSSEStream() is called in that window, StreamableHTTPClientTransport reconnects on schedule but without Last-Event-ID, and anything sent while it was disconnected sits in the event store and is never delivered.
SDK client against an in-process server (retryInterval: 300), one notification sent right after the close and one after the reconnect:
[19ms] client GET, Last-Event-ID=(none)
[221ms] server closeStandaloneSSEStream()
[528ms] client GET, Last-Event-ID=(none)
received: [ 'after-reconnect' ] <- 'during-gap' was stored as e2, never replayed
writePrimingEvent() is only called from the POST path; handleGetRequest() and replayEvents() never prime. v1.x (1.32.2) has the same code in webStandardStreamableHttp.ts.
What did you expect?
The GET stream primed on open and on resume, same as POST, so the client reconnects with Last-Event-ID and gets what it missed.
The 2025-11-25 transports spec, for GET streams: "If the server closes the connection without terminating the stream, it SHOULD follow the same polling behavior as described for POST requests: sending a retry field and allowing the client to reconnect." The POST rules it points to only allow closing after an event ID has been sent.
Two things a fix has to handle: the priming event has to be stored before the stream is registered, otherwise a concurrent send() can land ahead of it, and replay should skip stored priming events because _GET_stream is reused across connections. The Python SDK primes resumed GETs but not fresh ones, so it has the same gap on first connect. I have this on a branch with tests and can open a PR if the approach works for you.
Related: #2499
Code to reproduce
// Shows the missing priming event. Output:
// POST: "id: 30847839-..._0\nretry: 1000\ndata: \n\n"
// GET: ""
import { McpServer, WebStandardStreamableHTTPServerTransport } from '@modelcontextprotocol/server';
import type { EventStore } from '@modelcontextprotocol/server';
const events = new Map<string, unknown>();
const eventStore: EventStore = {
async storeEvent(streamId, message) {
const id = `${streamId}_${events.size}`;
events.set(id, message);
return id;
},
async replayEventsAfter() {
return '';
}
};
const transport = new WebStandardStreamableHTTPServerTransport({
sessionIdGenerator: () => crypto.randomUUID(),
eventStore,
retryInterval: 1000
});
await new McpServer({ name: 'repro', version: '0' }).connect(transport);
const init = await transport.handleRequest(
new Request('http://localhost/mcp', {
method: 'POST',
headers: { 'content-type': 'application/json', accept: 'application/json, text/event-stream' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'initialize',
params: { protocolVersion: '2025-11-25', capabilities: {}, clientInfo: { name: 'c', version: '0' } }
})
})
);
const sessionId = init.headers.get('mcp-session-id')!;
const initReader = init.body!.getReader();
console.log('POST:', JSON.stringify(new TextDecoder().decode((await initReader.read()).value)));
await initReader.cancel();
const get = await transport.handleRequest(
new Request('http://localhost/mcp', {
headers: { accept: 'text/event-stream', 'mcp-session-id': sessionId, 'mcp-protocol-version': '2025-11-25' }
})
);
setTimeout(() => transport.closeStandaloneSSEStream(), 100);
console.log('GET: ', JSON.stringify(await get.text()));
await transport.close();
SDK version
@modelcontextprotocol/server 2.4.0 (main @ 5ee54ee3)
Area
Transports
- 主要語言
- TypeScript
- 星號
- 13.8k
- 分支
- 2.5k
- 平均合併
- 6 天 23 小時
- 30 天內合併 PR
- 2
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
modelcontextprotocol/typescript-sdk 的其他 Issue
-
v2
難度 1/5 1 小時以內 新手友好度 72/100
modelcontextprotocol/typescript-sdk#3270 · 1 則留言 ·
維護者通常 1 天內回覆
-
`callTool` with `allowInputRequired: true` throws on an `input_required` result when the tool declares an `outputSchema`可能已有人在做 @mgoldsborough 於 6 天前認領。 未關閉v2
難度 2/5 1-3 小時 新手友好度 78/100
modelcontextprotocol/typescript-sdk#3249 ·
維護者通常 1 天內回覆
-
v2
難度 2/5 1-3 小時 新手友好度 68/100
modelcontextprotocol/typescript-sdk#3243 · 3 則留言 ·
維護者通常 1 天內回覆
-
TypeScript client accepts an unknown `resultType` in the first `server/discover` reply可能已有人在做 @Tidehyc 於 8 天前認領。 未關閉v2
難度 2/5 1-3 小時 新手友好度 72/100
modelcontextprotocol/typescript-sdk#3235 · 3 則留言 ·
維護者通常 1 天內回覆
-
UriTemplate.match() throws a TypeError on an empty expression it accepts可能已有人在做 @yunusemrejs 於 12 天前認領。 未關閉v1 v2
難度 2/5 1-3 小時 新手友好度 80/100
modelcontextprotocol/typescript-sdk#3221 · 3 則留言 ·
維護者通常 1 天內回覆
查看 modelcontextprotocol/typescript-sdk 的全部 Issue
相似的 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 72/100
-
難度 2/5 1-3 小時 新手友好度 68/100
Vessel9817/onion-site-template#512 ·
維護者通常 1 天內回覆
-
nightly-tests
難度 2/5 1-3 小時 新手友好度 68/100
BlackBeltTechnology/pi-agent-dashboard#1256 ·
維護者通常 1 天內回覆
-
approved
難度 2/5 1-3 小時 新手友好度 85/100
fritzprix/libr-agent#3266 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 88/100
better-auth/better-auth#13101 · 1 則留言 · 1 個 reaction ·
維護者通常 1 天內回覆