Building a Functional MCP Client
54%
Logging Handler
The server emits log messages during tool execution (e.g. via ctx.info()). This handler receives those messages on the client side and forwards them to Python's standard logging system.
This handler is optional — FastMCP provides a built-in default that does the same thing if no custom handler is supplied.
For more control, you can implement your own handler. For example, you could write the logs to a file, or display them in a custom format.
We are going to create the logging.py file for our custom log handler:
cat > $HOME/workspace/puppy_guide/client/handlers/logging.py << 'EOF'
import logging
from fastmcp.client.logging import LogMessage
logger = logging.getLogger("mcp.server")
async def log_handler(message: LogMessage) -> None:
msg = message.data.get("msg", "") if isinstance(message.data, dict) else str(message.data)
level_map = {
"debug":Practical MCP with FastMCP & LangChain
Engineering the Agentic ExperienceEnroll now to unlock current content and receive all future updates for free. Your purchase supports the author and fuels the creation of more exciting content. Act fast, as the price will rise as the course nears completion!
