Food Data Central MCP Server

Food Data Central MCP Server

Enables AI agents to search the USDA's FoodData Central database and retrieve detailed nutritional information and ingredient lists. It supports comprehensive food data access through keyword searches and structured queries for specific food items.

Category
访问服务器

README

<h1 align="center">Food Data Central MCP Server</h1>

A Model Context Protocol (MCP) server for accessing the USDA's FoodData Central database. This server provides AI agents with the ability to search for foods, get detailed nutritional information, and access comprehensive food data from the USDA's database.

Overview

This project demonstrates how to build an MCP server that enables AI agents to access the USDA FoodData Central API. It allows searching for foods, retrieving detailed nutritional information, and accessing comprehensive food data through keyword search and structured queries.

This project is based on Cole Medin's excellent MCP-Mem0 project and jlfwong's Food Data Central MCP Server.

Features

The server provides three essential food data access tools:

  1. search_foods: Search for foods using keywords with optional filters for data type, brand, date range, etc.
  2. get_food_details: Get comprehensive nutritional and ingredient information for a specific food item by FDC ID
  3. get_multiple_foods: Retrieve detailed information for multiple foods at once (up to 20 items)

Prerequisites

  • Python 3.12+
  • USDA API key (free from FoodData Central)
  • Docker if running the MCP server as a container (recommended)

Installation

Using uv

  1. Install uv if you don't have it:

    pip install uv
    
  2. Clone this repository:

    git clone https://github.com/FelipeAdachi/mcp-food-data-central.git
    cd food-data-central-mcp
    
  3. Create a virtual environment:

    uv venv
    
  4. Install dependencies:

    uv pip install -e .
    
  5. Create a .env file based on env.example:

    cp env.example .env
    
  6. Configure your environment variables in the .env file (see Configuration section)

Using Docker (Recommended)

  1. Build the Docker image:

    docker build -t food-data-central-mcp --build-arg PORT=8050 .
    
  2. Create a .env file based on env.example and configure your environment variables

Configuration

The following environment variables can be configured in your .env file:

Variable Description Example
USDA_API_KEY Your USDA FoodData Central API key your_api_key_here
TRANSPORT Transport protocol (sse or stdio) sse
HOST Host to bind to when using SSE transport 0.0.0.0
PORT Port to listen on when using SSE transport 8050

Getting Your API Key

  1. Visit the USDA FoodData Central API Guide
  2. Sign up for a free API key
  3. Add the key to your .env file as USDA_API_KEY

Running the Server

Using uv

SSE Transport

# Set TRANSPORT=sse in .env then:
uv run src/main.py

The MCP server will essentially be run as an API endpoint that you can then connect to with config shown below.

Stdio Transport

With stdio, the MCP client itself can spin up the MCP server, so nothing to run at this point.

Using Docker

SSE Transport

docker run --env-file .env -p 8050:8050 food-data-central-mcp

The MCP server will essentially be run as an API endpoint within the container that you can then connect to with config shown below.

Stdio Transport

With stdio, the MCP client itself can spin up the MCP server container, so nothing to run at this point.

Integration with MCP Clients

SSE Configuration

Once you have the server running with SSE transport, you can connect to it using this configuration:

{
  "mcpServers": {
    "food-data-central": {
      "transport": "sse",
      "url": "http://localhost:8050/sse"
    }
  }
}

Note for Windsurf users: Use serverUrl instead of url in your configuration:

{
  "mcpServers": {
    "food-data-central": {
      "transport": "sse",
      "serverUrl": "http://localhost:8050/sse"
    }
  }
}

Note for n8n users: Use host.docker.internal instead of localhost since n8n has to reach outside of its own container to the host machine:

So the full URL in the MCP node would be: http://host.docker.internal:8050/sse

Make sure to update the port if you are using a value other than the default 8050.

Python with Stdio Configuration

Add this server to your MCP configuration for Claude Desktop, Windsurf, or any other MCP client:

{
  "mcpServers": {
    "food-data-central": {
      "command": "your/path/to/food-data-central-mcp/.venv/Scripts/python.exe",
      "args": ["your/path/to/food-data-central-mcp/src/main.py"],
      "env": {
        "TRANSPORT": "stdio",
        "USDA_API_KEY": "YOUR-API-KEY"
      }
    }
  }
}

Docker with Stdio Configuration

{
  "mcpServers": {
    "food-data-central": {
      "command": "docker",
      "args": ["run", "--rm", "-i", 
               "-e", "TRANSPORT", 
               "-e", "USDA_API_KEY", 
               "food-data-central-mcp"],
      "env": {
        "TRANSPORT": "stdio",
        "USDA_API_KEY": "YOUR-API-KEY"
      }
    }
  }
}

Usage Examples

Searching for Foods

# Search for cheese products
search_foods(query="cheddar cheese", page_size=10)

# Search for branded foods from a specific company
search_foods(query="yogurt", data_type=["Branded"], brand_owner="Dannon")

# Search with date filtering
search_foods(query="organic apple", start_date="2023-01-01", end_date="2023-12-31")

Getting Food Details

# Get full details for a specific food item
get_food_details(fdc_id=534358)

# Get abridged details with specific nutrients only
get_food_details(fdc_id=534358, format_type="abridged", nutrients=[203, 204, 205])

Getting Multiple Foods

# Get details for multiple foods at once
get_multiple_foods(fdc_ids=[534358, 373052, 616350])

API Reference

The server provides access to the USDA FoodData Central API endpoints:

  • Search Foods (/v1/foods/search)
  • Food Details (/v1/food/{fdcId})
  • Multiple Foods (/v1/foods)

All data returned follows the official USDA FoodData Central API schema and includes comprehensive nutritional information, ingredients, serving sizes, and more.

License

This project is licensed under the MIT License - see the LICENSE file for details.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选