Feedback

Chat Icon

Practical MCP with FastMCP & LangChain

Engineering the Agentic Experience

Parameter Types, Tool Descriptions, and Additional Customization
42%

The Importance of Docstrings

To solve the first problem, we can add a docstring to the function:

@mcp.tool
def dog_to_human_age(age):
    """Calculate the real age of a dog in human years."""
    return age * 7

There are a few things to note:

The tool name: FastMCP automatically uses the function name (dog_to_human_age) as the tool identifier sent to clients. The function name becomes the tool identifier in the MCP protocol and its identity vis-a-vis the LLM. This is how clients will refer to the tool when calling it.

The description: FastMCP reads the function's docstring and uses it as the tool description sent to clients. The docstring is the single source of truth, visible both to developers reading the code and to the LLM using the tool.

We can also add @mcp.tool(description="...") to provide a custom description instead of using the docstring:

@mcp.tool(
    description="Calculate the real age of a dog in human years.",
)
def

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!