Client Logging with FastMCP
58%
Putting It All Together
At this level, here is the full server code with the necessary imports, the FastMCP instantiation, and the dog age calculator tool with logging:
cat > $HOME/workspace/puppy_guide/server/main.py << EOF
import logging
import os
from typing import Annotated
from dotenv import load_dotenv
from pydantic import Field
from fastmcp import Context
from fastmcp import FastMCP
from fastmcp.exceptions import ToolError
load_dotenv()
mcp = FastMCP(
name=os.getenv("MCP_NAME"),
instructions=os.getenv("MCP_INSTRUCTIONS"),
)
def get_breed_multiplier(breed: str) -> int | None:
"""Fetch the age multiplier for a given dog breed."""
breed_multipliers = {
"labrador": 7,
"chihuahua": 5,
"german shepherd": 8,
"bulldog": 6,
# In reality there are over 350 recognized breeds,
# but for brevity we only list a few here.
}
# Returns None if the breed is not found
return breed_multipliers.get(breed.lower())
@mcp.tool
async def dog_to_human_age(
age: Annotated[int, Field(ge=0, le=30,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!
