USDA Nutrition MCP Server
Access nutrition information for over 600,000 foods from the USDA FoodData Central database.
๐ฅ 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
๐ 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 textget_food_nutrition
- Get detailed nutrition for specific foodcompare_foods
- Compare nutrition between multiple foods
Example Claude Interaction
You: "Compare the protein content of chicken breast vs salmon"
Claude: Uses MCP tools automatically:
search_foods("chicken breast")
โ Finds FDC ID 171077search_foods("salmon")
โ Finds FDC ID 175167compare_foods([171077, 175167])
โ Gets comparison data- 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 serversrc/mcp_http_server.py
- FastAPI HTTP serversrc/mcp_bridge.py
- Smart bridge with server auto-detectionsrc/usda_client.py
- API client with retry logicsrc/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
- Fork the repository
- Create feature branch:
git checkout -b feature/amazing-feature
- Run tests:
python -m pytest tests/
- Run linting:
ruff check src/
- 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
Related Servers
MySQL MCP Server
Integrates with MySQL databases to provide secure database access for LLMs.
OpenTK
Provides access to Dutch parliamentary documents, debates, and member information from the Tweede Kamer via the OpenTK project.
RBDC MCP Server
An MCP-based database server with support for SQLite, MySQL, PostgreSQL, and MSSQL.
MySQL MCP Server
Enables secure interaction with MySQL databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.
Supabase
Connects to Supabase platform for database, auth, edge functions and more.
Poland KRS
Access to Polish National Court Register (KRS) โ the government's authoritative registry of all businesses, foundations, and other legal entities.
Databricks MCP Server
Interact with Databricks Unity Catalog metadata to explore catalogs, schemas, tables, and execute SQL queries.
Pinecone
Connect AI tools with Pinecone projects to search, configure indexes, generate code, and manage data.
Qixin API Service
Access comprehensive enterprise data from the Qixin Open Platform APIs.
Snowflake Stored Procedure Integration
Integrates and executes Snowflake stored procedures through an MCP server.