2026-07-28 SSE responses share one header list, so in-place middleware appends leak across responses
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
- #3704 của @guptaishaan — đã đóng, không merge
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 68/100
Hướng nghiên cứu
Bắt đầu từ handle_modern_request, nơi phản hồi SSE được gửi bằng danh sách cấp module _SSE_HEADERS, và kiểm tra xem việc sao chép một bản cho mỗi phản hồi có khắc phục được rò rỉ do nối thêm tại chỗ hay không. Trước khi viết bản sửa, hãy xem PR #3704 đã đóng và chưa được hợp nhất để hiểu vì sao nó không được chấp nhận. Hoàn thành khi một kiểm thử hồi quy trong tests/server/test_streamable_http_modern.py thất bại trên nhánh main hiện tại và đạt khi mỗi phản hồi SSE có danh sách header riêng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Initial Checks
- I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1)
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Release line
2.x (current stable)
Description
On the 2026-07-28 HTTP entry, handle_modern_request starts every SSE response with the module-level _SSE_HEADERS list itself:
await send({"type": "http.response.start", "status": _OK_STATUS, "headers": _SSE_HEADERS})
ASGI middleware that adds a header with message["headers"].append(...) therefore appends to the SDK's shared list. The header stays there for the life of the process, so every later SSE response carries one more copy, along with the values set for earlier requests. JSON responses aren't affected, because they build their own header list.
We hit this in production with an observability middleware that appended an x-correlation-id. After about 250 SSE responses in one process, our edge proxy's HTTP client rejected the responses as malformed. Only calls that commit to SSE (a notification, or more than 15 s without one) take this path, so fast calls and most test suites never touch it, and a restart hid it for a while.
The middleware shouldn't mutate a list it doesn't own; Starlette's MutableHeaders(scope=message) copies for exactly this reason. Passing list(_SSE_HEADERS) would keep one middleware's mistake from turning into process-wide header growth and cross-request header leakage.
Expected: each SSE response gets its own header list.
Example Code
import asyncio
import httpx
from mcp.server.mcpserver import Context, MCPServer
from mcp.server.transport_security import TransportSecuritySettings
mcp = MCPServer("repro")
@mcp.tool()
async def slow(ctx: Context) -> str:
await ctx.report_progress(1, 2) # any notification commits the response to SSE
return "done"
inner = mcp.streamable_http_app(
transport_security=TransportSecuritySettings(enable_dns_rebinding_protection=False)
)
async def app(scope, receive, send): # middleware that appends in place
async def send2(msg):
if msg["type"] == "http.response.start":
msg["headers"].append((b"x-correlation-id", b"abc"))
await send(msg)
await inner(scope, receive, send2)
def body(i):
return {"jsonrpc": "2.0", "id": i, "method": "tools/call",
"params": {"name": "slow", "arguments": {}, "_meta": {
"progressToken": i,
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": {"name": "r", "version": "0"},
"io.modelcontextprotocol/clientCapabilities": {}}}}
async def main():
async with inner.router.lifespan_context(inner):
async with httpx.AsyncClient(transport=httpx.ASGITransport(app=app), base_url="http://localhost") as c:
for i in range(1, 6):
r = await c.post("/mcp", json=body(i), headers={
"accept": "application/json, text/event-stream",
"mcp-protocol-version": "2026-07-28",
"mcp-method": "tools/call", "mcp-name": "slow"})
print(i, len(r.headers.get_list("x-correlation-id")))
asyncio.run(main())
Output: 1 1, 2 2, 3 3, 4 4, 5 5.
I have a fix ready (list(_SSE_HEADERS) plus a regression test in tests/server/test_streamable_http_modern.py that fails before and passes after) and would be glad to open the PR if you assign this to me. Open PR #3192 carries the same line, in case that's the better place for it.
AI disclosure: I used Claude Code to find the line, write the repro, and draft this issue. I hit the bug in production and have checked the repro and the fix myself.
Python & MCP Python SDK
Python 3.13, mcp 2.3.0 (also present on main at 754254c)
- Ngôn ngữ chính
- Python
- Star
- 24.5k
- Fork
- 4k
- Merge trung bình
- 18 giờ 3 phút
- Pull request đã merge (30 ngày)
- 39
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của modelcontextprotocol/python-sdk
-
bug v1 v2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
modelcontextprotocol/python-sdk#3698 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Streamable HTTP: Content-Type handling is order dependent and accepts invalid valuesCó thể đã có người làm @jayzuccarelli đã nhận 3 ngày trước. Đang mởbug v1 v2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
modelcontextprotocol/python-sdk#3691 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Skills: URI traversal validation skips percent-encoded dot-segmentsCó thể đã có người làm @Varshith-Kali đã nhận 2 ngày trước. Đang mởbug v2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
modelcontextprotocol/python-sdk#3685 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Type annotation gaps and unhandled FileNotFoundError in src/mcp/cli/cli.pyCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
modelcontextprotocol/python-sdk#3673 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Streamable HTTP server rejects a mixed-case Content-Type with 415Có thể đã có người làm @CRYPTONIKAV đã nhận 5 ngày trước. Đang mởbug v1 v2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
modelcontextprotocol/python-sdk#3670 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của modelcontextprotocol/python-sdk
Issue tương tự
-
area:core-platform effort:S priority:P3 status:in-review type:test
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 80/100
randomparity/kdive#3246 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Requantification library converts m/z to mass with the hydrogen-atom mass instead of the proton massĐang mởbug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
nf-core/metaboigniter#130 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
common-workflow-language/cwl-utils#477 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add dependabotĐang mởfeat
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 72/100
open-nudge/opentemplate#204 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
github-stale-ci-pr-closer: KV state is double-wrapped, never persists, and hits the depth-32 limitCó thể đã có người làm @VascoSch92 đã nhận hôm nay. Đang mởpriority:medium ready-for-dev
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
OpenHands/extensions#781 ·
Maintainer thường phản hồi trong vòng 1 ngày