stdio dual-era server refuses initialize after a failed server/discover probe (era latched by the first request)
維護者通常 1 天內回覆
@techaurah 已經在處理了。
開始於 2026年11月13日。
評估
研究方向
Start with serve_dual_era_loop and _replay_from_opening_request in src/mcp/server/runner.py, which set the era from the first request, then check where _serve_modern_stream raises UNSUPPORTED_PROTOCOL_VERSION for a later initialize. Run the two-message drive.py repro to confirm the -32022 refusal after a rejected server/discover. The issue asks a design question first (whether a rejected request should latch the era), so settle that with maintainers before changing code; done means the fallback initialize succeeds on the same process.
由索引模型根據 Issue 內容生成。
描述
Summary
On stdio, serve_dual_era_loop fixes the connection's protocol era from the
first request it reads. If that first request is a 2026-07-28 server/discover
probe that the server rejects, the connection is still latched to the modern
era, and the client's spec-described fallback to initialize on the same process
is refused with -32022 "connection is serving the 2026-07-28 protocol; the initialize handshake is not accepted".
The same server answers initialize normally when it is the first request, so it
does support 2025-11-25. It just can't be reached after a failed probe.
Spec (2026-07-28)
- stdio, Backward Compatibility: a dual-version client SHOULD probe with
server/discoverfirst. If "the server returns any other error [than a
recognized modern error], or does not respond within a reasonable timeout: the
server is legacy. Fall back to theinitializehandshake." The fallback MUST
NOT be keyed to one specific error code. - Versioning: "An
initializerequest selects legacy semantics, scoped to the
stdio process", and "A dual-era server MAY serve both eras concurrently on the
same endpoint or process." - Base protocol, Statelessness: "Servers MUST NOT rely on prior requests over
the same connection to establish context (e.g., capabilities, protocol
version, client identity)."
The spec doesn't say whether the fallback reuses the process or starts a new
one. But a client that follows the stdio text literally sends initialize next
on the same process, and a rejected request arguably shouldn't establish the
connection's version.
Reproduction (mcp 2.3.0, Python 3.12)
server.py:
from mcp.server import MCPServer
app = MCPServer("era-latch-repro")
@app.tool()
def ping() -> str:
return "pong"
if __name__ == "__main__":
app.run() # stdio
drive.py (one stdio process: a probe the server rejects with a non-modern
error, then the fallback initialize):
import json, subprocess, sys
META = "io.modelcontextprotocol/protocolVersion"
msgs = [
# Envelope missing clientCapabilities -> the SDK answers -32602 (a non-modern error)
{"jsonrpc": "2.0", "id": 1, "method": "server/discover",
"params": {"_meta": {META: "2026-07-28"}}},
{"jsonrpc": "2.0", "id": 2, "method": "initialize",
"params": {"protocolVersion": "2025-11-25", "capabilities": {},
"clientInfo": {"name": "repro", "version": "0"}}},
]
p = subprocess.Popen([sys.executable, "server.py"], stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True)
for m in msgs:
p.stdin.write(json.dumps(m) + "\n"); p.stdin.flush()
print("<<", p.stdout.readline().strip())
p.stdin.close(); p.wait(timeout=5)
Output:
<< {"jsonrpc":"2.0","id":1,"error":{"code":-32602,"message":"params._meta is missing the required envelope key(s): io.modelcontextprotocol/clientCapabilities"}}
<< {"jsonrpc":"2.0","id":2,"error":{"code":-32022,"message":"connection is serving the 2026-07-28 protocol; the initialize handshake is not accepted","data":{"supported":["2026-07-28"],"requested":"2025-11-25"}}}
Control: sending only the initialize (no probe) on a fresh process returns a
normal result with "protocolVersion":"2025-11-25".
A legacy-only server built with the SDK (one whose request handling refuses
modern versions before initialize) hits the same latch: the refused probe fixes
the era, and the fallback initialize is rejected.
Expected
A first request that the server rejects shouldn't decide the era. Two options:
latch only on a request that succeeds, or still accept initialize while no
modern request has been answered successfully. Either would let the stdio
fallback work on the same process.
Secondary observation
The -32022 data lists "supported": ["2026-07-28"] (both on the refused
initialize and on a well-formed probe with an unknown version), although the
same server answers initialize at 2025-11-25 when that comes first. The
spec's example of this error lists both eras (["2026-07-28", "2025-11-25"]).
Code
src/mcp/server/runner.py: serve_dual_era_loop / _replay_from_opening_request
decide opens_modern from the opening request alone, and _serve_modern_stream
raises UNSUPPORTED_PROTOCOL_VERSION for any later initialize. The docstring
says this is intentional ("A later claim from the other era is refused"), so this
may be a design question rather than a bug. Raising it because of the spec's
stdio fallback text.
- 主要語言
- Python
- 星號
- 25k
- 分支
- 4.2k
- 平均合併
- 10 分鐘
- 30 天內合併 PR
- 1
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
modelcontextprotocol/python-sdk 的其他 Issue
-
v2
難度 1/5 1 小時以內 新手友好度 86/100
modelcontextprotocol/python-sdk#3978 · 2 則留言 ·
維護者通常 1 天內回覆
-
Client serves cached tools after its context exits with an exception可能已有人在做 @jonxsong 於 1 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 65/100
modelcontextprotocol/python-sdk#3968 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 85/100
modelcontextprotocol/python-sdk#3957 ·
維護者通常 1 天內回覆
-
v2
難度 1/5 1 小時以內 新手友好度 91/100
modelcontextprotocol/python-sdk#3934 · 2 則留言 ·
維護者通常 1 天內回覆
-
bug v1
難度 2/5 1-3 小時 新手友好度 79/100
modelcontextprotocol/python-sdk#3929 · 2 則留言 ·
維護者通常 1 天內回覆
查看 modelcontextprotocol/python-sdk 的全部 Issue
相似的 Issue
-
auto-reported bug
難度 2/5 1-3 小時 新手友好度 62/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
-
backend bug
難度 2/5 1-3 小時 新手友好度 86/100
nolte/kamerplanter#3193 ·
維護者通常 1 天內回覆
-
soup prune-prompt exits 1 after writing its output on a file over 100,000 rows, and reports a capped row count otherwise可能已有人在做 @abdulwaarith0 今天認領。 未關閉needs-triage
難度 2/5 1-3 小時 新手友好度 84/100
MakazhanAlpamys/Soup#3690 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆