Labsco
zen-apps logo

USDA Nutrition MCP Server

โ˜… 5

from zen-apps

Access nutrition information for over 600,000 foods from the USDA FoodData Central database.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedAccount requiredNeeds API keys

๐Ÿฅ— USDA Nutrition MCP Enabled Server

Professional Model Context Protocol (MCP) enabled server for USDA FoodData Central
Transforms 600k+ foods into intelligent nutrition tools for Claude Desktop and other MCP clients

๐ŸŒŸ What This Demonstrates

This project showcases professional MCP implementation skills:

โœ… Dual Architecture - Both MCP protocol server AND HTTP API
โœ… Production Bridge - Smart mcp_bridge.py with hosted/local/custom server support
โœ… Three Deployment Options - Hosted service, local development, custom server
โœ… Type-Safe Models - Pydantic schemas with proper validation
โœ… Docker + Cloud Run - Complete deployment pipeline

๐Ÿ”ง For Non-Claude Desktop Users

Direct HTTP API

Live API: https://usda-nutrition-mcp-oc46l7ob5a-uc.a.run.app
Documentation: https://usda-nutrition-mcp-oc46l7ob5a-uc.a.run.app/docs

# Search foods
curl -X POST "https://usda-nutrition-mcp-oc46l7ob5a-uc.a.run.app/tools/search_foods" \
  -H "Content-Type: application/json" \
  -d '{"query": "chicken breast", "page_size": 5}'

# Get nutrition details  
curl -X POST "https://usda-nutrition-mcp-oc46l7ob5a-uc.a.run.app/tools/get_food_nutrition" \
  -H "Content-Type: application/json" \
  -d '{"fdc_id": 171688}'

See API_USAGE.md for complete integration examples with Python, JavaScript, LangChain, and OpenAI.

๐Ÿ›  MCP Tools Available

Once configured, Claude Desktop gets these nutrition tools:

  • search_foods - Search USDA database by text
  • get_food_nutrition - Get detailed nutrition for specific food
  • compare_foods - Compare nutrition between multiple foods

Example Claude Interaction

You: "Compare the protein content of chicken breast vs salmon"

Claude: Uses MCP tools automatically:

  1. search_foods("chicken breast") โ†’ Finds FDC ID 171077
  2. search_foods("salmon") โ†’ Finds FDC ID 175167
  3. compare_foods([171077, 175167]) โ†’ Gets comparison data
  4. Provides detailed analysis with recommendations

๐Ÿ— Architecture Deep Dive

Dual Server Design

Claude Desktop โ†โ†’ mcp_bridge.py โ†โ†’ HTTP API โ†โ†’ USDA FoodData Central
     (MCP)              โ†‘              โ†‘              โ†‘
                   Smart Bridge    FastAPI       Rate Limited
                                                   Client

Key Implementation Details:

  • src/mcp_server.py - FastMCP protocol server
  • src/mcp_http_server.py - FastAPI HTTP server
  • src/mcp_bridge.py - Smart bridge with server auto-detection
  • src/usda_client.py - API client with retry logic
  • src/models/ - Type-safe Pydantic schemas

Smart Bridge Logic

The bridge automatically detects server type and provides appropriate user feedback:

# Hosted service detection
if "usda-nutrition-mcp-oc46l7ob5a-uc.a.run.app" in args.server_url:
    print("๐ŸŒ Using hosted service (1,000 requests/hour shared)")

# Local development  
elif "localhost" in args.server_url:
    print("๐Ÿ  Using local server (requires your USDA API key)")

๐Ÿงช Testing Strategy

# Quick connectivity test
python test_quick.py

# Full test suite with mocking
python -m pytest tests/ -v

# Test specific MCP tools
python examples/live_demo.py

The test suite includes:

  • USDA API mocking with httpx-mock
  • Async MCP server testing
  • Integration test examples
  • Performance benchmarking

๐Ÿค Contributing

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Run tests: python -m pytest tests/
  4. Run linting: ruff check src/
  5. Submit pull request

๐Ÿ“„ License

MIT License - see LICENSE file for details.


๐ŸŽฏ Ready to use? See examples/configs/claude_desktop_config_examples.json for setup instructions!

๐Ÿ”— Live API: https://usda-nutrition-mcp-oc46l7ob5a-uc.a.run.app/docs