Food Data Central MCP Server

by jlfwong

食品数据中心 MCP 服务器

这是一个模型上下文协议 (MCP) 服务器,用于公开对美国农业部 FoodData Central API 的API 访问。

特征

  • 在美国农业部食品数据中心数据库中搜索食品
  • 获取食物营养信息
  • 分页结果
  • 支持多种数据类型(基础、SR Legacy、调查、品牌)

设置

  1. 克隆存储库
  2. 安装依赖项:
    npm install
  3. 构建项目:
    npm run build

运行服务器

该服务器使用 stdio 传输,这意味着它被设计为由 MCP 客户端作为子进程运行。要直接运行它:

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

对于使用热重载进行开发:

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

与 Claude Desktop 一起使用

要将此 MCP 服务器与 Claude Desktop 一起使用:

  1. 打开 Claude 桌面设置:
    • 在 macOS 上:单击 Claude 菜单并选择“设置...”
    • 在 Windows 上:单击 Claude 菜单并选择“设置...”
  2. 在“设置”窗格中,单击左侧栏中的“开发人员”,然后单击“编辑配置”
  3. 这将在以下位置创建或打开一个配置文件:
    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
  4. 将 Food Data Central MCP 服务器添加到配置文件:
    { "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>" } } } }
    /path/to/food-data-central-mcp-server替换为此存储库的绝对路径,并将<INSERT KEY HERE>替换为您的实际 USDA API 密钥。注意:如果您使用的是 Windows,则可能需要调整 PATH 值以包含您的 npm 全局安装目录。
  5. 保存配置文件并重新启动Claude Desktop
  6. 重启后,您应该会在输入框右下角看到一个锤子图标。点击它即可查看可用的工具。

现在,Claude 将能够通过此 MCP 服务器访问食品数据中心 API。您可以让 Claude 搜索食品、获取营养信息或检索详细的食品数据。

MCP 资源和工具

资源

  • food://details - 通过 ID 获取特定食物的详细信息
    • 查询参数:
      • fdcId :食品数据中心ID(必填)
      • format :可选。“abridged”表示元素集的缩写,“full”表示所有元素(默认)
      • nutrients :可选。最多 25 个营养素编号列表(以逗号分隔)
  • food://foods - 使用输入的 FDC ID 获取多种食品的详细信息
    • 查询参数:
      • fdcIds :多个 FDC ID 的列表(必需,以逗号分隔)
      • format :可选。“abridged”表示元素集的缩写,“full”表示所有元素(默认)
      • nutrients :可选。最多 25 个营养素编号列表(以逗号分隔)
  • food://list - 获取食物的分页列表
    • 查询参数:
      • dataType :可选。按特定数据类型进行过滤(逗号分隔列表)
      • pageSize :可选。返回的最大结果数(默认值:50)
      • pageNumber :可选。要检索的页码(默认值:1)
      • sortBy : 可选。排序依据字段
      • sortOrder :可选。排序顺序,"asc" 或 "desc"

工具

  • search-foods - 使用关键词搜索食物
    • 参数:
      • query :查找食物的搜索词(必填)
      • dataType :可选。按特定数据类型(字符串数组)进行过滤
      • pageSize :可选。返回的最大结果数(默认值:50)
      • pageNumber :可选。要检索的页码(默认值:1)
      • sortBy : 可选。排序依据字段
      • sortOrder :可选。排序顺序,"asc" 或 "desc"
      • brandOwner :可选。根据食品品牌所有者筛选结果(仅适用于品牌食品)
      • tradeChannel :可选。过滤包含指定贸易渠道的食品
      • startDate :可选。过滤在此日期及之后发布的食物(格式:YYYY-MM-DD)
      • endDate :可选。过滤在此日期或之前发布的食物(格式:YYYY-MM-DD)

示例用法

使用 MCP 资源获取食物详细信息:

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

使用 MCP 资源获取多种食物:

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

使用 MCP 资源获取食物列表:

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

使用 MCP 工具搜索食物:

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

模型上下文协议服务器使 Claude 能够从美国农业部的 FoodData Central 数据库搜索和访问详细的营养信息。

  1. Features
    1. Setup
      1. Running the Server
        1. Using with Claude Desktop
          1. MCP Resources and Tools
            1. Resources
            2. Tools
          2. Example Usage

            Related MCP Servers

            • -
              security
              F
              license
              -
              quality
              A Model Context Protocol server that allows Claude to query the Untappd beer database API for searching beers and retrieving detailed beer information.
              Last updated -
              JavaScript
              • Apple
            • A
              security
              F
              license
              A
              quality
              A Model Context Protocol server that provides tools to search and retrieve economic data series from the Federal Reserve Economic Data (FRED) API.
              Last updated -
              2
              3
              TypeScript
            • A
              security
              A
              license
              A
              quality
              A Model Context Protocol server that interfaces with Biomart databases, allowing models to discover biological datasets, explore attributes/filters, retrieve biological data, and translate between different biological identifiers.
              Last updated -
              8
              Python
              MIT License
              • Apple
              • Linux
            • -
              security
              F
              license
              -
              quality
              A Model Context Protocol server that provides language models with access to personal Whoop fitness data, allowing queries for cycles, recovery, strain, and workout information from the Whoop API.
              Last updated -
              2
              Python
              • Apple

            View all related MCP servers

            ID: zn2oskz5zq