mcp-server-fatsecret

mcp-server-fatsecret

Enables searching FatSecret's food and recipe database, and managing personal food diary, weight, exercise, saved meals, and favorites, with multi-user support and secure OAuth authentication.

Category
访问服务器

README

mcp-server-fatsecret

MCP server for the FatSecret Platform API — food/recipe search plus your own food diary, weight, exercise, saved meals, and favorites. Built for multiple named individuals sharing one hosted instance, each linking their own real FatSecret account.

This is an independent, unofficial project. Not affiliated with or endorsed by FatSecret.

Scope

  • Public food/recipe database (search, nutrition detail, recipes) — read-only, no personal data involved, authenticated via OAuth2 client-credentials.
  • Your own FatSecret data — profile, food diary, weight diary, exercise diary, saved meals, favorites, custom foods — read AND write, authenticated via a per-person OAuth1 token you link yourself.
  • Every write goes through a prepare → commit ceremony: fatsecret_prepare_* returns a dry-run preview with a hash; nothing is sent to FatSecret until a fatsecret_commit_* call restates that hash plus a fresh idempotency key.

Multi-user model

This server is designed to run as one shared instance behind a gateway that authenticates callers (e.g. via Entra ID) and forwards the verified caller identity as X-MCP-User. Each person's FatSecret OAuth1 token is stored in its own encrypted row, keyed by that identity — nobody can reach anyone else's diary, weight, or exercise data. If FATSECRET_TRUST_FORWARDED_USER is unset (or the header is missing), every data/auth tool refuses outright.

For local development without a gateway, set FATSECRET_DEV_USER to act as a single fixed identity over stdio.

Setup

  1. Register a developer app at platform.fatsecret.com to get a consumer key/secret. Premier tier is recommended if any user is outside the US — the free Basic tier's food database is US-only.
  2. Set FATSECRET_CONSUMER_KEY / FATSECRET_CONSUMER_SECRET.
  3. Generate an encryption key for the token store: openssl rand -hex 32 → FATSECRET_ENCRYPTION_KEY.
  4. Set FATSECRET_ENABLE_WRITES=true once you're ready to allow writes (off by default).
  5. Each person links their own account once: call fatsecret_start_auth, open the returned URL, sign into (or create) your fatsecret.com account, approve, then call fatsecret_complete_auth with the PIN FatSecret shows you. fatsecret_check_auth_status / fatsecret_disconnect manage the link afterward.

Claude / Cursor config (local stdio)

{
  "mcpServers": {
    "fatsecret": {
      "command": "npx",
      "args": ["-y", "mcp-server-fatsecret"],
      "env": {
        "FATSECRET_CONSUMER_KEY": "...",
        "FATSECRET_CONSUMER_SECRET": "...",
        "FATSECRET_ENCRYPTION_KEY": "...",
        "FATSECRET_DEV_USER": "you@example.com",
        "FATSECRET_ENABLE_WRITES": "true"
      }
    }
  }
}

API tiers (Basic vs Premier) — read this before wondering why a food is missing

FatSecret's Platform API has a free Basic tier and a paid Premier tier, and the split materially affects what this server can do. Note the paid consumer app subscription is a different product and does not unlock any of this.

On Basic (the default):

  • The food database is US-only. region=DK and other localization is a Premier feature, so non-US foods largely won't be found.
  • Only foods.search v1 is available (v2–v5 are Premier).
  • Custom foods (food.create) are Premier-only — you cannot inject your own nutrition values.
  • Listing favorites is Premier-only (foods.get_favorites, most-eaten, recently-eaten). Adding and removing favorites still works.
  • Everything that actually matters for a diary does work: logging, editing and deleting food entries, copying days, weight, saved meals, and exercise.

Set FATSECRET_PREMIER=true only if the app has genuinely been upgraded. Tools backed by Premier-only methods are not registered at all on Basic, so callers are never offered a tool that can only fail, and any direct call to one fails fast with an explanation instead of an opaque upstream error.

Working with non-US foods on Basic: look the item up in a local food-data source (e.g. Open Food Facts or a national food-composition database) to get its real macros, then log the closest match from FatSecret's database with the serving quantity scaled so the calories and macros line up. Search results include per-serving macros in food_description to make that matching possible.

Write policy

  • FATSECRET_ENABLE_WRITES=true — required for any mutating call; off by default.
  • FATSECRET_ENABLE_PROFILE_CREATE — separately gates the account-less profile.create fallback auth path (dev/test only; see below). Off by default even when general writes are enabled.
  • FATSECRET_POLICY_PATH — optional JSON file to further restrict which capabilities/methods are allowed.
  • FATSECRET_AUDIT_LOG — optional JSONL audit log path. Records tool/actingAs/status/a hash of the target — never the actual food, weight, or exercise data itself, since this is personal health-adjacent information.

Every write tool follows: fatsecret_prepare_* (dry-run, returns operationHash) → fatsecret_commit_prepared_operation (requires the operation object back, a restated confirmOperationHash, and a fresh idempotencyKey). The idempotency key is a local-only safety net — FatSecret's API has no server-side idempotency support, unlike some other providers — so retrying a commit with the same key only protects you within this process's lifetime, not across a restart.

Auth model

The primary path is real 3-legged OAuth1 against your own fatsecret.com account (fatsecret_start_auth / fatsecret_complete_auth), so your FatSecret mobile app and this MCP server see the same diary.

A fallback path, profile.create, can mint an account-less token pair (no real login, no companion-app access) for quick local testing — gated separately behind FATSECRET_ENABLE_PROFILE_CREATE and its own commit tool, fatsecret_commit_profile_create. Not recommended for real use.

Exercise logging — a real API limitation

FatSecret has no endpoint to log a single ad-hoc workout. It only supports a recurring weekly template (exercise_entries.save_template) that gets committed into a given day's diary (exercise_entries.commit_day), plus shifting minutes between two exercises on an existing day (exercise_entry.edit). fatsecret_log_one_off_exercise orchestrates the template-swap-then-commit sequence for a one-off workout, but it is not atomic across FatSecret's underlying calls — if it fails partway, your template may be left modified; the tool reports which steps completed so you can check and restore it.

Security / audit

See SECURITY.md. Credentials are read from the server environment only, never accepted as tool arguments. Per-user tokens are encrypted at rest (AES-256-GCM).

Optional HTTP server

npm run dev:http (or the published Docker image, which runs dist/http.js) exposes /mcp over Streamable HTTP, gated by MCP_HTTP_TOKEN. Intended to sit behind a reverse proxy that authenticates callers and forwards their identity as X-MCP-User (only trusted when FATSECRET_TRUST_FORWARDED_USER=true).

Verification

npm run typecheck && npm test && npm run build

For a live check against the real API (requires real credentials and a linked account): npm run smoke:live.

API sources

License

Apache-2.0

推荐服务器

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

官方
精选