Open Food Facts MCP Server

Open Food Facts MCP Server

Enables AI assistants to access the Open Food Facts database to query detailed food product information, nutritional data, and environmental scores. Supports product lookup by barcode, smart search with filtering, nutritional analysis, product comparison, and dietary recommendations to help users make informed food choices.

Category
访问服务器

README

Open Food Facts MCP Server

Test Suite codecov License: MIT

A comprehensive Model Context Protocol (MCP) server that provides AI assistants with access to the Open Food Facts database. Query detailed food product information, nutritional data, and environmental scores to help users make informed food choices.

🌟 Features

  • Product Lookup: Get detailed information by barcode including nutritional facts, ingredients, and scores
  • Smart Search: Find products with advanced filtering by categories, brands, nutrition grades, and more
  • Nutritional Analysis: Interpret Nutri-Score, NOVA processing groups, and Eco-Score ratings
  • Product Comparison: Compare multiple products side-by-side across different criteria
  • Dietary Recommendations: Get suggestions based on dietary preferences and restrictions
  • Rate Limiting: Built-in rate limiting respects Open Food Facts API constraints
  • Docker Ready: Production deployment with Docker and Docker Compose

🚀 Quick Start

Docker Deployment (Recommended)

# Clone and run
git clone https://github.com/conner/open-food-facts-mcp
cd open-food-facts-mcp
docker-compose up --build

Local Development

# Install dependencies
npm install

# Configure environment
cp .env.example .env

# Build and start
npm run build
npm start

# Development mode
npm run dev

🔧 Configuration

Configure the server via environment variables:

# API Configuration
OPEN_FOOD_FACTS_BASE_URL=https://world.openfoodfacts.net
OPEN_FOOD_FACTS_USER_AGENT=YourApp/1.0 (contact@example.com)

# Rate Limits (requests per minute)
RATE_LIMIT_PRODUCTS=100
RATE_LIMIT_SEARCH=10
RATE_LIMIT_FACETS=2

🛠 Available Tools

get_product

Retrieve comprehensive product information by barcode.

{
  "barcode": "3017620422003"
}

Returns: Product name, brand, nutritional scores, ingredients, nutrition facts, and metadata.

search_products

Search products with advanced filtering capabilities.

{
  "search": "organic chocolate",
  "categories": "snacks",
  "nutrition_grades": "a,b,c",
  "page_size": 10
}

Filters: Categories, brands, countries, nutrition grades, NOVA groups, sorting options.

analyze_product

Get detailed nutritional analysis and score interpretations.

{
  "barcode": "3017620422003"
}

Returns: Score explanations, nutritional breakdown with health assessments, and processing level details.

compare_products

Compare multiple products across different aspects.

{
  "barcodes": ["3017620422003", "8712566073219"],
  "focus": "nutrition"
}

Focus Options: nutrition, environmental, processing, ingredients.

get_product_suggestions

Get personalized product recommendations.

{
  "category": "beverages",
  "dietary_preferences": ["vegan", "organic"],
  "min_nutriscore": "b",
  "max_results": 5
}

Dietary Options: vegan, vegetarian, gluten-free, organic, low-fat, low-sugar, high-protein.

🤖 MCP Integration

Add to your MCP client configuration:

{
  "mcpServers": {
    "open-food-facts": {
      "command": "docker",
      "args": ["run", "-i", "--rm", "open-food-facts-mcp"]
    }
  }
}

Or for local development:

{
  "mcpServers": {
    "open-food-facts": {
      "command": "node",
      "args": ["dist/index.js"],
      "cwd": "/path/to/open-food-facts-mcp"
    }
  }
}

📊 Data & Scores

Nutri-Score

  • A-E rating indicating overall nutritional quality
  • Green (A/B): Healthier choices
  • Red (D/E): Less healthy options

NOVA Groups

  • Group 1: Unprocessed/minimally processed foods
  • Group 2: Processed culinary ingredients
  • Group 3: Processed foods
  • Group 4: Ultra-processed foods

Eco-Score

  • A-E rating for environmental impact
  • Considers packaging, transportation, and production methods

🧪 Development

Testing

# Run all tests
npm test

# Watch mode
npm run test:watch

# Coverage report
npm run test:coverage

# Validate code quality
npm run validate

Code Quality

# Type checking
npm run typecheck

# Linting
npm run lint
npm run lint:fix

Project Structure

src/
├── client.ts       # HTTP client with rate limiting
├── handlers.ts     # MCP tool implementations
├── index.ts        # MCP server entry point
├── tools.ts        # Tool definitions
└── types.ts        # TypeScript types and schemas

tests/
├── client.test.ts      # Client unit tests
├── handlers.test.ts    # Handler unit tests
├── server.test.ts      # Integration tests
├── validation.test.ts  # Schema validation tests
├── rate-limiting.test.ts # Rate limiting tests
├── e2e.test.ts        # End-to-end tests
├── fixtures/          # Test data
└── utils/            # Test utilities

📈 Performance

  • Rate Limiting: Automatic enforcement of API limits
  • Efficient Caching: Smart request deduplication
  • Batch Operations: Optimized multi-product comparisons
  • Error Recovery: Graceful handling of API failures

🔒 API Limits

The server respects Open Food Facts API rate limits:

  • Product queries: 100 requests/minute
  • Search queries: 10 requests/minute
  • Facet queries: 2 requests/minute

Rate limits are enforced automatically with proper error messaging.

🌍 Data Source

All data comes from Open Food Facts, the largest open food database in the world:

  • 900,000+ products from 150+ countries
  • Collaborative data maintained by contributors worldwide
  • Open Database License ensuring free access to food information
  • Real-time updates from the global community

📝 Examples

Basic Product Information

**Nutella**
Brand: Ferrero
Quantity: 400g
Categories: Sweet spreads, Chocolate spreads

Scores:
Nutri-Score: E | NOVA Group: 4 | Eco-Score: D

Ingredients:
Sugar, palm oil, hazelnuts (13%), skimmed milk powder...

Nutrition (per 100g):
Energy: 539 kcal | Fat: 30.9g | Carbs: 57.5g | Sugars: 56.3g

Nutritional Analysis

Nutritional Analysis: Nutella

Scores:
• Nutri-Score E: Very poor nutritional quality
• NOVA Group 4: Ultra-processed foods  
• Eco-Score D: High environmental impact

Nutritional Breakdown:
• Energy: 539 kcal (high)
• Fat: 30.9g (high)
• Sugars: 56.3g (high)
• Salt: 0.107g (low)

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes with tests
  4. Run quality checks (npm run validate)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments


Need help? Open an issue or check the examples for detailed usage patterns.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选