Unit Conversion Tools for AI via MCP

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
Real example: When asked to convert 98.6°F to Celsius, GPT-4 has been observed returning 37.0°C, 36.89°C, and 37.2°C in different sessions. The correct answer is exactly 37°C.

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:

mcp.json
{
  "mcpServers": {
    "tinyfn-convert": {
      "url": "https://api.tinyfn.io/mcp/convert/",
      "headers": {
        "X-API-Key": "your-api-key"
      }
    }
  }
}

Or include all TinyFn tools:

mcp.json (all 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

Tool Call
convert/fahrenheit-to-celsius
{
  "fahrenheit": 98.6
}
Response
{
  "celsius": 37,
  "fahrenheit": 98.6,
  "formula": "(98.6 - 32) × 5/9 = 37"
}

Celsius to Kelvin

Tool Call
convert/celsius-to-kelvin
{
  "celsius": -40
}
Response
{
  "kelvin": 233.15,
  "celsius": -40
}

Length and Weight Conversions

Miles to Kilometers

Tool Call
convert/miles-to-km
{
  "miles": 26.2
}
Response
{
  "kilometers": 42.1648,
  "miles": 26.2,
  "conversionFactor": 1.609344
}

Pounds to Kilograms

Tool Call
convert/pounds-to-kg
{
  "pounds": 150
}
Response
{
  "kilograms": 68.0389,
  "pounds": 150,
  "conversionFactor": 0.45359237
}

Agent Integration Examples

Python Agent with LangChain

Python
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:

User Prompt
Convert 72°F to Celsius for me.
Claude's Response (with TinyFn)
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

  1. Use specific endpoints: If your agent only needs conversions, use /mcp/convert instead of /mcp/all to reduce tool discovery overhead
  2. 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)
  3. 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
  4. 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

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key