Parameter Types, Tool Descriptions, and Additional Customization
Hiding Parameters from the LLM
Since all parameters of our function are sent to the client as part of the tool schema, it's important to avoid including sensitive information (like credentials or database connections) in the function signature.
Our example, doesn't really have any sensitive information, but let's suppose we want to make the age multiplier configurable through environment variables, but we don't want the LLM to see or control this configuration value. We only want the LLM to provide the dog's age, while our server handles the calculation logic internally.
First, we can add the age multiplier to our .env file:
[...]
DOG_AGE_MULTIPLIER=7
Instead of including the multiplier as a parameter in the function signature, we can use FastMCP's dependency injection system with Depends() to inject it at runtime without exposing it in the tool schema:
from fastmcp import FastMCP
from fastmcp.dependencies import Depends
def get_age_multiplier() -> int:
"""Load the age multiplier from environment variables."""
return int(os.getenv("DOG_AGE_MULTIPLIER", "7"))
@mcp.toolPractical 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!
