Skip to main content
Use this when you need to capture or process log messages sent by the server. MCP servers can emit log messages to clients. The client handles these through a log handler callback.

Log Handler

Provide a log_handler function when creating the client:
The handler receives a LogMessage object:

LogMessage

Literal["debug", "info", "notice", "warning", "error", "critical", "alert", "emergency"]
The log level
str | None
The logger name (may be None)
Any
The JSON-serializable log payload sent by the server. FastMCP’s structured logger uses a dictionary with msg and extra keys, but other MCP servers may send any JSON value.

Structured Logs

The message.data attribute contains the server’s JSON-serializable log payload. FastMCP servers commonly send a dictionary with msg and extra keys, which enables structured logging with rich contextual information.
This structure is preserved even when logs are forwarded through a FastMCP proxy, making it useful for debugging multi-server applications.

Default Behavior

If you do not provide a custom log_handler, FastMCP’s default handler routes server logs to Python’s logging system at the appropriate severity level. The MCP levels map as follows: notice becomes INFO; alert and emergency become CRITICAL.