[v2] Every inbound message is re-classified with up to four full zod parses after the transport already parsed it
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 56/100
- Issue 類型
- 重構
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- typescript
- 領域
- backend, performance
研究方向
Start by reading packages/server/src/server/streamableHttp.ts:838-839, then trace message handling through packages/core-internal/src/shared/protocol.ts:838-845 and protocol.ts:1887, plus the guards in types/guards.ts. Compare the two proposed classification approaches and check existing protocol tests. Done means inbound messages avoid redundant schema parses while validation remains strict.
由索引模型根據 Issue 內容生成。
描述
What happened?
On a Streamable HTTP server, each inbound JSON-RPC request goes through five zod schema walks before its handler runs, though its kind is settled by the first one. Line references are at 919bb8e (main); 2.4.0 behaves the same.
- The transport parses the message with
JSONRPCMessageSchema.parse(packages/server/src/server/streamableHttp.ts:838-839). That union's first member isJSONRPCRequestSchema, so this parse has already established that the message is a request. Protocol'sonmessage(packages/core-internal/src/shared/protocol.ts:838-845) discards that result and classifies the message again with the guards intypes/guards.ts. Each guard is a fullsafeParse. For a request this runsisJSONRPCResultResponse(fails), thenisJSONRPCErrorResponse(fails), thenisJSONRPCRequest(succeeds): three more walks. A notification gets four.- Dispatch validates the request again through the era codec (
protocol.ts:1887,validateRequest).
The three parses in step 2 do no work that step 1 hasn't already done. On our server (@modelcontextprotocol/server 2.4.0, about 1000 concurrent sessions), zod accounts for 6.8% of server CPU in a profile, and this classification chain is a large share of it.
What did you expect?
Each message is classified once. Two options:
- Have the transport pass on the kind it already parsed, so
onmessagedoesn't classify again. - Or classify by key presence (
methodwithid,methodwithoutid,result,error) and run only the one schema those keys select.
Either option keeps validation strict and drops two or three full parses from every inbound message.
Related: #3178 asks for pluggable protocol validation, mainly to reduce bundle size, and lists skipping inbound validation as one option. This issue is narrower. It asks for no new API, only for each message to be parsed once rather than three to five times.
Code to reproduce
Every inbound message takes this path, with no conditions. POST any request (for example tools/call) to a McpServer on StreamableHTTPServerTransport and step through streamableHttp.ts:838 → protocol.ts:838-845 → protocol.ts:1887. The guard chain in onmessage runs on every message the transport delivers, after the transport has already parsed it with JSONRPCMessageSchema.
SDK version
@modelcontextprotocol/server 2.4.0 (also present on main at 919bb8e)
Area
Server
- 主要語言
- TypeScript
- 星號
- 13.8k
- 分支
- 2.5k
- 平均合併
- 6 天 23 小時
- 30 天內合併 PR
- 2
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
modelcontextprotocol/typescript-sdk 的其他 Issue
-
v2
難度 1/5 1 小時以內 新手友好度 72/100
modelcontextprotocol/typescript-sdk#3270 · 1 則留言 ·
維護者通常 1 天內回覆
-
`callTool` with `allowInputRequired: true` throws on an `input_required` result when the tool declares an `outputSchema`可能已有人在做 @mgoldsborough 於 6 天前認領。 未關閉v2
難度 2/5 1-3 小時 新手友好度 78/100
modelcontextprotocol/typescript-sdk#3249 ·
維護者通常 1 天內回覆
-
v2
難度 2/5 1-3 小時 新手友好度 68/100
modelcontextprotocol/typescript-sdk#3243 · 3 則留言 ·
維護者通常 1 天內回覆
-
TypeScript client accepts an unknown `resultType` in the first `server/discover` reply可能已有人在做 @Tidehyc 於 7 天前認領。 未關閉v2
難度 2/5 1-3 小時 新手友好度 72/100
modelcontextprotocol/typescript-sdk#3235 · 3 則留言 ·
維護者通常 1 天內回覆
-
UriTemplate.match() throws a TypeError on an empty expression it accepts可能已有人在做 @yunusemrejs 於 12 天前認領。 未關閉v1 v2
難度 2/5 1-3 小時 新手友好度 80/100
modelcontextprotocol/typescript-sdk#3221 · 3 則留言 ·
維護者通常 1 天內回覆
查看 modelcontextprotocol/typescript-sdk 的全部 Issue
相似的 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 72/100
-
難度 2/5 1-3 小時 新手友好度 68/100
Vessel9817/onion-site-template#512 ·
維護者通常 1 天內回覆
-
nightly-tests
難度 2/5 1-3 小時 新手友好度 68/100
BlackBeltTechnology/pi-agent-dashboard#1256 ·
維護者通常 1 天內回覆
-
approved
難度 2/5 1-3 小時 新手友好度 85/100
fritzprix/libr-agent#3266 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 88/100
better-auth/better-auth#13101 · 1 則留言 · 1 個 reaction ·
維護者通常 1 天內回覆