USDA Nutrition MCP Server
Provides access to USDA FoodData Central database, enabling food search, nutrition details, and comparison for dietary analysis via MCP.
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
🌟 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
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。