Ask an LLM to convert 98.6°F to Celsius and you might get 37°C, 36.8°C, or something entirely wrong. Unit conversions are a notorious weak spot for language models. This guide shows you how to give your AI agents precise, deterministic conversion tools via MCP.
Why LLMs Fail at Unit Conversions
Large language models don't actually compute conversions. They predict what text should come next based on patterns in their training data. This creates several failure modes:
- Memorized approximations: LLMs often recall "1 mile is about 1.6 km" instead of the precise 1.609344 km
- Formula errors: Temperature conversion requires (F - 32) × 5/9, but LLMs frequently apply formulas incorrectly
- Rounding mistakes: Even when the formula is right, LLMs round at the wrong step or to the wrong precision
- Obscure units: Less common conversions (stones to kg, nautical miles to meters) have higher error rates
TinyFn Conversion Categories
TinyFn provides deterministic conversion tools across multiple categories:
| Category | Units Supported | MCP Endpoint |
|---|---|---|
| Temperature | Celsius, Fahrenheit, Kelvin, Rankine | /mcp/convert |
| Length | Meters, feet, inches, miles, km, yards, nautical miles | /mcp/convert |
| Weight | Kilograms, pounds, ounces, grams, stones, tons | /mcp/convert |
| Volume | Liters, gallons, cups, ml, fluid ounces, pints | /mcp/convert |
| Data | Bytes, KB, MB, GB, TB, bits | /mcp/convert |
Setting Up MCP for Conversions
Add TinyFn's conversion tools to your MCP client configuration:
{
"mcpServers": {
"tinyfn-convert": {
"url": "https://api.tinyfn.io/mcp/convert/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
Or include all TinyFn tools:
{
"mcpServers": {
"tinyfn": {
"url": "https://api.tinyfn.io/mcp/all/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
Temperature Conversions
Temperature conversions are particularly error-prone for LLMs because the formula isn't a simple multiplication.
Fahrenheit to Celsius
convert/fahrenheit-to-celsius
{
"fahrenheit": 98.6
}
{
"celsius": 37,
"fahrenheit": 98.6,
"formula": "(98.6 - 32) × 5/9 = 37"
}
Celsius to Kelvin
convert/celsius-to-kelvin
{
"celsius": -40
}
{
"kelvin": 233.15,
"celsius": -40
}
Length and Weight Conversions
Miles to Kilometers
convert/miles-to-km
{
"miles": 26.2
}
{
"kilometers": 42.1648,
"miles": 26.2,
"conversionFactor": 1.609344
}
Pounds to Kilograms
convert/pounds-to-kg
{
"pounds": 150
}
{
"kilograms": 68.0389,
"pounds": 150,
"conversionFactor": 0.45359237
}
Agent Integration Examples
Python Agent with LangChain
from langchain.tools import Tool
import requests
def convert_temperature(query: str) -> str:
"""Convert temperature using TinyFn MCP."""
# Parse the query to extract value and units
# This is simplified - real implementation would be smarter
response = requests.post(
"https://api.tinyfn.io/v1/convert/fahrenheit-to-celsius",
headers={"X-API-Key": "your-api-key"},
json={"fahrenheit": 98.6}
)
return response.json()
temperature_tool = Tool(
name="temperature_converter",
func=convert_temperature,
description="Convert temperatures between Celsius, Fahrenheit, and Kelvin"
)
# Add to your agent's tool list
agent = create_agent(tools=[temperature_tool, ...])
Claude Desktop Usage
Once TinyFn MCP is configured in Claude Desktop, conversions happen automatically:
Convert 72°F to Celsius for me.
Using convert/fahrenheit-to-celsius tool...
72°F is exactly 22.22°C.
The conversion formula is (72 - 32) × 5/9 = 22.222...
Best Practices
- Use specific endpoints: If your agent only needs conversions, use
/mcp/convertinstead of/mcp/allto reduce tool discovery overhead - Handle precision: TinyFn returns high-precision results. Your agent should round appropriately for the context (2 decimal places for everyday use, more for scientific applications)
- Chain conversions: For multi-step conversions (e.g., stones to grams), let your agent make multiple tool calls rather than trying to compute intermediate steps
- Include units in prompts: Train your agent to always include units in responses to avoid ambiguity
Get Accurate Conversions for Your AI
Stop guessing at unit conversions. Give your AI agents deterministic tools.
Get Free API Key