Feedback

Chat Icon

Practical MCP with FastMCP & LangChain

Engineering the Agentic Experience

Parameter Types, Tool Descriptions, and Additional Customization
45%

Putting Everything Together

This is the full code at this stage:

cat > main.py << EOF
import os
from typing import Annotated
from dotenv import load_dotenv
from pydantic import Field
from fastmcp import FastMCP
from fastmcp.dependencies import Depends

load_dotenv()

def get_age_multiplier() -> int:
    """Load the age multiplier from environment variables."""
    return int(os.getenv("DOG_AGE_MULTIPLIER", "7"))

mcp = FastMCP(
    name=os.getenv("MCP_NAME"),
    list_page_size=int(os.getenv("MCP_LIST_PAGE_SIZE", "10")),
    instructions=os.getenv("MCP_INSTRUCTIONS"),
)

@mcp.tool
def dog_to_human_age(
    age: Annotated[int, Field(ge=0, le=30, description="The dog's age in years")],
    multiplier: int = Depends(get_age_multiplier),
) -> int:
    """Calculate the real age of a dog in human years."""
    return age * multiplier
EOF

Update the environment variables:

cat > .env << EOF
MCP_NAME="Puppy Guide"
MCP_LIST_PAGE_SIZE=10

Practical MCP with FastMCP & LangChain

Engineering the Agentic Experience

Enroll 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!