[v2] Streamable HTTP client never re-initializes after server 404 "session not found" — needs maintainer call on era architecture

Đang mở
#3,056 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
backend-api-design

Hướng nghiên cứu

Read the v2 client’s POST _send() error handling and the connect paths _connectPlainLegacy, _legacyHandshake, and _connectNegotiated; the issue gives their names and relevant dist/index.mjs locations. Check the expected-failure e2e scenario client-transport:http:session-404-reinitialize and the companion http:404-surfaces test. Done means agreeing on the recovery handshake strategy, then covering one bounded 404 recovery while retaining the unrecoverable-case coverage.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

v1 v2

What happened?

Once a stateful Streamable HTTP server drops a session (restart, eviction, keepalive timeout without a server→client SSE stream), every subsequent client POST with the stale Mcp-Session-Id returns HTTP 404 "session not found". The v2 client never recovers: the same error is thrown verbatim on every tools/call for the rest of the process lifetime.

Reproduced on a 24h-long-lived agent harness (DeepSeek Harness) talking to a stateful Rancher MCP server nightly-restarted by cert rotation: first call succeeds, all calls from the next minute onward 404. No transport or SDK error handling re-tries a handshake. A full transport close/reconnect (or process restart) is the only recovery.

What did you expect?

MCP spec 2025-06-18, Session Management §5 (normative MUST):

When a client receives HTTP 404 in response to a request containing an Mcp-Session-Id, it MUST start a new session by sending a new InitializeRequest without a session ID attached.

The client should treat a 404 carrying a session id as an expired-session signal: clear the cached id, re-run initialize session-less, and replay the failed request once (bounded, not a loop).

Code / verified in dist

On @modelcontextprotocol/client 2.0.0 (dist/index.mjs):

  • _sessionId is assigned only from a successful initialize response (~L5332); nothing else mutates it.
  • The if (!response.ok) branch in the POST _send() path special-cases only 401 (auth seam, ~L4841). A 404 falls straight through to throw new Error(\Error POSTing to endpoint (HTTP 404): …`)`.
  • No "clear session id on 404 / re-initialize / retry once" path exists anywhere in the package.

The e2e scenario client-transport:http:session-404-reinitialize is still listed as an expected failure; the companion scenario http:404-surfaces covers the unrecoverable case (no recovery hook installed) and should stay.

Prior art (both authored but never merged)

  • #2150 implemented exactly this on the pre-era codebase. The author closed it himself: the connect path has since been rebuilt around era negotiation (_connectPlainLegacy / _legacyHandshake / _connectNegotiated), and he asked for one design call from maintainers before redoing it — "when a session expires mid-connection, should the client re-probe with server/discover (full fresh negotiation) or re-run the handshake pinned to the era it originally negotiated?" He is happy to redo the PR once that direction is settled.
  • #2466 aligned session-id lifecycle with the spec more broadly; author withdrew it as "grew far past its purpose" and deferred the recovery part to a minimal follow-up PR that never materialized.

A search on this tracker confirms no open PR currently brings 404-reinitialize to v2.

Why I am opening an issue instead of submitting the PR myself

Per CONTRIBUTING.md, this touches the connect architecture (a "significant change"), and the open design question above makes the "what/how" unsettled as the guide asks of PR authors. First maintainer signal we need: re-probe via server/discover, or re-run pinned-era handshake? Once that is answered, #2150's author and I are both willing to produce the PR.

SDK version: @modelcontextprotocol/client 2.0.0 (consumer: DeepSeek Harness dsh-mcp-client 0.2.0-rc.2)
Area: Client / Transports

Ngôn ngữ chính
TypeScript
Star
13.8k
Fork
2.5k
Merge trung bình
6 ngày 23 giờ
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của modelcontextprotocol/typescript-sdk

Tất cả issue của modelcontextprotocol/typescript-sdk

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.