Skip to main content

Add your description here

Project description

Food Tracker MCP

A Model Context Protocol (MCP) server for tracking food consumption, analyzing nutrition, and managing dietary restrictions.

Overview

Food Tracker MCP integrates with the OpenFoodFacts database to provide a comprehensive food tracking system with the following features:

  • Search for food products by barcode or keyword
  • Analyze nutritional content of food products
  • Create meal plans based on specific nutrition goals and dietary restrictions
  • Track food consumption with meal logging
  • Manage dietary restrictions and allergies
  • Check product compatibility with user restrictions
  • View food logs and nutrition summaries

Installation

Prerequisites

  • Python 3.8 or higher
  • pip (Python package manager)

Setup

  1. Clone the repository or download the food_tracker.py file:
# Option 1: Clone the repository (if available)
git clone https://github.com/yourusername/food-tracker-mcp.git
cd food-tracker-mcp

# Option 2: Create a new directory and save the file there
mkdir food-tracker-mcp
cd food-tracker-mcp
# Copy food_tracker.py into this directory
  1. Create a virtual environment (recommended):
python -m venv venv
  1. Activate the virtual environment:
# On Windows
venv\Scripts\activate

# On macOS/Linux
source venv/bin/activate
  1. Install the required dependencies:
pip install httpx fastmcp pydantic
  1. Ensure the data directories are created (the script will do this automatically on first run):
mkdir -p data/users data/logs

Running the MCP Server

Run the server using:

python food_tracker.py

The server will start and be ready to receive commands.

Using with Claude

To use this MCP with Claude, you'll need to register it with the Claude platform. Here's how to do it:

  1. Follow Anthropic's documentation to register your MCP:

    • Visit https://console.anthropic.com/mcps or the relevant section in your Anthropic account
    • Register the food-tracker MCP by providing the necessary information and endpoint
  2. Once registered, you can interact with the Food Tracker through Claude by invoking the MCP's tools.

Example prompts to use with Claude:

  • "Scan this barcode to see nutrition information: 3270190119357"
  • "Add a peanut allergy to my dietary restrictions"
  • "Log that I had a granola bar for breakfast"
  • "Search for products containing 'oatmeal'"
  • "Check if this product is compatible with my dietary restrictions"
  • "Show me my food log for today"

Available Tools

This MCP provides the following tools that Claude can access:

1. get_product_by_barcode

Get detailed information about a food product using its barcode.

Parameters:

  • barcode: The product barcode (EAN, UPC, etc.)

2. search_products

Search for food products by name or description.

Parameters:

  • query: The search query
  • page: Page number for pagination (default: 1)
  • page_size: Number of results per page (default: 10)

3. manage_user_restrictions

Manage a user's dietary restrictions.

Parameters:

  • user_id: The user's unique identifier
  • action: The action to perform (get, add, remove, update)
  • restriction_type: Type of restriction (allergen, diet, ingredient, medical, preference)
  • restriction_value: The specific restriction value (e.g., "peanuts", "vegetarian")
  • severity: How severe the restriction is (avoid, limit, fatal)
  • notes: Additional notes about the restriction

4. check_product_compatibility

Check if a product is compatible with a user's dietary restrictions.

Parameters:

  • user_id: The user's unique identifier
  • barcode: The product barcode to check

5. analyze_nutrition

Analyze the nutritional content of a food product.

Parameters:

  • barcode: The product barcode

6. log_food_consumption

Log food consumption for a user.

Parameters:

  • user_id: The user's unique identifier
  • barcode: The product barcode
  • quantity: Amount consumed (default: 1 serving)
  • meal_type: Type of meal (breakfast, lunch, dinner, snack)

7. get_user_food_log

Get a user's food log for a specific date.

Parameters:

  • user_id: The user's unique identifier
  • date: Date in YYYY-MM-DD format (defaults to today)

Example Usage Scenarios

Setting Up a New User with Restrictions

  1. Add a gluten allergy:
manage_user_restrictions(
    user_id="user123",
    action="add",
    restriction_type="allergen", 
    restriction_value="gluten",
    severity="avoid",
    notes="Avoid all wheat products"
)
  1. Add a vegetarian diet:
manage_user_restrictions(
    user_id="user123",
    action="add",
    restriction_type="diet", 
    restriction_value="vegetarian"
)

Tracking Food Consumption

  1. Scan a product and log it:
# First get product info
product = get_product_by_barcode(barcode="3270190119357")

# Then log consumption
log_food_consumption(
    user_id="user123",
    barcode="3270190119357",
    quantity=1,
    meal_type="breakfast"
)
  1. Check compatibility with restrictions:
check_product_compatibility(
    user_id="user123",
    barcode="3270190119357"
)

Analyzing Nutritional Information

  1. Get detailed nutrition analysis:
analyze_nutrition(barcode="3270190119357")
  1. View food log and nutrition totals:
get_user_food_log(user_id="user123")

Data Storage

The Food Tracker MCP stores data locally in JSON files:

  • User profiles: ./data/users/{user_id}.json
  • Food logs: ./data/logs/{user_id}_{date}.json

Extending the MCP

You can extend the MCP by:

  1. Adding new nutritional analysis features
  2. Implementing more detailed diet plans and goals
  3. Adding recipe suggestions based on available ingredients
  4. Creating reports and visualizations of nutrition data
  5. Implementing social features for sharing progress

Troubleshooting

  • If you encounter connection issues, ensure you have internet access as the MCP connects to the OpenFoodFacts API
  • If product information is incomplete, this may be due to limitations in the OpenFoodFacts database
  • For any data persistence issues, check the permissions on the data directory

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iflow_mcp_nagarjun226_food_tracker-0.1.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file iflow_mcp_nagarjun226_food_tracker-0.1.0.tar.gz.

File metadata

  • Download URL: iflow_mcp_nagarjun226_food_tracker-0.1.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_nagarjun226_food_tracker-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0a319fdfe9337c266997f265e53028df266672d3f9e99ac8ebd29f3de381ab23
MD5 0ac9a3c016130857440607e7525404a3
BLAKE2b-256 3d2162d087f3f9d31c8b00fb18aef0fa45007f39a9258a64449d7b7d9486c2c8

See more details on using hashes here.

File details

Details for the file iflow_mcp_nagarjun226_food_tracker-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: iflow_mcp_nagarjun226_food_tracker-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_nagarjun226_food_tracker-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 66032d8e367038592434527dc32cd49a281790c35488ce3b845d33008d70fdcb
MD5 86a2dde20127cf7bf9a8093b902389be
BLAKE2b-256 bb0d8f80ea1af6bd05408e69dd8b727409f2b6e2f7244e05972ae312845264ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page