ChowAPI is now in open beta — sign up and start building today.
c
ChowAPI
Blog
aiclaudemcptutorial

Building an AI Nutrition Coach with Claude MCP and ChowAPI

ChowAPI Team·

Building an AI Nutrition Coach with Claude MCP and ChowAPI

Large language models are remarkably good at conversation, reasoning, and generating structured output. They are remarkably bad at knowing how many calories are in a banana.

Ask Claude or ChatGPT for the nutrition facts of a specific branded food, and you will get a confident, well-formatted, completely fabricated answer. The model does not have access to a nutrition database. It is pattern-matching against its training data, which means the numbers might be close, outdated, or entirely wrong. For a casual question, that is fine. For a health app that people rely on, it is not.

The fix is simple: give the model access to real data. That is exactly what the Model Context Protocol (MCP) does.

What is MCP?

MCP is a standard that lets AI models call external tools during a conversation. Instead of guessing at nutrition data, Claude can call a ChowAPI endpoint, get the real answer, and use it in its response.

Think of it as giving Claude a phone it can use to look things up. The model decides when it needs data, makes the call, reads the response, and incorporates it into the conversation — all transparently.

For nutrition coaching, this means:

  • "How much protein is in 200g of chicken breast?" triggers a real API lookup instead of a guess
  • "Scan this barcode" sends the code to ChowAPI and returns the actual product data
  • "What should I eat to hit 40g of protein at lunch?" searches for high-protein foods with real numbers

Setting up ChowAPI as an MCP tool

To connect Claude to ChowAPI via MCP, you define tool specifications that describe what the API can do. Here is a minimal setup that gives Claude food search and barcode lookup capabilities.

Add this to your MCP configuration (e.g., in your Claude Desktop config or your app's tool definitions):

{
  "tools": [
    {
      "name": "search_foods",
      "description": "Search for foods by name. Returns nutrition data for matching foods. Use this when the user asks about nutrition, calories, macros, or food composition.",
      "input_schema": {
        "type": "object",
        "properties": {
          "query": { "type": "string", "description": "Food name to search for" },
          "limit": { "type": "number", "description": "Max results (1-25, default 5)" }
        },
        "required": ["query"]
      }
    },
    {
      "name": "barcode_lookup",
      "description": "Look up a food product by its barcode (UPC or EAN). Returns full nutrition data for the product.",
      "input_schema": {
        "type": "object",
        "properties": {
          "code": { "type": "string", "description": "UPC or EAN barcode number" }
        },
        "required": ["code"]
      }
    }
  ]
}

Then implement the tool handlers to call ChowAPI:

async function handleTool(name: string, input: Record<string, unknown>) {
  const headers = { Authorization: "Bearer chow_live_your_key_here" };

  if (name === "search_foods") {
    const { query, limit = 5 } = input;
    const res = await fetch(
      `https://api.chowapi.dev/v1/search?q=${encodeURIComponent(query as string)}&limit=${limit}`,
      { headers }
    );
    return await res.json();
  }

  if (name === "barcode_lookup") {
    const { code } = input;
    const res = await fetch(
      `https://api.chowapi.dev/v1/barcode/${code}`,
      { headers }
    );
    return await res.json();
  }
}

Example conversation flow

With MCP connected, a conversation with your AI nutrition coach looks like this:

User: "I had a Clif Bar for breakfast and 200g of grilled salmon for lunch. How am I doing on protein today?"

Claude (internally):

  1. Calls search_foods({ query: "Clif Bar", limit: 1 })
  2. Gets back: 10g protein per serving, data_quality: 0.65
  3. Calls search_foods({ query: "grilled salmon", limit: 1 })
  4. Gets back: 25.4g protein per 100g, data_quality: 0.91
  5. Calculates: 10g + (25.4 * 2) = 60.8g protein

Claude: "You have had about 61g of protein so far today — 10g from the Clif Bar and roughly 51g from 200g of salmon. If you are targeting 120g daily, you have about 59g to go. The salmon data is high-confidence (quality score 0.91), and the Clif Bar data covers most nutrients (0.65)."

Notice two things: the numbers are real, and Claude communicates the confidence level. The data_quality score lets the model tell the user how much to trust each number.

The .suggestion field for error recovery

When something goes wrong — a barcode is not found, a search returns no results, or a rate limit is hit — ChowAPI returns a suggestion field in every error response:

{
  "error": {
    "code": "NOT_FOUND",
    "message": "No product found for barcode 0000000000000",
    "suggestion": "Check the barcode value. If this is a valid product, it may not be in our database yet.",
    "docs": "https://chowapi.dev/docs/barcode"
  }
}

This field is specifically designed for AI consumption. When Claude receives this error, it can read the suggestion and respond naturally: "I could not find that barcode. Could you double-check the number, or tell me the product name so I can search for it instead?"

No custom error handling logic needed. The API tells the model what to do.

Using data_quality for AI confidence

The data_quality score (0.00 to 1.00) gives your AI a way to express confidence without making things up:

  • 0.80+: "This is well-documented data. The nutrition values are reliable."
  • 0.40-0.79: "This food has basic nutrition data but is missing some micronutrients."
  • Below 0.40: "I only have limited data for this food. The calorie and macro numbers should be roughly correct, but I would not rely on the micronutrient values."

You can include this guidance in your system prompt, and the model will naturally incorporate confidence language into its responses. Users learn to trust the precise numbers and take the sparse ones with appropriate context.

Putting it together

A production AI nutrition coach built on Claude + ChowAPI gives you:

  1. Accurate food data — real numbers from 780K+ foods, not LLM guesses
  2. Transparent confidence — quality scores tell the model (and the user) how much to trust each value
  3. Graceful error handling — the .suggestion field guides the model through edge cases
  4. 34 nutrients per food — not just calories and macros, but vitamins, minerals, and micronutrients
  5. Barcode support — users can reference packaged products by their barcode

The combination of a strong reasoning model and a reliable data source is what separates a toy demo from a product people actually use for health decisions.

Ready to build your AI nutrition assistant? Get your API key and check the quickstart guide. Credit packs start at $5 for 5,000 calls.