[v2] serveStdio falls back to legacy when a notification without _meta arrives after server/discover

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

維護者通常 1 天內回覆

@ar70n 已經在處理了。

開始於 2026年11月25日。

  • #3237 來自 @ar70n —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
30/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
typescript

研究方向

Read serveStdio.ts and inspect the probe phase's legacy and modern branches, especially how notifications without _meta affect protocol selection. Start by running the supplied stdio reproduction, then review the linked pull request #3237, which already addresses this issue. Done means the notification leaves the selected protocol era unchanged and the subsequent tools/list and server/discover responses remain on 2026-07-28.

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

描述

v2
What happened?

Hi! I ran into this while testing a client against server-everything over stdio.

If a client sends server/discover and then a notification that has no _meta, serveStdio takes it as a legacy client falling back and pins the connection to 2025-11-25. From then on everything is served as legacy: a second server/discover gets Method not found, and tools/list comes back without resultType.

The realistic way to hit this is a client cancelling its discover request after a timeout (e.g. while npx is still starting the server). The cancellation example in the spec doesn't include _meta either.

With the repro below I get:

{"id":1,"resultType":"complete","error":null}
{"id":2,"resultType":null,"error":null}
{"id":3,"resultType":null,"error":"Method not found"}

If you remove the cancel line, 2 and 3 both come back with "resultType":"complete".

What did you expect?

The notification shouldn't change the era, so 2 and 3 should still be answered as 2026-07-28.

Looking at serveStdio.ts, while in the probe phase the case 'legacy' branch falls back for any message without a protocol version, notifications included. The modern branch already lets enveloped notifications through during the probe without pinning anything, so I think the no-_meta case just needs the same check. I have a fix with a test, happy to open a PR.

Code to reproduce
META='"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{},"io.modelcontextprotocol/clientInfo":{"name":"repro","version":"0"}}'

{
  echo "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"server/discover\",\"params\":{$META}}"
  sleep 2
  echo '{"jsonrpc":"2.0","method":"notifications/cancelled","params":{"requestId":1}}'
  sleep 1
  echo "{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"tools/list\",\"params\":{$META}}"
  echo "{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"server/discover\",\"params\":{$META}}"
  sleep 2
} | npx -y @modelcontextprotocol/[email protected] stdio 2>/dev/null | jq -c '{id, resultType: .result.resultType, error: .error.message}'
SDK version

@modelcontextprotocol/server 2.4.0 (through server-everything 2.3.1). The code is the same on main.

Area

Server

主要語言
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 摘要。