Skip to main content
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.
Server logging allows MCP tools to send debug, info, warning, and error messages back to the client. This provides visibility into function execution and helps with debugging during development and operation.

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
Unlike standard Python logging, MCP server logging sends messages directly to the client, making them visible in the client’s interface or logs.

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.

Server Logs

Client Logging in the form of ctx.log() and its convenience methods (debug, info, warning, error) are meant for sending messages to the MCP clients. Messages sent to clients are also logged to the server’s log at DEBUG level. Enable debug logging on the server or enable debug logging on the fastmcp.server.context.to_client logger to see these messages in the server’s log.

Logging Methods

Context Logging Methods

ctx.debug
async method
Send debug-level messages for detailed execution information
ctx.info
async method
Send informational messages about normal execution
ctx.warning
async method
Send warning messages for potential issues that didn’t prevent execution
ctx.error
async method
Send error messages for problems that occurred during execution
ctx.log
async method
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
See Client Logging for details on how clients can handle server log messages.