modelcontextprotocol / modelcontextprotocol/python-sdk

HTTP transport swallows non-2xx status codes causing client to hang

未关闭
#2,110 7 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug P1 v2
主要语言
Python
星标
24.3k
派生
4k
平均合并
1 天 1 小时
30 天内合并 PR
31

描述

Summary

When an MCP server returns non-2xx HTTP status codes (401/403/404/5xx), the Streamable HTTP and SSE transports do not reliably propagate the error to the caller. In the Streamable HTTP transport, post_writer catches exceptions and logs them, but the caller blocks indefinitely waiting for a response on the read stream. HTTP 404 responses are also converted to JSONRPCError(code=32600), losing the original HTTP status information.

Expected Behavior

  • Non-2xx HTTP responses should be surfaced as exceptions to the caller, not silently logged
  • The original HTTP status code should be preserved and accessible
  • Auth-related errors (401/403) should be distinguishable from other failures

Current Behavior

  • post_writer in Streamable HTTP transport catches and logs errors without forwarding them through the read stream
  • Callers hang indefinitely waiting for a response
  • HTTP 404 is converted to JSONRPCError(code=32600), destroying HTTP-level context

Affected Code

  • src/mcp/client/streamable_http.py (post_writer)
  • src/mcp/client/sse.py (sse_reader)

Related

  • #1742 — broader typed error classes design

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先跟踪 src/mcp/client/streamable_http.py 中的错误处理,尤其是 post_writer,以及 src/mcp/client/sse.py 中的错误处理,尤其是 sse_reader。查看相关 issue #1742,了解类型化错误设计。当非 2xx 响应以异常形式传递给调用方、保留其 HTTP 状态、区分 401/403,并且不再让调用方无限期等待时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
api, backend
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。