[Server] Decode an HTTP request body once instead of per pipeline stage

未關閉
#733 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
48/100
Issue 類型
重構
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
php

研究方向

Start with InboundClassifier::classify(), Protocol and StatelessProtocol, MessageFactory::create(), and Json::objectsToArrays() to trace how the request body is decoded across the StreamableHttpTransport pipeline. Check the HTTP transport tests and add coverage showing that one decoded message is shared through classification and handling. Update docs/run/http.md to explain that maxBodyBytes limits encoded bytes and that decoded memory use depends on body shape; the issue leaves whether to lower the default unresolved.

由索引模型根據 Issue 內容生成。

描述

enhancement P3

Currently a POST body is decoded several times before it reaches a handler: InboundClassifier::classify(), then Protocol or StatelessProtocol, then MessageFactory::create() and Json::objectsToArrays(). Not all copies are alive at the same time, but peak memory ends up at about twice a single decode, and the CPU cost is paid on every pass - also for requests that are rejected right after.

Measured on main with a tools/call for an unknown tool through StreamableHttpTransport:

body (600 KB) one json_decode() full pipeline
list of [0] 35.6 MB 74.4 MB
list of {"a":0} 31.9 MB 68.4 MB
list of {} 4.0 MB 33.4 MB
list of ints 8.0 MB 19.1 MB

Two things to do:

  • decode once at the edge and pass the decoded message down, so classification, the protocol and the MessageFactory share it
  • document in docs/run/http.md that maxBodyBytes bounds bytes, not decoded size - adversarial shapes need ~60x the body in memory, so the cap should be sized against memory_limit. Maybe also worth lowering the 4 MiB default.

Reported by @kanokwut.

主要語言
PHP
星號
1.7k
分支
206
平均合併
1 天 17 小時
30 天內合併 PR
102

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

modelcontextprotocol/php-sdk 的其他 Issue

查看 modelcontextprotocol/php-sdk 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。