Client Logging with FastMCP
Structured Data with the Extra Parameter
Every logging method accepts an optional extra parameter, which lets you attach a dictionary of structured data alongside the human-readable message. This is particularly useful for clients that do more than just display log lines. A monitoring dashboard might parse the extra data to build charts. An analytics client might index it for later querying. Even a simple development client benefits from having structured metadata it can format nicely.
The extra dictionary can contain any JSON-serializable data: strings, numbers, booleans, nested dictionaries, and lists. You might include a transaction ID, a count of processed records, request timing information, or any other contextual data that would be useful for understanding the log message in detail. The human-readable message tells the story; the extra data provides the evidence.
Here is an example of using the extra parameter in our code:
from fastmcp import FastMCP
from fastmcp import Context
@mcp.tool
async def dog_to_human_age(ctx: Context, age: int, breed: str) -> int:
multiplier = get_breed_multiplier(breedPractical 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!
