# mason-levyy/myfitnesspal-mcp architecture

> Architecture diagram of the GitHub repository mason-levyy/myfitnesspal-mcp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mason-levyy/myfitnesspal-mcp
- Repository: https://github.com/mason-levyy/myfitnesspal-mcp

## Overview

This repository is an MCP server that lets an AI client read and change a user’s MyFitnessPal diary. The main workflow is: a client invokes a server tool, food searches can be ranked into a draft and confirmed for logging, and the server reads or writes MyFitnessPal before returning results. Diary summaries and trends use a local SQLite cache; sync fills it from MyFitnessPal. Authentication uses a browser session cookie, with optional headless-browser refresh. Some tool and helper wiring is inferred from the README where source excerpts are incomplete.

Main entry points: [`src/myfitnesspal_mcp/server.py`](https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/server.py) (MCP tools), [`src/myfitnesspal_mcp/mfp_client.py`](https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/mfp_client.py) (MFP client), [`src/myfitnesspal_mcp/food_logging.py`](https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/food_logging.py) (Food logging), [`src/myfitnesspal_mcp/sync.py`](https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/sync.py) (Diary sync)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["MCP interface"]
  node_server["MCP tools<br/>[server.py]"]
  node_cli["CLI entry<br/>[cli.py]"]
end

subgraph group_diary["Diary operations"]
  node_food_logging["Food logging<br/>[food_logging.py]"]
  node_ranking["Food ranking<br/>[food_ranking.py]"]
  node_diary_ops["Diary operations<br/>[diary.py]"]
end

subgraph group_data["Cache and analysis"]
  node_sync["Diary sync<br/>[sync.py]"]
  node_store[("Local cache<br/>[store.py]")]
end

subgraph group_identity["Session management"]
  node_mfp_client["MFP client<br/>[mfp_client.py]"]
  node_auth["Cookie auth<br/>[auth.py]"]
  node_config["Configuration<br/>[config.py]"]
  node_refresh["Session refresh<br/>[refresh.py]"]
end

node_client(("MCP client"))
node_mfp(("MyFitnessPal"))

node_client -->|"invokes tools"| node_server
node_cli -->|"starts server"| node_server
node_server -->|"handles food tools"| node_food_logging
node_server -->|"handles diary tools"| node_diary_ops
node_server -->|"syncs diary"| node_sync
node_server -->|"reads and writes"| node_store
node_server -->|"gets session client"| node_mfp_client
node_server -->|"retries auth failures"| node_refresh
node_food_logging -->|"ranks candidates"| node_ranking
node_food_logging -->|"uses pins and drafts"| node_store
node_food_logging -->|"logs food"| node_diary_ops
node_diary_ops -->|"reads and writes diary"| node_mfp
node_sync -->|"fetches notes"| node_diary_ops
node_sync -->|"fetches diary data"| node_mfp_client
node_sync -->|"updates cache"| node_store
node_mfp_client -->|"loads cookies"| node_auth
node_mfp_client -->|"authenticates requests"| node_mfp
node_auth -->|"validates cookie"| node_mfp_client
node_auth -->|"locates cookie file"| node_config
node_refresh -.->|"refreshes session"| node_mfp
node_refresh -.->|"saves refreshed cookies"| node_auth
node_refresh -.->|"resets client"| node_mfp_client
node_store -->|"locates database"| node_config

click node_server "https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/server.py"
click node_cli "https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/cli.py"
click node_food_logging "https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/food_logging.py"
click node_ranking "https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/food_ranking.py"
click node_diary_ops "https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/diary.py"
click node_mfp_client "https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/mfp_client.py"
click node_sync "https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/sync.py"
click node_store "https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/store.py"
click node_auth "https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/auth.py"
click node_config "https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/config.py"
click node_refresh "https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/refresh.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_server,node_cli,node_client toneBlue
class node_food_logging,node_ranking,node_diary_ops toneAmber
class node_sync,node_store toneMint
class node_mfp_client,node_auth,node_config,node_refresh toneRose
class node_mfp toneIndigo
```

## Components

### MCP interface

- [MCP tools](https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/server.py): `src/myfitnesspal_mcp/server.py`
- [CLI entry](https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/cli.py): `src/myfitnesspal_mcp/cli.py`

### Diary operations

- [Food logging](https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/food_logging.py): `src/myfitnesspal_mcp/food_logging.py`
- [Food ranking](https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/food_ranking.py): `src/myfitnesspal_mcp/food_ranking.py`
- [Diary operations](https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/diary.py): `src/myfitnesspal_mcp/diary.py`

### Cache and analysis

- [Diary sync](https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/sync.py): `src/myfitnesspal_mcp/sync.py`
- [Local cache](https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/store.py): `src/myfitnesspal_mcp/store.py`

### Session management

- [MFP client](https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/mfp_client.py): `src/myfitnesspal_mcp/mfp_client.py`
- [Cookie auth](https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/auth.py): `src/myfitnesspal_mcp/auth.py`
- [Configuration](https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/config.py): `src/myfitnesspal_mcp/config.py`
- [Session refresh](https://github.com/mason-levyy/myfitnesspal-mcp/blob/main/src/myfitnesspal_mcp/refresh.py): `src/myfitnesspal_mcp/refresh.py`

### Other components

- **MCP client**
- **MyFitnessPal**

## Connections

- MCP client → MCP tools: invokes tools
- CLI entry → MCP tools: starts server
- MCP tools → Food logging: handles food tools
- MCP tools → Diary operations: handles diary tools
- MCP tools → Diary sync: syncs diary
- MCP tools → Local cache: reads and writes
- MCP tools → MFP client: gets session client
- MCP tools → Session refresh: retries auth failures
- Food logging → Food ranking: ranks candidates
- Food logging → Local cache: uses pins and drafts
- Food logging → Diary operations: logs food
- Diary operations → MyFitnessPal: reads and writes diary
- Diary sync → Diary operations: fetches notes
- Diary sync → MFP client: fetches diary data
- Diary sync → Local cache: updates cache
- MFP client → Cookie auth: loads cookies
- MFP client → MyFitnessPal: authenticates requests
- Cookie auth → MFP client: validates cookie
- Cookie auth → Configuration: locates cookie file
- Session refresh → MyFitnessPal: refreshes session
- Session refresh → Cookie auth: saves refreshed cookies
- Session refresh → MFP client: resets client
- Local cache → Configuration: locates database
