modelcontextprotocol / modelcontextprotocol/python-sdk

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

Đang mở
#2,588 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

enhancement needs decision P3 v2
Ngôn ngữ chính
Python
Star
24.3k
Fork
4k
Merge trung bình
1 ngày 1 giờ
Pull request đã merge (30 ngày)
31

Mô tả

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)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với các định nghĩa callback và các lệnh gọi chuyển tiếp trong src/mcp/client/client.py, sau đó theo dõi tham số liên quan và thuộc tính nội bộ trong src/mcp/client/session.py. Kiểm tra ServerConnectionParams trong src/mcp/client/session_group.py, cùng với biến cục bộ và đối số từ khóa trong src/mcp/client/main.py. Được xem là hoàn tất khi cả bốn vị trí đều nhất quán sử dụng message_callback và không còn cách đặt tên message_handler nào trong luồng này.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
backend
Loại issue
Tái cấu trúc
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
73/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.