使用说明
🥗 FatSecret MCP服务器
A. 模型上下文协议(MCP) 服务器 FatSecret平台API.将任何兼容MCP的LLM(Claude、GPT-4、Cursor、Continue等)直接连接到FatSecret的营养数据库和食物记录功能。
特性
| 工具 | 描述 | 身份验证 |
|---|---|---|
search_foods |
按名称搜索FatSecret食品数据库 | OAuth 2.0 |
get_food |
获取特定食物的完整营养信息(所有份量+微量) | OAuth 2.0 |
search_recipes |
使用卡路里/宏过滤器搜索食谱 | OAuth 2.0 |
get_food_entries |
阅读任何日期的日记条目 | OAuth 1.0 |
add_food_entry |
将食物记录到日记中 | OAuth 1.0 |
get_daily_nutrition |
从日记汇总的每日宏/卡路里总量 | OAuth 1.0 |
get_month_of_statistics |
整个月的每日营养统计 | OAuth 1.0 |
注: 标记的工具 OAuth 1.0 需要额外的用户级令牌(请参见 获取用户令牌).三人 OAuth 2.0 这些工具仅适用于您的应用程序凭据。
快速开始
1.获取API凭据
- 注册地址: platform.fatsecret.com
- 创建一个应用程序来接收您的 客户端ID 和 客户端密钥
2.安装和构建
# Clone the repo
git clone https://github.com/YOUR_USERNAME/fatsecret-mcp.git
cd fatsecret-mcp
# Install dependencies
npm install
# Build TypeScript
npm run build
3.配置凭据
cp .env.example .env
# Edit .env and fill in your credentials
4.测试它
# Quick sanity check — search for "apple"
echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"search_foods","arguments":{"query":"apple"}}}' \
| FATSECRET_CLIENT_ID=xxx FATSECRET_CLIENT_SECRET=yyy node dist/index.js
Claude桌面配置
将此添加到您的Claude Desktop配置文件中:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
窗户: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"fatsecret": {
"command": "node",
"args": ["/absolute/path/to/fatsecret-mcp/dist/index.js"],
"env": {
"FATSECRET_CLIENT_ID": "your_client_id",
"FATSECRET_CLIENT_SECRET": "your_client_secret",
"FATSECRET_ACCESS_TOKEN": "your_access_token",
"FATSECRET_ACCESS_TOKEN_SECRET": "your_access_token_secret"
}
}
}
}
或者,如果你更喜欢使用 .env 文件和 npx:
{
"mcpServers": {
"fatsecret": {
"command": "npx",
"args": ["fatsecret-mcp"],
"env": {
"FATSECRET_CLIENT_ID": "your_client_id",
"FATSECRET_CLIENT_SECRET": "your_client_secret"
}
}
}
}
编辑配置后,重新启动Claude Desktop。您应该在Claude的工具面板中看到FatSecret工具。
工具参考
search_foods
搜索FatSecret食品数据库。
参数:
| 参数 | 类型 | 必填 | 默认 | 说明 |
|---|---|---|---|---|
query |
string | ✅ | — | 搜索词(例如。 "chicken breast") |
max_results |
编号 | 10 |
每页显示结果(1-50) | |
page_number |
编号 | 0 |
从零开始的页面索引 | |
food_type |
"generic" |
"brand" |
"all" |
|
region |
string | -- | ISO 3166-1 alpha-2代码(例如。 "US") |
示例提示: “搜索烤三文鱼,给我看看卡路里”
get_food
获取食品的完整营养数据。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
food_id |
string | ✅ | FatSecret食品ID(来自 search_foods) |
flag_default_serving |
boolean | 突出显示默认服务(默认 true) |
示例提示: “获取食品ID 35718的完整营养信息”
search_recipes
搜索FatSecret的食谱集。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
query |
string | 搜索词(例如。 "lemon chicken") |
|
max_results |
number | 每页结果数(1-50,默认值 10) |
|
page_number |
number | 从零开始的页面索引 | |
calories_min |
数量 | 每份的最低卡路里 | |
calories_max |
数量 | 每份最大卡路里 | |
sort_by |
string | newest |
|
must_have_images |
boolean | 仅返回带有图像的食谱 |
示例提示: “寻找400卡路里以下的高蛋白食谱”
get_food_entries
阅读食物日记条目。 需要OAuth 1.0令牌。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
date |
string | YYYY-MM-DD (默认为今天) |
|
food_entry_id |
string | 检索特定条目 |
示例提示: “我今天午饭吃了什么?”
add_food_entry
把食物记在日记里。 需要OAuth 1.0令牌。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
food_id |
string | ✅ | FatSecret食品ID |
serving_id |
string | ✅ | 服务尺寸ID(从 get_food) |
number_of_units |
编号 | ✅ | 食用份数 |
meal |
"breakfast" |
"lunch" |
"dinner" |
date |
string | YYYY-MM-DD (默认为今天) |
|
food_entry_name |
string | 自定义显示名称 |
示例提示: “记录1.5份鸡胸肉(food_id 4888,serving_id 15183)作为今天的晚餐”
get_daily_nutrition
一天的总热量和宏观总量。 需要OAuth 1.0令牌。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
date |
string | YYYY-MM-DD (默认为今天) |
示例提示: “我昨天吃了多少卡路里和多少克蛋白质?”
get_month_of_statistics
整个月的每日营养数据。 需要OAuth 1.0令牌。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
date |
string | 目标月份中的任何日期(默认为当前月份) |
示例提示: “显示我2026年3月的营养数据”
获取用户令牌(日记功能)
日记工具需要 三条腿的OAuth 1.0 以获得用户特定的访问令牌和秘密。以下是完整的过程:
步骤1--获取请求令牌
# Replace with your actual credentials
curl -X POST "https://www.fatsecret.com/oauth/request_token" \
-H "Authorization: OAuth oauth_callback=\"oob\", \
oauth_consumer_key=\"YOUR_CLIENT_ID\", \
oauth_nonce=\"$(openssl rand -hex 16)\", \
oauth_signature_method=\"HMAC-SHA1\", \
oauth_timestamp=\"$(date +%s)\", \
oauth_version=\"1.0\", \
oauth_signature=\"<computed_signature>\""
提示: 使用类似的库 oauth-1.0a 或 FatSecret API演示 以处理签名生成。
步骤2——在浏览器中授权
指导用户:
https://www.fatsecret.com/oauth/authorize?oauth_token=<request_token>
用户登录并批准。FatSecret展示了一个 PIN/验证码.
步骤3——交换访问令牌
curl -X POST "https://www.fatsecret.com/oauth/access_token" \
-H "Authorization: OAuth oauth_consumer_key=\"YOUR_CLIENT_ID\", \
oauth_token=\"<request_token>\", \
oauth_verifier=\"<pin_code>\", \
..."
响应包含 oauth_token (访问令牌)和 oauth_token_secret.将这些存储为 FATSECRET_ACCESS_TOKEN 和 FATSECRET_ACCESS_TOKEN_SECRET.
对于一个人设置(记录您自己的用餐),您可以使用FatSecret API Demo工具来完成OAuth 1.0流并直接复制生成的令牌。
对话示例
在Claude Desktop中配置后,您可以进行自然对话,例如:
你: “我早餐刚吃了一碗燕麦片加牛奶。你能记下来吗?”
克劳德: (电话
search_foods→get_food→add_food_entry自动) “完成!我早餐吃了1杯煮熟的燕麦片(147千卡)和1杯全脂牛奶(149千卡)。总共296千卡,含13克蛋白质。”
你: “我的宏今天看起来怎么样?”
克劳德: (电话
get_daily_nutrition) “到目前为止,你已经摄入了1240千卡:87克蛋白质(28%),142克碳水化合物(46%),38克脂肪(27%)。”
发展
# Run in development mode (no build step)
npm run dev
# Type-check only
npm run typecheck
# Build for production
npm run build
项目结构
src/
├── index.ts # MCP server entry point, tool dispatch
├── fatsecret.ts # API client (OAuth 2.0 + OAuth 1.0 HMAC-SHA1)
└── tools/
├── food.ts # search_foods, get_food, search_recipes
├── diary.ts # get_food_entries, add_food_entry
└── nutrition.ts # get_daily_nutrition, get_month_of_statistics
API限制和已知限制
| 限制 | 详细信息 |
|---|---|
| 日记需要OAuth 1.0 | 日记和月度统计端点不支持OAuth 2.0。您必须完成3个标签的OAuth 1.0流程并存储个人令牌。 |
| 无费率限制文档 | FatSecret不会公开发布速率限制。免费等级通常限制在约2 req/sec。卓越理财账户有更高的限制。 |
| JSON不一致 | 单个结果响应返回一个对象;多结果响应返回一个数组。客户端通过以下方式自动处理此问题 toArray(). |
| 主要功能 | 条形码扫描、图像识别(Snap It)和NLP食品记录需要订阅Premier API。 |
| 区域可用性 | 有些食品/品牌是针对特定地区的。使用 region 要筛选的参数。 |
| 日期整数 | FatSecret日期存储为“自1970-01-01以来的天数”。客户端转换为/从 YYYY-MM-DD 透明的字符串。 |
许可证
麻省理工学院——见 许可证 了解详情。
贡献
欢迎问题和拉取请求!请先打开一个问题以了解重大更改。