MCP provides a dedicated channel for servers to send log messages to the client, which is separate from the standard notification system. This allows for structured and level-specific logging without cluttering the main message stream.
mcp-use
supports this feature through a logging_callback
function that can be passed to the MCPClient
.
fastmcp
), you can send log messages with different severity levels from within a tool’s context (ctx
).
logging/message
notifications to the client.
LoggingMessageNotification
events within the general message_handler
, the recommended approach is to use the dedicated logging_callback
. This keeps your code clean by separating logging concerns from other notification handling.
The logging_callback
receives the parameters of the log notification directly, which include the level
and message
.
logging_callback
, you can easily route server-side logs to your client’s logging system, display them in a debug console, or handle them in any other way that suits your application’s needs.