Refactor handler context to be transport- and handler-type-aware
還沒有人認領這個 Issue。
評估
- 難度
- 5/5
- 預估耗時
- 一週以上
- 新手友好度
- 25/100
- Issue 類型
- 重構
- 描述清晰度
- 需要釐清
- 活躍度
- 停滯
- 技術堆疊
- python
研究方向
首先沿著 handler 入口點追蹤 RequestContext 和 ServerRequestContext,然後檢查 ServerMessageMetadata.request_context,以及針對 Starlette Request 和 stdio 提到的傳輸情況。比較 request handler 和 notification handler 如何接收 context,以及如何存取傳輸特定的值。在不依賴 Any 或可選 request ID 的情況下定義預期的型別邊界和傳輸行為,即表示完成。
由索引模型根據 Issue 內容生成。
描述
The current RequestContext / ServerRequestContext design has a few rough edges that warrant a dedicated refactor:
-
Request vs notification context — Request handlers have
request_idandmeta, notification handlers do not. Currentlyrequest_idis optional (RequestId | None) on a single shared type, which loses type safety. Ideally these would be distinct types so request handlers get a context whererequest_idis always present, and notification handlers get one where it does not exist. -
Transport-specific context — The
request_contextfield onServerMessageMetadatais typed asAnybecause the server layer is transport-agnostic (e.g. it is a StarletteRequestfor HTTP transports,Nonefor stdio). A better design would let transports provide their own typed context that handlers can access without casting.
These two concerns are related — both point toward making the context type more precise depending on how and where a handler is invoked.
- 主要語言
- Python
- 星號
- 24.3k
- 分支
- 4k
- 平均合併
- 1 天 1 小時
- 30 天內合併 PR
- 31
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
modelcontextprotocol/python-sdk 的其他 Issue
-
v1 v2
難度 2/5 1-3 小時 新手友好度 85/100
modelcontextprotocol/python-sdk#3546 · 4 則留言 ·
-
v1 v2
難度 2/5 1-3 小時 新手友好度 76/100
modelcontextprotocol/python-sdk#3545 · 1 則留言 ·
-
v1 v2
難度 1/5 1 小時以內 新手友好度 91/100
modelcontextprotocol/python-sdk#3508 · 2 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 64/100
modelcontextprotocol/python-sdk#3504 ·
-
v1 v2
難度 2/5 1-3 小時 新手友好度 82/100
modelcontextprotocol/python-sdk#3492 · 1 則留言 ·
查看 modelcontextprotocol/python-sdk 的全部 Issue
相似的 Issue
-
難度 1/5 1 小時以內 新手友好度 90/100
-
bug
難度 2/5 1-3 小時 新手友好度 86/100
zostera/django-bootstrap4#894 ·
-
難度 2/5 1-3 小時 新手友好度 78/100
use-agent-os/agent-os#3276 ·
-
難度 2/5 1-3 小時 新手友好度 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
難度 2/5 1-3 小時 新手友好度 88/100
NousResearch/hermes-agent#117848 ·