[Server][Streamable HTTP] Concurrent SSE streams on one session can consume each other's client responses
维护者通常 1 天内回复
已经有一个关联 PR 被合并了。
- #556 来自 @mglaman —— 已合并
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- php
调研方向
Start with StreamableHttpTransport::createStreamedResponse() and the getPendingRequests() and checkForResponse() calls described in the issue; trace how yielded request IDs relate to each stream's fiber. Check linked pull request #556, which is already open. Done means concurrent streams on one session cannot consume or time out each other's responses.
由索引模型根据 Issue 内容生成。
描述
Summary
On Streamable HTTP (handshake era, SSE), two tool calls on one session that both send a server-to-client request, such as elicitation/create, can each receive the other's answer.
Cause
Protocol keeps pending server-to-client requests in one session-wide list, _mcp.pending_requests. The SSE loop in StreamableHttpTransport::createStreamedResponse() walks that whole list, not only the requests its own fiber sent:
$pendingRequests = $this->getPendingRequests($this->sessionId);
// ...
foreach ($pendingRequests as $pending) {
$response = $this->checkForResponse($pending['request_id'], $this->sessionId);
if (null !== $response) {
$yielded = $this->sessionFiber->resume($response);
// ...
With tool calls A and B open on one session, each waiting in ClientGateway::elicit():
- The client answers B's elicitation.
- A's loop polls first, finds B's answer, consumes it, and resumes A's fiber with it. A's tool continues with B's answer.
- B's answer is gone from the session. B's tool waits until its 120-second timeout.
The timeout branch has the same problem: A's loop can resume A's fiber with a timeout error for B's request ID.
I found this by reading the source on main (a5ed85f) and 0.8.1. I have not reproduced it end to end. Running two streams on one session at the same time needs a server that doesn't serialize requests per session.
Suggested fix
Record which stream sent each pending request, and have each loop check only its own. For example, track the request IDs the fiber yielded in the transport instance, and filter getPendingRequests() by them.
Context
In Drupal's mcp_server we lock the session for the length of a stream. That lock made a second elicitation wait, which hid this bug. We're changing the lock to cover each session write instead of the whole stream, so elicitation answers don't wait on the lease (mcp_server!88). That makes this race reachable.
- 主要语言
- PHP
- 星标
- 1.6k
- 派生
- 177
- 平均合并
- 2 天 16 小时
- 30 天内合并 PR
- 36
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/php-sdk 的其他 Issue
-
[Server] Handler type uses bare Closure, hard to decorate RegistryInterface under strict PHPStan未关闭Server
难度 1/5 1 小时以内 新手友好度 78/100
modelcontextprotocol/php-sdk#468 · 2 条评论 ·
维护者通常 1 天内回复
-
Builder::build() silently skips configured file-based discovery when symfony/finder is missing — should fail loudly可能已有人在做 @ousamabenyounes 于 54 天前认领。 未关闭needs confirmation needs maintainer action Server
难度 2/5 1-3 小时 新手友好度 68/100
modelcontextprotocol/php-sdk#398 · 1 个 reaction ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 68/100
modelcontextprotocol/php-sdk#370 ·
维护者通常 1 天内回复
-
bug
难度 3/5 半天 新手友好度 60/100
modelcontextprotocol/php-sdk#586 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 18/100
modelcontextprotocol/php-sdk#583 ·
维护者通常 1 天内回复
查看 modelcontextprotocol/php-sdk 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 60/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
scanaislop/aislop#476 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
components-web-app/api-components-bundle#403 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
mollie/PrestaShop#1566 ·
维护者通常 1 天内回复