modelcontextprotocol / modelcontextprotocol/python-sdk

`ClientConfig` has inconsistent naming: `message_handler` should be `message_callback`

未关闭
#2,588 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

enhancement needs decision P3 v2
主要语言
Python
星标
24.3k
派生
4k
平均合并
1 天 1 小时
30 天内合并 PR
31

描述

Initial Checks
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_handlermessage_callback consistently across all three sites:

File Change
src/mcp/client/client.py message_handlermessage_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_handlermessage_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)

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 src/mcp/client/client.py 中的回调定义和转发调用开始,然后跟踪 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

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。