FoodDB - USDA Food Database MCP Server
An MCP server for querying USDA Food Data Central information. It provides tools to search for foods and get detailed nutritional information.
Note: This project was 100% created with Claude AI. No human has directly edited any code files. All development was done through AI-assisted programming.
Data Source
To use this project, you'll need to download the USDA Food Data Central dataset:
- Visit USDA FDC Download Datasets
- Download the "Full Download" package
- Extract the CSV files to the
./datadirectory in this project
Features
- Import USDA Food Data Central CSV files into a SQLite database
- Model Context Protocol (MCP) server for integration with Claude for Desktop and other MCP clients
- Smart keyword-based search for food items
- Semantic vector search using OpenAI embeddings
- Comprehensive nutritional data including calories, macros, and serving sizes
Installation
# Install in development mode
uv pip install -e .
Usage
Initialize the Database
Before using the server, you need to import the USDA data:
# Import data from the default location (./data) with embeddings generation
uv run food init-db
# Custom data and database paths
uv run food init-db --data-dir /path/to/data --db-path custom.sqlite
# Skip embeddings generation
uv run food init-db --no-embeddings
Generate Embeddings
If you need to generate or update embeddings for vector search:
# Generate ALL embeddings for foods that don't have them yet
uv run food generate-embeddings
# Process foods in larger batches (default is 1000)
uv run food generate-embeddings --batch-size 5000
For vector search to work, you need to set the OPENAI_API_KEY environment variable:
export OPENAI_API_KEY=your-api-key
Search for Foods
You can search for foods using the CLI:
# Search for foods matching a query
uv run food search "ice cream" --limit 5
Get Food Information
Get detailed information about a specific food by its ID:
# Display detailed nutrition information for a food
uv run food info 167575
Run the MCP Server
Run the server with the stdio transport (for use with Claude Desktop):
uv run food run-server
Or with the HTTP transport for other clients:
uv run food run-server --transport http --port 8000
Integrating with Claude for Desktop
To use this server with Claude for Desktop, add it to your Claude Desktop configuration at ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"fooddb": {
"command": "uv",
"args": [
"--directory",
"/path/to/fooddb",
"run",
"food",
"run-server"
],
"env": {
"OPENAI_API_KEY": "your-openai-api-key-here"
}
}
}
}
Important:
- Replace
/path/to/fooddbwith the absolute path to your fooddb installation - Replace
your-openai-api-key-herewith your actual OpenAI API key - The
envsection is required for vector search functionality - Without a valid OpenAI API key, only basic text matching searches will work
MCP Tools
The server provides the following MCP tools:
food_search
Search for foods using semantic vector search via embeddings. This can find foods that match the concept even if they don't contain the exact keywords.
food_search(query: str, limit: int = 10, model: str = "text-embedding-3-small") -> List[Dict]
food_info
Get detailed information about a specific food by ID, including nutritional content, portions, and brand information.
food_info(food_id: int) -> str
Development
Running Tests
uv run pytest
Linting
uv run ruff check .
Data Structure
The USDA Food Data Central dataset includes:
- Food: Basic food information (name, category, etc.)
- Nutrient: Definitions of nutrients (calories, protein, etc.)
- FoodNutrient: Mapping of foods to their nutrient values
- FoodPortion: Serving size information for foods
- FoodEmbeddings: Vector embeddings for semantic search
Vector Search
The system uses OpenAI's text-embedding-3-small model to generate vector embeddings for food descriptions. These embeddings are stored in the SQLite database using the sqlite-vec extension, which enables efficient similarity searches.
For vector search functionality:
- Make sure the sqlite-vec extension is installed and available
- Set the OPENAI_API_KEY environment variable
- Generate embeddings during database initialization or with the generate-embeddings command
- Use the semantic_food_search MCP tool for natural language food searches
Recommend MCP Servers 💡
linear-mcp-server
A server that integrates Linear's project management system with the Model Context Protocol (MCP) to allow LLMs to interact with Linear.
ai-agent-marketplace-index-mcp
An MCP server that allows AI assistants to search and discover available AI agents from the DeepNLP AI Agent Marketplace Index by keywords or categories, and monitor their web traffic performance.
brian3814/notion_fastmcp
A MCP server that integrates with Notion to manage and retrieve tasks.
netdata
Netdata's MCP server enables AI assistants to access infrastructure monitoring data (metrics, logs, alerts, live system info) for DevOps/SRE tasks.
deebo
Autonomous debugging agent MCP server that helps AI coding agents debug by launching automated investigations, speeding up time-to-resolution by 10x
NeoCoder-neo4j-ai-workflow
An MCP server that enables AI assistants to use Neo4j knowledge graphs and Qdrant vector databases for hybrid reasoning and workflow management.