usda-fdc-mcp

usda-fdc-mcp

MCP server that provides food composition data from USDA FoodData Central, enabling search, nutrient lookups, and recipe nutrition calculations.

Category
访问服务器

README

usda-fdc-mcp

A stdio MCP server that answers food composition questions from USDA FoodData Central.

What it does

The server exposes four tools over the Model Context Protocol.

Tool Purpose
search_foods Search foods by name. Returns the FDC ID, description, data type, and a macro-completeness flag.
get_food Return the nutrient panel for one FDC ID, scaled to a gram amount.
food_nutrition Search and scale in one call. Prefers a record with a complete macro panel.
recipe_nutrition Sum an ingredient list into per-serving totals with a per-ingredient breakdown.

FoodData Central reports every amount per 100 g. The server scales each amount to the grams that you request. The percent Daily Value uses the FDA adult values in 21 CFR 101.9.

Nutrient identifiers

FoodData Central gives each nutrient two identifiers. The modern nutrientId for protein is 1003. The legacy NDB nutrientNumber for protein is "203". A filter on the wrong identifier returns an empty nutrient table and no error. The server keys on nutrientId in every code path.

Response shapes

The two endpoints put nutrient values in different fields.

/foods/search  ->  [{ nutrientId: 1003, value: 16.5 }]
/food/{id}     ->  [{ nutrient: { id: 1003 }, amount: 16.5 }]

The server normalizes both shapes. Results from either endpoint are interchangeable.

Alias identifiers

A nutrient can arrive under a different identifier in a different data type. The value then reads as missing. The server resolves three known cases.

  • Foundation cashews carry energy as Atwater factors under 2048. The canonical energy identifier is 1008.
  • SR Legacy flaxseed carries omega-3 under the general PUFA 18:3 identifier 1270. The ALA-specific identifier is 1404.
  • Foundation raisins carry sugars under 1063. SR Legacy records use 2000.

Requirements

  • Node.js 20 or later.
  • An internet connection for live lookups.
  • A FoodData Central API key. Read the API key section below.

Install

npm install
npm run build

Configuration

API key

The server reads the key from the USDA_FDC_API_KEY environment variable. The server falls back to DEMO_KEY when that variable is absent.

DEMO_KEY is the shared key that USDA publishes. It allows about 30 requests per hour for each IP address. Use DEMO_KEY for light testing only.

Get a free personal key at https://fdc.nal.usda.gov/api-key-signup. A personal key allows 1,000 requests per hour.

Pass the key through the environment. Do not commit the key to a file.

Cache

The server writes every response to a disk cache at ~/.cache/usda-fdc-mcp. Set USDA_FDC_CACHE_DIR to move the cache. A cached food still answers after you reach the rate limit.

MCP client

Add the server to your MCP client configuration. Replace /path/to/usda-fdc-mcp with the path to your own clone.

{
  "mcpServers": {
    "usda-fdc": {
      "command": "node",
      "args": ["/path/to/usda-fdc-mcp/dist/index.js"],
      "env": {
        "USDA_FDC_API_KEY": "your_key_here"
      }
    }
  }
}

Usage

A name search can return a neighbouring food

search_foods ranks its results by relevance. It returns a plausible food when the exact food falls outside the result order. It reports no error in that case.

A query for raisins seedless returns golden raisins (168164) before dark seedless raisins (168165). The two records differ by nearly half on iron. Golden raisins hold 0.98 mg per 100 g. Dark seedless raisins hold 1.79 mg per 100 g.

Read the description field on each hit before you use the numbers. Call get_food with a known FDC ID when the exact food matters.

Ingredients that FoodData Central does not hold

FoodData Central holds few supplement powders and few branded products. Pass such an item through manual_items. Take its figures from the product label or from published literature.

{
  "items": [
    { "query": "bananas raw", "grams": 118, "label": "1 medium banana" },
    { "query": "seeds hemp seed hulled", "grams": 30 }
  ],
  "manual_items": [
    { "label": "whey isolate, 1 scoop", "nutrients": { "energy_kcal": 120, "protein_g": 30 } }
  ],
  "servings": 1
}

Source citation

Every get_food result carries a source string.

USDA FoodData Central, FDC ID 170554 (SR Legacy), https://fdc.nal.usda.gov/food-details/170554

Quote that string when you publish a nutrition figure. The figure then stays traceable to its source record.

Tests

Run the offline test. It needs no network access and no API quota.

npm test

The offline test replays four cached FoodData Central records from test/fixtures. It asserts that each alias case resolves to the correct number.

Run the smoke test to check the live API contract. It consumes API quota.

npm run smoke

The smoke test confirms that both endpoint shapes parse to the same numbers. It confirms that gram scaling is linear. It confirms that the percent Daily Value and the source string are populated.

Development

npm run dev     # run the server from source through tsx
npm run build   # compile TypeScript into dist/
npm start       # run the compiled server

Licence

Licensed under the PolyForm Noncommercial License 1.0.0. Copyright 2026 Seraphine Renard.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选