Receive and handle log messages from MCP servers.
New in version: 2.0.0
MCP servers can emit log messages to clients. The client can handle these logs through a log handler callback.
log_handler
function when creating the client. For robust logging, the log messages can be integrated with Python’s standard logging
module.
message.data
attribute is a dictionary that contains the log payload from the server. This enables structured logging, allowing you to receive rich, contextual information.
The dictionary contains two keys:
msg
: The string log message.extra
: A dictionary containing any extra data sent from the server.log_handler
is called every time a log message is received. It receives a LogMessage
object:
log_handler
, FastMCP uses a default handler that emits a DEBUG-level FastMCP log for every log message received from the server, which is useful for visibility without polluting your own logs.