This documentation covers MCP client logging - sending messages from your server to MCP clients. For standard server-side logging (e.g., writing to files, console), use
fastmcp.utilities.logging.get_logger()
or Python’s built-in logging
module.For production observability and distributed tracing, see the OpenTelemetry Integration guide.Why Use Server Logging?
Server logging is essential for:- Debugging: Send detailed execution information to help diagnose issues
- Progress visibility: Keep users informed about what the tool is doing
- Error reporting: Communicate problems and their context to clients
- Audit trails: Create records of tool execution for compliance or analysis
Basic Usage
Use the context logging methods within any tool function:Structured Logging with extra
All logging methods (debug
, info
, warning
, error
, log
) now accept an extra
parameter, which is a dictionary of arbitrary data. This allows you to send structured data to the client, which is useful for creating rich, queryable logs.
Logging Methods
Context Logging Methods
Send debug-level messages for detailed execution information
Send informational messages about normal execution
Send warning messages for potential issues that didn’t prevent execution
Send error messages for problems that occurred during execution
Generic logging method with custom level and logger name
Log Levels
Debug
Use for detailed information that’s typically only useful when diagnosing problems:Info
Use for general information about normal program execution:Warning
Use for potentially harmful situations that don’t prevent execution:Error
Use for error events that might still allow the application to continue:Client Handling
Log messages are sent to the client through the MCP protocol. How clients handle these messages depends on their implementation:- Development clients: May display logs in real-time for debugging
- Production clients: May store logs for later analysis or display to users
- Integration clients: May forward logs to external logging systems