modelcontextprotocol / modelcontextprotocol/python-sdk
`ClientConfig` has inconsistent naming: `message_handler` should be `message_callback`
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 24.3k
- 分支
- 4k
- 平均合併
- 1 天 1 小時
- 30 天內合併 PR
- 31
描述
Initial Checks
- I confirm that I'm using the latest version of MCP Python SDK
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Description
ClientConfig exposes five user-facing callback fields, but four of them use the *_callback suffix while one uses *_handler:
# src/mcp/client/client.py
sampling_callback: SamplingFnT | None = None
list_roots_callback: ListRootsFnT | None = None
logging_callback: LoggingFnT | None = None
elicitation_callback: ElicitationFnT | None = None
message_handler: MessageHandlerFnT | None = None # ← inconsistent
The same inconsistency is present in ClientSession.__init__ and ServerConnectionParams:
# src/mcp/client/session.py
def __init__(self, ..., message_handler: MessageHandlerFnT | None = None, ...)
# src/mcp/client/session_group.py
class ServerConnectionParams:
message_handler: MessageHandlerFnT | None = None
A TODO comment in the codebase already flags this:
# TODO(Marcelo): Why do we have both "callback" and "handler"?
message_handler: MessageHandlerFnT | None = None
Proposed Fix
Rename message_handler → message_callback consistently across all three sites:
| File | Change |
|---|---|
src/mcp/client/client.py |
message_handler → message_callback (field + forwarding call) |
src/mcp/client/session.py |
message_handler parameter → message_callback; internal _message_handler → _message_callback |
src/mcp/client/session_group.py |
ServerConnectionParams.message_handler → message_callback + forwarding call |
src/mcp/client/__main__.py |
local variable + keyword arg rename |
Since this is the v2 rewrite on main, a breaking rename is appropriate and there is no need for a deprecation shim.
I'd like to take this on if you're open to a fix.
Python & MCP Python SDK
Python 3.13
Reproduced on: main @ 161834d (2026-05-13)
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 src/mcp/client/client.py 中的 callback 定義和轉送呼叫開始,接著追蹤 src/mcp/client/session.py 中相關的參數和內部屬性。檢查 src/mcp/client/session_group.py 中的 ServerConnectionParams,以及 src/mcp/client/main.py 中的區域變數和關鍵字引數。完成的標準是四個位置都一致使用 message_callback,且此流程中不再有 message_handler 命名。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 重構
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 73/100