Skip to content

ClientConfig has inconsistent naming: message_handler should be message_callback #2588

@fuyu-quant

Description

@fuyu-quant

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions