FoodData Central MCP server

Provides access to the USDA's FoodData Central database for searching foods and retrieving detailed nutritional information to support meal planning and dietary analysis.
Back to servers
Setup instructions
Provider
Jamie Wong
Release date
Apr 07, 2025
Language
TypeScript
Stats
5 stars

This MCP server provides access to the USDA's FoodData Central API, allowing you to search for foods and retrieve detailed nutrient information through Model Context Protocol. It's designed to be integrated with AI assistant applications like Claude Desktop.

Installation

Prerequisites

To use this server, you'll need:

Setup Steps

  1. Clone the repository
  2. Install dependencies:
    npm install
    
  3. Build the project:
    npm run build
    

Running the Server

The server uses stdio transport, meaning it's designed to be run as a subprocess by an MCP client. To run it directly:

# Set the USDA API key as an environment variable
export USDA_API_KEY=your-api-key-here
npm start

For development with hot reloading:

# Set the USDA API key as an environment variable
export USDA_API_KEY=your-api-key-here
npm run dev

Integrating with Claude Desktop

Configuration Steps

  1. Open the Claude Desktop settings:

    • On macOS: Claude menu → "Settings..."
    • On Windows: Claude menu → "Settings..."
  2. Click on "Developer" in the left sidebar, then "Edit Config"

  3. Add the Food Data Central MCP server to the configuration file:

    {
      "mcpServers": {
        "food-data-central": {
          "command": "npx",
          "args": ["tsx", "/path/to/food-data-central-mcp-server/src/index.ts"],
          "env": {
            "PATH": "/opt/homebrew/bin",
            "USDA_API_KEY": "<INSERT KEY HERE>"
          }
        }
      }
    }
    

    Be sure to:

    • Replace /path/to/food-data-central-mcp-server with the absolute path to the repository
    • Add your actual USDA API key in place of <INSERT KEY HERE>
    • Adjust the PATH value for your system if needed (especially on Windows)
  4. Save the configuration file and restart Claude Desktop

  5. After restarting, you should see a hammer icon in the bottom right corner of the input box, which indicates access to the available tools.

Available Resources and Tools

Resources

  • food://details - Get detailed information about a specific food

    • Parameters:
      • fdcId: Food Data Central ID (required)
      • format: Optional. 'abridged' or 'full' (default)
      • nutrients: Optional. List of up to 25 nutrient numbers (comma-separated)
  • food://foods - Get details for multiple food items

    • Parameters:
      • fdcIds: List of multiple FDC IDs (required, comma-separated)
      • format: Optional. 'abridged' or 'full' (default)
      • nutrients: Optional. List of up to 25 nutrient numbers (comma-separated)
  • food://list - Get a paged list of foods

    • Parameters:
      • dataType: Optional. Filter on specific data types (comma-separated)
      • pageSize: Optional. Maximum results to return (default: 50)
      • pageNumber: Optional. Page number to retrieve (default: 1)
      • sortBy: Optional. Field to sort by
      • sortOrder: Optional. Sort order, "asc" or "desc"

Tools

  • search-foods - Search for foods using keywords
    • Parameters:
      • query: Search terms to find foods (required)
      • dataType: Optional. Filter on specific data types (array)
      • pageSize: Optional. Maximum results to return (default: 50)
      • pageNumber: Optional. Page number to retrieve (default: 1)
      • sortBy: Optional. Field to sort by
      • sortOrder: Optional. Sort order, "asc" or "desc"
      • brandOwner: Optional. Filter by brand owner (Branded Foods only)
      • tradeChannel: Optional. Filter by trade channels
      • startDate: Optional. Filter by publish date (YYYY-MM-DD)
      • endDate: Optional. Filter by publish date (YYYY-MM-DD)

Usage Examples

Accessing Food Details

To get information for a specific food item:

food://details?fdcId=2345678&format=full

Retrieving Multiple Foods

To get details for several foods at once:

food://foods?fdcIds=534358,373052,616350

Listing Foods

To get a list of foods with pagination:

food://list?dataType=Foundation,SR Legacy&pageSize=10&pageNumber=1

Searching Foods

To search for foods using the MCP tool:

{
  "name": "search-foods",
  "arguments": {
    "query": "apple",
    "dataType": ["Foundation", "SR Legacy"],
    "pageSize": 10,
    "pageNumber": 1
  }
}

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "food-data-central" '{"command":"npx","args":["tsx","/path/to/food-data-central-mcp-server/src/index.ts"],"env":{"PATH":"/opt/homebrew/bin","USDA_API_KEY":"<INSERT KEY HERE>"}}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "food-data-central": {
            "command": "npx",
            "args": [
                "tsx",
                "/path/to/food-data-central-mcp-server/src/index.ts"
            ],
            "env": {
                "PATH": "/opt/homebrew/bin",
                "USDA_API_KEY": "<INSERT KEY HERE>"
            }
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "food-data-central": {
            "command": "npx",
            "args": [
                "tsx",
                "/path/to/food-data-central-mcp-server/src/index.ts"
            ],
            "env": {
                "PATH": "/opt/homebrew/bin",
                "USDA_API_KEY": "<INSERT KEY HERE>"
            }
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later