`list_mcp_tools` hangs when MCP endpoint returns plain-text error as `text/event-stream`
維護者通常 1 天內回覆
@cassiofariasmachado 已經在處理了。
開始於 2026年9月21日。
評估
這個 Issue 還沒有評估資料。
描述
Describe the Bug
Problem
When an AGW MCP endpoint returns 200 text/event-stream with a plain-text body (e.g. Jwt issuer is not configured) instead of a valid SSE data: event, await session.list_tools()
in list_server_tools() blocks indefinitely.
The MCP SSE parser discards lines without a data: prefix — silently, with no error. The ClientSession then waits forever for a JSON-RPC response that will never arrive. The httpx
timeout does not protect against this because the HTTP response itself completes successfully in ~1s.
Since all fragments run concurrently via asyncio.gather, one hanging fragment blocks the entire list_mcp_tools() call until the outer app-level timeout fires (up to 180s).
Proposed fixes
1. Per-fragment timeout (defensive minimum)
result = await asyncio.wait_for(session.list_tools(), timeout=30.0)
2. Race against stream closure (detects the problem immediately)
done, _ = await asyncio.wait(
[session.list_tools(), stream_closed_event],
return_when=asyncio.FIRST_COMPLETED
)
# if stream closed before list_tools() responded → raise immediately
3. Validate SSE body before entering ClientSession
first_chunk = await response.aread(64)
if not first_chunk.startswith((b"data:", b"event:")):
raise McpError(f"Non-SSE response: {first_chunk.decode(errors='replace')}")
Context
- Reproduced on sap.btpn8n:apiResource:ManagedN8nMcpServer:v1, AGW EU12
- The upstream fix (return 4xx or a proper SSE error event) is tracked separately
- This SDK fix is defensive and needed regardless of the upstream fix
### Steps to Reproduce
### Reproduction
Send `initialize` followed by `tools/list` to any MCP endpoint that returns a plain-text error:
```bash
# initialize — works, returns valid SSE
curl -X POST "<mcp-endpoint>" \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}'
# tools/list — returns 200 but body is plain text, not an SSE data: event
curl -X POST "<mcp-endpoint>" \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'
Actual tools/list response:
HTTP/2 200
content-type: text/event-stream
<plain text error message>
Expected tools/list response:
HTTP/2 200
content-type: text/event-stream
event: message
data: {"jsonrpc":"2.0","id":1,"result":{"tools":[...]}}
The body lacks the data: prefix required by the SSE spec. The MCP SSE parser silently discards it, leaving ClientSession blocked on a queue that will never receive a message.
Expected Behavior
Exception must be thrown, but it should not wait indefinitely for a response.
Screenshots
No response
Used Versions
- Python version via
python --version: ... - SAP Cloud SDK for Python version: ...
- Framework version (if applicable, e.g., Flask, FastAPI): ...
Installed packages via pip list or uv pip list
Package list here
Code Examples
# Your code here
Stack Trace
No response
Log File
Log file
...Affected Development Phase
Getting Started
Impact
No Impact
Timeline
No response
- 主要語言
- Python
- 星號
- 29
- 分支
- 45
- 平均合併
- 2 天 4 小時
- 30 天內合併 PR
- 51
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
SAP/cloud-sdk-python 的其他 Issue
-
難度 4/5 3-5 天 新手友好度 15/100
SAP/cloud-sdk-python#474 ·
維護者通常 1 天內回覆
-
Relax opentelemetry-api cap (~=1.44.0) to allow 1.45.2 (fixes CVE-2026-114603 / GHSA-xcq7-p3pf-p88h)未關閉
難度 3/5 1-2 天 新手友好度 64/100
SAP/cloud-sdk-python#472 ·
維護者通常 1 天內回覆
-
bug
難度 4/5 3-5 天 新手友好度 25/100
SAP/cloud-sdk-python#456 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 65/100
SAP/cloud-sdk-python#452 ·
維護者通常 1 天內回覆
-
How/Whether langgraph-checkpoint-hana would be supported by sap-cloud-sdk?可能已有人在做 @gpretto 於 3 天前認領。 未關閉question
難度 5/5 一週以上 新手友好度 15/100
SAP/cloud-sdk-python#427 · 2 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
查看 SAP/cloud-sdk-python 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 66/100
deepchem/deepchem#5289 · 1 則留言 ·
維護者通常 2 天內回覆
-
難度 1/5 1 小時以內 新手友好度 75/100
-
難度 2/5 1-3 小時 新手友好度 60/100
UKGovernmentBEIS/inspect_evals#2892 · 1 則留言 ·
維護者通常 1 天內回覆
-
Versioning docs: say that no output from the 0.46 warning check means nothing is affected可能已有人在做 @grelinfo 今天認領。 未關閉documentation priority:low size:S
難度 1/5 1 小時以內 新手友好度 72/100
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 88/100
alphacrack/readme2demo#293 ·