Health & Fitness Calculations in AI Apps with MCP

Building a health or fitness AI application? Accuracy is not optional. When users ask about their BMI, daily calorie needs, or heart rate zones, wrong answers are not just unhelpful; they can be harmful. This guide shows you how to equip your AI with deterministic health calculations via MCP.

Why Accuracy Matters in Health Apps

Health calculations involve formulas that LLMs know but cannot reliably execute. Consider BMI calculation:

BMI Formula
BMI = weight (kg) / height (m)^2

Example: 70 kg, 175 cm
BMI = 70 / (1.75)^2 = 70 / 3.0625 = 22.86

An LLM might calculate this as 22.9, 23.0, 22.5, or even wildly wrong values. In health contexts, these errors matter:

  • BMI categories have precise thresholds: 24.9 vs 25.0 is the difference between "normal" and "overweight"
  • Calorie calculations affect real decisions: Wrong TDEE leads to ineffective diet plans
  • Users trust health apps: They may not verify calculations independently
The Stakes: A user following calorie advice based on a hallucinated BMR calculation could consume 500+ calories too many or too few daily. Over weeks, this leads to unintended weight changes and frustration.

BMI Calculations

Body Mass Index is the most commonly requested health calculation. TinyFn provides accurate BMI with category classification:

MCP Tool Call
Tool: health/bmi
Input: {
  "weight": 70,
  "height": 175,
  "unit": "metric"
}

Result: {
  "bmi": 22.86,
  "category": "Normal weight",
  "healthy_range": {
    "min_weight": 56.7,
    "max_weight": 76.6
  }
}

BMI Categories

BMI Range Category
Below 18.5 Underweight
18.5 - 24.9 Normal weight
25.0 - 29.9 Overweight
30.0 and above Obese

BMR and TDEE

Basal Metabolic Rate (BMR) and Total Daily Energy Expenditure (TDEE) are foundational for nutrition planning.

BMR Calculation

MCP Tool Call
Tool: health/bmr
Input: {
  "weight": 70,
  "height": 175,
  "age": 30,
  "gender": "male",
  "formula": "mifflin_st_jeor"
}

Result: {
  "bmr": 1680,
  "formula": "mifflin_st_jeor",
  "unit": "kcal/day"
}

TDEE Calculation

MCP Tool Call
Tool: health/tdee
Input: {
  "weight": 70,
  "height": 175,
  "age": 30,
  "gender": "male",
  "activity_level": "moderate"
}

Result: {
  "bmr": 1680,
  "tdee": 2604,
  "activity_multiplier": 1.55,
  "activity_description": "Moderate exercise 3-5 days/week"
}

Activity Levels

Level Multiplier Description
sedentary 1.2 Little to no exercise
light 1.375 Light exercise 1-3 days/week
moderate 1.55 Moderate exercise 3-5 days/week
active 1.725 Hard exercise 6-7 days/week
very_active 1.9 Very hard exercise, physical job

Calorie and Macro Calculations

Once you have TDEE, calculate calorie targets for weight goals and macro distributions:

MCP Tool Call
Tool: health/calorie-goal
Input: {
  "tdee": 2604,
  "goal": "lose",
  "rate": "moderate"
}

Result: {
  "maintenance": 2604,
  "target": 2104,
  "deficit": 500,
  "weekly_change": "0.45 kg loss"
}

Macro Distribution

MCP Tool Call
Tool: health/macros
Input: {
  "calories": 2104,
  "goal": "balanced"
}

Result: {
  "protein": { "grams": 158, "calories": 630, "percentage": 30 },
  "carbs": { "grams": 236, "calories": 946, "percentage": 45 },
  "fat": { "grams": 58, "calories": 526, "percentage": 25 }
}

Fitness Metrics

TinyFn also provides tools for fitness tracking and training:

Heart Rate Zones

MCP Tool Call
Tool: health/heart-rate-zones
Input: {
  "age": 30,
  "resting_hr": 60
}

Result: {
  "max_hr": 190,
  "zones": {
    "zone1": { "name": "Recovery", "min": 114, "max": 133 },
    "zone2": { "name": "Aerobic", "min": 133, "max": 152 },
    "zone3": { "name": "Tempo", "min": 152, "max": 162 },
    "zone4": { "name": "Threshold", "min": 162, "max": 176 },
    "zone5": { "name": "Anaerobic", "min": 176, "max": 190 }
  }
}

Pace Calculator

MCP Tool Call
Tool: health/pace
Input: {
  "distance": 5,
  "time_minutes": 25,
  "unit": "km"
}

Result: {
  "pace_per_km": "5:00",
  "pace_per_mile": "8:03",
  "speed_kmh": 12,
  "speed_mph": 7.46
}

Building a Health Chatbot

Here's how a health chatbot conversation flows with TinyFn MCP tools:

Example Conversation
User: "I'm 175cm tall, weigh 85kg, I'm 35 years old male.
       I want to lose weight. What should I eat?"

Agent workflow:
1. Calculate BMI to assess current status
2. Calculate BMR and TDEE
3. Calculate calorie target for weight loss
4. Calculate macro distribution

Tool calls:
- health/bmi { "weight": 85, "height": 175 }
  Result: { "bmi": 27.76, "category": "Overweight" }

- health/tdee { "weight": 85, "height": 175, "age": 35, "gender": "male", "activity_level": "light" }
  Result: { "bmr": 1769, "tdee": 2432 }

- health/calorie-goal { "tdee": 2432, "goal": "lose", "rate": "moderate" }
  Result: { "target": 1932, "deficit": 500 }

- health/macros { "calories": 1932, "goal": "high_protein" }
  Result: { "protein": 174g, "carbs": 169g, "fat": 64g }

Agent response:
"Based on your stats, your BMI is 27.8, which is in the overweight range.
Here's your personalized plan:

**Daily Targets:**
- Calories: 1,932 kcal (500 calorie deficit)
- Protein: 174g (helps preserve muscle during weight loss)
- Carbs: 169g
- Fat: 64g

This should result in about 0.45kg (1 lb) weight loss per week.
Your healthy weight range is 56-77kg."

MCP Setup

Add TinyFn health tools to your AI application:

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

Available Health Tools

Tool Description
health/bmi Calculate Body Mass Index with category
health/bmr Calculate Basal Metabolic Rate
health/tdee Calculate Total Daily Energy Expenditure
health/ideal-weight Calculate ideal body weight range
health/body-fat Estimate body fat percentage
health/calorie-goal Calculate calorie target for goals
health/macros Calculate macro nutrient distribution
health/heart-rate-zones Calculate training heart rate zones
health/pace Calculate running/cycling pace
Important: These tools provide calculations, not medical advice. Always include appropriate disclaimers in health applications and encourage users to consult healthcare professionals.

Build Your Health AI with Accurate Calculations

Get your free API key and add deterministic health tools to your application.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key