food-calorie-api
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
Food Calorie API
A simple REST API for tracking food calorie intake with MCP (Model Context Protocol) integration for AI agent access.
Features
๐ Create food calorie entries with name, calories, timestamp, and notes
๐ List food entries with date filtering and pagination
๐ Calculate calorie statistics (total, daily average)
๐ค MCP server integration for AI agents
๐ CSV-based storage (no database required)
โ Full input validation and error handling
๐ OpenAPI v3 specification
Related MCP server: foodlog
Installation
# Install dependencies
pip install -r requirements.txtUsage
Starting the API Server
python3 -m food_calorie_api.appThe API will be available at http://localhost:5001
API Endpoints
POST /api/foods
Create a new food entry.
Request:
{
"food_name": "Apple",
"calories": 95,
"timestamp": "2026-01-01T08:30:00Z", // optional, defaults to current time
"notes": "Morning snack" // optional
}Response (201 Created):
{
"id": 1,
"timestamp": "2026-01-01T08:30:00Z",
"food_name": "Apple",
"calories": 95.0,
"notes": "Morning snack"
}Validation Rules:
food_name: Required, 1-200 characterscalories: Required, 0-10000, rounded to 1 decimal placetimestamp: Optional ISO8601 UTC format, cannot be in the futurenotes: Optional, max 500 characters
GET /api/foods
List food entries with optional filters.
Query Parameters:
start_date: Filter from this date (ISO8601)end_date: Filter to this date (ISO8601)limit: Maximum entries to return (default: 100, max: 1000)offset: Number of entries to skip (default: 0)
Response (200 OK):
{
"total": 250,
"entries": [
{
"id": 1,
"timestamp": "2026-01-01T08:30:00Z",
"food_name": "Apple",
"calories": 95.0,
"notes": "Morning snack"
}
]
}GET /api/foods/stats
Get calorie statistics.
Query Parameters:
start_date: Start of date range (ISO8601)end_date: End of date range (ISO8601)
Response (200 OK):
{
"total_calories": 5420.5,
"average_per_day": 1806.83,
"total_entries": 18,
"date_range": {
"start": "2026-01-01",
"end": "2026-01-03"
}
}Note: average_per_day = total_calories / number_of_days_in_range. Days with no entries are included (counted as 0 calories).
Error Response Format
All errors return a structured JSON response:
{
"error": "Human-readable error message",
"code": "ERROR_CODE",
"details": [
{
"field": "field_name",
"message": "Specific field error"
}
]
}Error Codes:
INVALID_INPUT: Validation failedFUTURE_TIMESTAMP: Timestamp cannot be in the futureSTORAGE_ERROR: CSV file access errorNOT_FOUND: Resource not foundINTERNAL_ERROR: Unexpected server error
MCP Integration
Starting the MCP Server
DATA_FILE=data/food_entries.csv python3 -m food_calorie_api.mcp_serverMCP Configuration
Add to your MCP client configuration (e.g., mcp_config.json):
{
"mcpServers": {
"food-calorie-api": {
"command": "python3",
"args": ["-m", "food_calorie_api.mcp_server"],
"env": {
"DATA_FILE": "data/food_entries.csv"
}
}
}
}Available MCP Tools
add_food_entry
Add a new food calorie entry.
Parameters:
food_name(string, required): Name of the foodcalories(number, required): Calorie value (0-10000)timestamp(string, optional): ISO8601 UTC timestampnotes(string, optional): Optional notes
Example:
{
"food_name": "Chicken Breast",
"calories": 165.5,
"notes": "Grilled, 100g"
}list_food_entries
List food entries with optional filtering.
Parameters:
start_date(string, optional): Filter from this dateend_date(string, optional): Filter to this datelimit(integer, optional): Maximum entries (default: 100)
get_calorie_stats
Get calorie statistics for a date range.
Parameters:
start_date(string, optional): Start of date rangeend_date(string, optional): End of date range
MCP Resources
food://entries: List of all food calorie entriesfood://stats: Overall calorie statistics
Examples
Create a food entry
curl -X POST http://localhost:5001/api/foods \
-H "Content-Type: application/json" \
-d '{
"food_name": "Chicken Breast",
"calories": 165.5,
"notes": "Grilled"
}'List recent entries
curl http://localhost:5001/api/foods?limit=10Get today's statistics
TODAY=$(date +%Y-%m-%d)
curl "http://localhost:5001/api/foods/stats?start_date=${TODAY}&end_date=${TODAY}"Testing
Run the test suite:
python3 -m unittest tests.test_api -vData Storage
Food entries are stored in data/food_entries.csv with the following format:
id,timestamp,food_name,calories,notes
1,2026-01-01T08:30:00Z,Apple,95.0,Morning snack
2,2026-01-01T12:00:00Z,"Apple, Red Delicious",95.5,"Fresh from ""market"""Uses CSV QUOTE_MINIMAL for automatic escaping
File locking prevents concurrent write issues
Auto-incrementing integer IDs
Tech Stack
Python 3.11+
Flask - Web framework
flask-restful - REST API framework
python-dateutil - Date parsing
mcp - Model Context Protocol
Architecture
food_calorie_api/
โโโ __init__.py
โโโ app.py # Flask application
โโโ resources.py # API resources
โโโ storage.py # CSV storage layer
โโโ models.py # Data models
โโโ validators.py # Input validation
โโโ mcp_server.py # MCP integrationLicense
MIT
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogโฆ
This server cannot be deployed
Maintenance
Related MCP Connectors
Calorie tracker. Tell your AI what you ate and it goes into your Ampsu food diary.
Calorie and protein log with honest ranges: log, edit, plan and review meals from any assistant.
AI-powered calorie tracking with photo recognition, barcode scanning, and voice logging
Calorie tracker app for ChatGPT and Claude: read meals, macros, weight and log meals from chat.
Related MCP Servers
- FlicenseNot gradedqualityCmaintenanceEnables querying Yazio food logs including meals, daily summaries, and nutrition totals through MCP tools.-
- FlicenseNot gradedqualityCmaintenanceEnables agents to log and edit meals, query a food journal, and retrieve calorie/macro/quality KPIs with server-side nutritional grading, plus manage staples and targets.1-
- FlicenseNot gradedqualityBmaintenanceEnables the agent to record meals, workouts, and check-ins, and to retrieve daily summaries, history, and settings through MCP tools.-
- AlicenseBqualityCmaintenanceEnables AI agents and LLMs to retrieve precise food chemistry and nutrition data from USDA, Open Food Facts, and IFCT, evaluate recipes, optimize macros, look up barcodes, and detect ultra-processed foods through MCP tools.9MIT