USDA Nutrition MCP Server

USDA Nutrition MCP Server

Provides access to USDA FoodData Central database, enabling food search, nutrition details, and comparison for dietary analysis via MCP.

Category
Visit Server

README

๐Ÿฅ— 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

License: MIT Python 3.11+ MCP Compatible Hosted Service

๐ŸŒŸ 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

๐Ÿš€ Quick Start for Claude Desktop

Option 1: Minimal Installation (Recommended)

Download just the bridge file - no need to clone the entire repository:

# Download the bridge
wget https://raw.githubusercontent.com/zen-apps/mcp-nutrition-tools/main/src/mcp_bridge.py

# Install dependencies
pip install mcp httpx

Then add to your Claude Desktop config:

{
  "mcpServers": {
    "usda-nutrition": {
      "command": "python3",
      "args": ["/path/to/downloaded/mcp_bridge.py"]
    }
  }
}

Mac Users with Virtual Environment

# Navigate to your project
cd /Users/yourusername/your-project-folder

# Create new venv in the project folder
python3 -m venv venv

# Activate it
source venv/bin/activate

# Install dependencies
pip install mcp httpx

# Test it works
python src/mcp_bridge.py --server-url https://usda-nutrition-mcp-356272800218.us-central1.run.app

Option 2: Full Repository (For Development)

{
  "mcpServers": {
    "usda-nutrition": {
      "command": "python3",
      "args": ["/path/to/mcp-nutrition-tools/src/mcp_bridge.py"],
      "cwd": "/path/to/mcp-nutrition-tools"
    }
  }
}

Option 2: Local Development

{
  "mcpServers": {
    "usda-nutrition": {
      "command": "python3",
      "args": [
        "/path/to/mcp-nutrition-tools/src/mcp_bridge.py",
        "--server-url",
        "http://localhost:8080"
      ],
      "cwd": "/path/to/mcp-nutrition-tools"
    }
  }
}

Option 3: Custom Server

{
  "mcpServers": {
    "usda-nutrition": {
      "command": "python3", 
      "args": [
        "/path/to/mcp-nutrition-tools/src/mcp_bridge.py",
        "--server-url",
        "https://your-server.com"
      ],
      "cwd": "/path/to/mcp-nutrition-tools"
    }
  }
}

See examples/configs/claude_desktop_config_examples.json for detailed configuration examples.

๐Ÿ”ง 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)")

๐Ÿ“ฆ Installation & Development

# Clone and setup
git clone https://github.com/zen-apps/mcp-nutrition-tools
cd mcp-nutrition-tools
pip install -r requirements.txt

# Get USDA API key (for local development)
# Visit: https://fdc.nal.usda.gov/api-guide.html
echo "FDC_API_KEY=your_key_here" > .env

# Test MCP server
python -m src.mcp_server

# Test HTTP server  
python -m src.mcp_http_server

# Run tests
python -m pytest tests/ -v

# Code quality
ruff check src/
ruff format src/
mypy src/

๐Ÿณ Deployment Options

Local Development

# Run HTTP server locally
python -m src.mcp_http_server

# Run with Docker
make up

Production Deployment

# Deploy to Google Cloud Run
export FDC_API_KEY="your_usda_key"
./scripts/deploy-gcp.sh

The production deployment includes:

  • Automatic SSL/HTTPS
  • Health checks and monitoring
  • Auto-scaling based on demand
  • Structured logging

๐Ÿ”‘ Configuration

Environment Variables

  • FDC_API_KEY - USDA FoodData Central API key (required for local)
  • ENVIRONMENT - "development" or "production"
  • LOG_LEVEL - Logging level (DEBUG, INFO, etc.)

Rate Limits

  • Hosted Service: 1,000 requests/hour (shared)
  • Local Deployment: 1,000 requests/hour (your key)
  • Enterprise: Contact for higher limits

๐Ÿงช 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

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured