usda-mcp-server
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@usda-mcp-servercompare calcium in milk and cheese"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Tools
Five tools covering the USDA FoodData Central workflow — from discovery to detailed nutrient analysis:
Tool | Description |
| Search foods by keyword across SR Legacy, Foundation, Survey FNDDS, and Branded data sources, with nutrient preview and pagination |
| Full nutrient profile for one food by FDC ID, with optional per-portion scaling (g, oz, lb, kg, or serving) |
| Batch nutrient fetch for 2–20 FDC IDs in a single request; failed IDs reported in |
| Side-by-side nutrient comparison for 2–5 foods, formatted as a markdown table scaled to a common gram basis |
| Static FDC nutrient reference table (~150 nutrients) with IDs, names, units, and categories — no API call required |
usda_search_foods
Search USDA FoodData Central foods by keyword, UPC/GTIN code, or ingredient.
Covers all FDC data sources: SR Legacy (common whole foods, complete nutrient profiles), Foundation, Survey FNDDS, and Branded (packaged products)
Defaults to SR Legacy; include
"Branded"indataTypefor packaged products or UPC lookupBrand owner filter to narrow branded results (e.g.
"General Mills")Food category filter (e.g.
"Poultry Products","Vegetables and Vegetable Products")Pagination via
pageSize(up to 50) andpageNumberReturns FDC IDs and a preview of key nutrients (energy, protein, fat, carbs) — use
usda_get_foodfor the full profile
usda_get_food
Full nutrient profile for one food by FDC ID.
All available nutrients (or a filtered subset via
nutrients[]) with amounts per 100gOptional portion scaling — provide
quantity+unitto scale values (e.g.quantity=200, unit="g"→ per-200g values)unit="serving"scales to the food's first defined portion weightReturns all named portion definitions (
allPortions[]) alongside the serving infoFiltering
nutrients[]to specific IDs strongly reduces context size for common queries (useusda_list_nutrientsto look up IDs)
usda_get_foods
Batch nutrient fetch for 2–20 FDC IDs.
All values per 100g (no portion scaling in batch mode)
nutrients[]filter strongly recommended — full profiles for 20 foods are largePer-item partial failure:
failed[]carries IDs that returned no data, so one missing food doesn't abort the batchMore efficient than N individual
usda_get_foodcalls when you already have FDC IDs
usda_compare_foods
Side-by-side nutrient comparison for 2–5 foods.
Returns a pivot table — one row per nutrient, one column per food — and formats it as a markdown table
Defaults to the 12 most commonly compared nutrients (energy, protein, fat, saturated fat, carbs, fiber, sugars, sodium, potassium, calcium, iron, vitamin C)
Pass custom
nutrients[]for specific comparisons (e.g. just iron and vitamin C)All values scaled to a common gram basis (default 100g; override with
quantity+unit)Proceeds with valid foods when some IDs aren't found — only fails when fewer than 2 IDs return data
Rows where all values are null (nutrient not tracked for any of the selected foods) are filtered out
usda_list_nutrients
FDC nutrient reference table — all ~150 tracked nutrients.
Returns IDs, names, SR reference numbers, units, and categories
Optional
categoryfilter:macronutrients,vitamins,minerals,lipids,amino_acids,otherResolves nutrient names (e.g.
"vitamin C") to FDC IDs (1162) for use innutrients[]paramsStatic data — no API call, instant response; call once and reuse the IDs
Related MCP server: nutrition-mcp-server
Resources and prompts
Type | Name | Description |
Resource |
| Full nutrient profile for a specific food by FDC ID — same data as |
Resource |
| Complete FDC nutrient reference list — all ~150 tracked nutrients with IDs, names, units, and categories |
All resource data is also reachable via tools. Use usda_search_foods to discover FDC IDs before reading food resources.
Features
Built on @cyanheads/mcp-ts-core:
Declarative tool and resource definitions — single file per primitive, framework handles registration and validation
Unified error handling — handlers throw, framework catches, classifies, and formats
Pluggable auth:
none,jwt,oauthSwappable storage backends:
in-memory,filesystem,Supabase,Cloudflare KV/R2/D1Structured logging with optional OpenTelemetry tracing
STDIO and Streamable HTTP transports
USDA FDC-specific:
Type-safe client for the USDA FoodData Central REST API (
api.nal.usda.gov/fdc/v1)Normalization layer that handles inconsistent API response shapes across search, single-food, and batch endpoints
Batch API endpoint (
/foods) with per-food partial failure reportingHTML response detection (rate-limit proxy returns 200 HTML) with service-unavailable error surfacing
Static nutrient reference dictionary — ~150 nutrients with FDC IDs, SR numbers, units, and categories; no API call required
Agent-friendly output:
Provenance preserved — FDC data source (
dataType) on every food result so callers know whether they're reading curated research data or label-derived branded valuesPartial failure reporting — batch tools (
usda_get_foods,usda_compare_foods) return successes alongside structuredfailed[]/missingData[]entries rather than failing the whole requestCross-reference hints — FDC IDs and tool names in descriptions so agents know exactly which call to make next (search → get → compare workflow)
Getting started
Add the following to your MCP client configuration file. See data.gov API key signup to generate a free API key.
{
"mcpServers": {
"usda-mcp-server": {
"type": "stdio",
"command": "bunx",
"args": ["@cyanheads/usda-mcp-server@latest"],
"env": {
"MCP_TRANSPORT_TYPE": "stdio",
"MCP_LOG_LEVEL": "info",
"USDA_FDC_API_KEY": "your-api-key"
}
}
}
}Or with npx (no Bun required):
{
"mcpServers": {
"usda-mcp-server": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@cyanheads/usda-mcp-server@latest"],
"env": {
"MCP_TRANSPORT_TYPE": "stdio",
"MCP_LOG_LEVEL": "info",
"USDA_FDC_API_KEY": "your-api-key"
}
}
}
}Or with Docker:
{
"mcpServers": {
"usda-mcp-server": {
"type": "stdio",
"command": "docker",
"args": [
"run", "-i", "--rm",
"-e", "MCP_TRANSPORT_TYPE=stdio",
"-e", "USDA_FDC_API_KEY=your-api-key",
"ghcr.io/cyanheads/usda-mcp-server:latest"
]
}
}
}For Streamable HTTP, set the transport and start the server:
MCP_TRANSPORT_TYPE=http MCP_HTTP_PORT=3010 USDA_FDC_API_KEY=your-api-key bun run start:http
# Server listens at http://localhost:3010/mcpPrerequisites
Bun v1.3.2 or higher (or Node.js v24+).
A free USDA FDC API key — register at api.data.gov/signup. The key is required; without it the server will not start.
Installation
Clone the repository:
git clone https://github.com/cyanheads/usda-mcp-server.gitNavigate into the directory:
cd usda-mcp-serverInstall dependencies:
bun installConfigure environment:
cp .env.example .env
# edit .env and set USDA_FDC_API_KEYConfiguration
Variable | Description | Default |
| Required. USDA FoodData Central API key from api.data.gov. | — |
| Transport: |
|
| Port for HTTP server. |
|
| Auth mode: |
|
| Log level (RFC 5424). |
|
| Directory for log files (Node.js only). |
|
| Storage backend. |
|
| Enable OpenTelemetry instrumentation (spans, metrics, completion logs). |
|
See .env.example for the full list of optional overrides.
Running the server
Local development
Build and run:
# One-time build bun run rebuild # Run the built server bun run start:stdio # or bun run start:httpRun checks and tests:
bun run devcheck # Lint, format, typecheck, security bun run test # Vitest test suite bun run lint:mcp # Validate MCP definitions against spec
Docker
docker build -t usda-mcp-server .
docker run --rm -e USDA_FDC_API_KEY=your-key -p 3010:3010 usda-mcp-serverThe Dockerfile defaults to HTTP transport, stateless session mode, and logs to /var/log/usda-mcp-server. OpenTelemetry peer dependencies are installed by default — build with --build-arg OTEL_ENABLED=false to omit them.
Project structure
Directory | Purpose |
|
|
| Server-specific environment variable parsing and validation with Zod ( |
| Tool definitions ( |
| Resource definitions ( |
|
|
| Unit tests mirroring |
Development guide
See CLAUDE.md for development guidelines and architectural rules. The short version:
Handlers throw, framework catches — no
try/catchin tool logicUse
ctx.logfor request-scoped logging,ctx.statefor tenant-scoped storageRegister new tools and resources via the barrels in
src/mcp-server/*/definitions/index.tsWrap external API calls: validate raw → normalize to domain type → return output schema; never fabricate missing fields
Contributing
Issues and pull requests are welcome. Run checks and tests before submitting:
bun run devcheck
bun run testLicense
Apache-2.0 — see LICENSE for details.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/cyanheads/usda-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server