Skip to main content
Glama
README.md
# household-mcp

A personal [MCP](https://modelcontextprotocol.io) server that lets Claude handle everyday chores for you, from your
phone or computer. It is one server made of **three separate products**, each with its own set of tools:

| | Product | What it does | Status |
|---|---|---|---|
| 1 | **[King Soopers](#king-soopers-from-recipe-to-pickup-order)** (primary) | Turns a recipe or grocery list into a King Soopers cart for pickup, with a built-in staging and review step so nothing wrong ends up in your order | Read and write (adds to your cart; you check out in the King Soopers app) |
| 2 | **[Fantasy football](#espn-fantasy-football-read-only)** | Answers questions about your ESPN fantasy league: standings, matchups, lineups, waivers and injuries | Read-only |
| 3 | **[Garmin](#garmin-connect-read-only)** | Answers questions about your training, sleep, recovery and body data from Garmin Connect | Read-only |

King Soopers is the main reason this exists and gets the most detail below. Fantasy football and Garmin are smaller
add-ons that share the same server, login and hosting. Setup, deployment and operations for all three are in
[Setup and operations](#setup-and-operations).

---

# King Soopers: from recipe to pickup order

## What it's for
Before this, planning meals with Claude meant copying the grocery list into the King Soopers chatbot or searching
for every item by hand. With this server you stay in the Claude app, on your phone or computer:

1. **Plan in Claude.** Ask for a recipe, a meal plan, or a staples run ("plan three dinners with chicken thighs and
   build the grocery list").
2. **Claude builds the cart.** It finds the right products at your store, with real prices and stock, and prepares
   the list. It uses products you've bought before when it can.
3. **You review a staged basket.** Before anything touches your cart, Claude shows every line with its estimated
   cost and any warnings (details below). You approve, change, or remove lines.
4. **Claude adds it to your King Soopers cart.** Only the approved basket is added, and never twice.
5. **You check out in the King Soopers app** for pickup. Checkout stays in your hands, always.

Example (illustrative numbers):
```
You:     Add the ingredients for the chicken thigh recipe to my cart.
Claude:  Here's the draft basket (nothing is in your cart yet), estimated total $63.40:
         1. Heritage Farm boneless skinless chicken thighs, 1 lb x 3, $11.97
         2. Fresh green grapes: 3 units is about 6.5 lb, about $18.25, not 3 lb. Is that what you want?
         3. Boar's Head turkey, 2 units, about 3.1 lb, about $50.21, above the $30 line limit. Confirm?
         ...
You:     Make the grapes 2 lb and skip the turkey. Looks good.
Claude:  Added 14 items to your cart (estimated $41.80). Check out in the King Soopers app when you're ready.
```

What it can't do (the free Kroger API doesn't allow it): read what's in your cart, remove items, place the order,
or see your order history. That is why the server keeps its own records, described below.

## Why there is a staging step
Everything a grocery assistant does wrong ends up in a real order, and the cart can't be edited through the API.
The mistakes we actually saw in past orders drove the design:

- **By-weight items.** Grapes, deli meat, produce and bananas are priced per pound and weighed by the store. Adding
  "3" of per-lb grapes quietly became 6.5 lb and about $18 (logged as 3 x $2.79 = $8), and 2 units of deli turkey
  became 3.1 lb and $50 (logged as 2 x $15.99 = $32).
- **Product drift and duplicates.** The same request resolving to a different product each week, and the same list
  being added twice.
- **Surprise totals.** One order's item total came to about $34 more than the server had logged.

So nothing reaches the cart directly. It's always **stage -> review -> commit**:

1. `kroger_stage_list` builds a draft basket. Nothing is added to the cart. Each line gets units, estimated weight
   and cost, and warnings. Products you've bought before (saved preferences) are filled in automatically; anything
   ambiguous comes back as a pick-list, never a guess.
2. Claude shows you the whole basket, every warning, and the estimated total, and asks for your approval.
3. `kroger_update_basket` applies your changes (pick a product, change a quantity, restate a weight in pounds,
   remove a line, acknowledge a warning you're fine with).
4. `kroger_commit_basket` adds exactly the approved basket. It needs the basket's exact fingerprint and the total you
   were shown, re-checks live prices and stock first (if anything got worse, it stops and asks again), and is safe to
   retry: a basket can never be added twice.

### What gets checked on every line
| Check | Default | What happens |
|---|---|---|
| Sold by weight | always | Shows estimated weight and cost; you confirm, or restate the amount in pounds |
| High quantity | more than 6 of one product | Needs your OK |
| High line total | over $30 | Needs your OK |
| High basket total | over $250 | Needs your OK |
| Price spike | 15% and $0.50 above what you paid last time | Needs your OK |
| Duplicate | same product added in the last 4 days and not checked out, or twice in one basket | Needs your OK |
| Doesn't match the request | fewer than half the requested words in the product name | Needs your OK |
| Expensive single item | $25 or more each | Needs your OK |
| Out of stock / not found / never-add list | always | Must be replaced or removed |

The limits live in `modules/kroger/rules.py` and can be overridden by the server owner with `KROGER_RULES` (JSON) and
`KROGER_BLOCKLIST` (comma-separated) in `fly.toml`. They are deliberately **not** editable through Claude's tools,
so Claude can't loosen its own limits. `kroger_get_rules` shows what's in force.

The server can't prove a person said yes; it forces the real numbers (fingerprint and approved total) into the commit
call, and Claude's instructions require it to show you every line and warning first.

## After checkout: the ledger and receipts
Since the cart can't be read, the server keeps a **cart ledger**: what it added since your last checkout, with an
expected total. Use it to sanity-check the cart before you pay (`kroger_cart_ledger`).

After checkout, give Claude your receipt (pasted text or a screenshot) and it runs
`kroger_reconcile_receipt`. It reports items you removed or added in the app, compares estimated cost to what you
actually paid, **learns how heavy one unit of each by-weight item really is**, and clears the ledger. The more you use
it, the closer the estimates get.

## Remembering what you buy
- **Saved preferences:** "chicken thighs" always means one specific product. `kroger_save_preference` sets one
  explicitly, and an explicit preference always wins.
- **Learned preferences:** after the same product is added twice for the same generic name, it's remembered automatically.
- Names are normalised, so "Chicken Thigh" and "chicken thighs" match. If your preferred product is out of stock,
  Claude offers alternatives instead of failing.

## King Soopers tools
| Tool | Purpose |
|---|---|
| `kroger_find_stores`, `kroger_set_home_store` | Find and save your store (prices and stock are per store) |
| `kroger_search_products`, `kroger_get_product` | Look up products with price, sale price, stock, aisle, and whether it's sold by weight |
| `kroger_stage_list` | Build a draft basket (nothing added to the cart) |
| `kroger_get_basket`, `kroger_update_basket` | Review and edit the draft |
| `kroger_commit_basket` | Add the approved basket to your King Soopers cart |
| `kroger_cart_ledger`, `kroger_cart_cleared` | What was added since the last checkout; reset it |
| `kroger_reconcile_receipt` | Compare the real order with the ledger and learn from it |
| `kroger_save_preference`, `kroger_list_preferences`, `kroger_forget_preference` | Manage remembered products |
| `kroger_recent_adds` | History of what was added through the server |
| `kroger_auth_status` | Whether your King Soopers login is valid; returns a login link if not |
| `kroger_get_rules` | The safety limits currently in force (read-only) |

## How it works
King Soopers is a Kroger banner, so everything goes through the free [Kroger Developer API](https://developer.kroger.com).
Product and store lookups use an app-only token. Cart adds use your own King Soopers login (OAuth, approved once in
your browser; tokens are encrypted on disk and refresh automatically). Claude never sees your Kroger credentials; the
server holds them. Items are added for **pickup**. Preferences, history, baskets and the ledger live in a small SQLite
database on the server.

Operational notes: Kroger's firewall blocks some Fly.io addresses (see [Kroger firewall note](#kroger-firewall-note)),
search terms are trimmed to Kroger's 8-word limit, and the server was built and tested against real orders.

---

# Other modules

These share the server but are secondary to the grocery workflow.

## ESPN Fantasy Football (read-only)
Ask Claude about your ESPN fantasy football league in plain English and get answers based on your real league data.
It is **read-only**: it can look at everything, but it can't set your lineup, add or drop players, or make trades.

**What it can do**
- **League overview:** league name, current week, scoring settings, and every team (with the team IDs the other
  tools need) via `espn_league_info`.
- **Standings and matchups:** standings sorted by wins then points for (`espn_league_standings`), and this week's (or
  any week's) matchups and scores (`espn_matchups`).
- **Your team:** record, points, adds/drops/trades and playoff odds (`espn_team_info`), the full roster with points,
  projections and injury status (`espn_team_roster`), and a week's lineup with starters and bench, opponent,
  projection and injury status (`espn_lineup`) for start/sit decisions.
- **Waivers:** the top available free agents ranked by ESPN, with ownership and projections, filterable by position
  (`espn_free_agents`).
- **Players:** season stats for any rostered player found by partial name (`espn_player_stats`).
- **Injuries:** an injury check for every player on a roster, with ESPN's designation, body part, expected return
  date and latest news with its date (`espn_injury_report`), plus lookups for specific players by name, such as free
  agents you're considering (`espn_player_injury`).

**Things you might ask**
- "Who should I start at flex this week?"
- "Who are the best available running backs on waivers, and are any of them hurt?"
- "How does my week's matchup look, and where am I in the standings?"

**Built-in guardrails.** Before any start/sit, waiver or lineup recommendation, Claude is instructed to check the
injury report, cross-check reputable outside sources (the official NFL injury report, team beat reporters,
FantasyPros, ESPN and Yahoo news) with web search, and cite them. It reports the designation, body part and news date.
ESPN doesn't publish a real chance-to-play, so Claude must never invent percentages, and it should say when data is
stale or missing.

**Setup.** Public leagues work as is. Private leagues need the `ESPN_S2` and `SWID` cookies from your ESPN login,
set as secrets. They expire eventually and need refreshing. The data comes from ESPN's unofficial API, which can change
without warning.

## Garmin Connect (read-only)
Ask Claude about your fitness and health data from Garmin Connect: training, sleep, recovery and body trends. It is
**read-only** and uses imperial units. Weeks run Monday to Sunday in `GARMIN_TZ` (default America/Denver).

**What it can do**
- **Weekly big picture (start here):** `garmin_weekly_overview` rolls up the last 1 to 12 weeks: training volume by
  activity type, training load, average sleep, average HRV, resting heart rate, weight and average daily steps, plus
  first-to-last-week trends.
- **Workouts:** `garmin_recent_activities` lists recent sessions (lifting, indoor cycling such as Peloton, tennis,
  and so on) with type, duration, distance, heart rate, calories, training effect and load. `garmin_activity_detail`
  digs into one: time in heart-rate zones, and for lifting the actual sets (exercise, reps and weight), or laps and
  splits for cardio.
- **Daily snapshot:** steps, resting heart rate, stress, Body Battery, intensity minutes and calories
  (`garmin_daily_summary`).
- **Sleep:** nightly duration, deep, light, REM and awake minutes, sleep score, and bed and wake times (`garmin_sleep`).
- **Recovery:** nightly HRV with 7-day average, baseline range and Garmin's HRV status (`garmin_hrv`), and current
  training status with acute and chronic load, the 4-week load focus versus targets, VO2 max, training readiness and
  recovery time (`garmin_training_status`).
- **Body composition:** weigh-ins from a Withings scale synced to Garmin: weight, body fat %, muscle and bone mass,
  water % and BMI (`garmin_body_composition`).
- **Connection check:** `garmin_auth_status` reports whether the session and saved tokens are working.

**Things you might ask**
- "How has my training and sleep looked over the last month?"
- "Am I recovering well enough to lift heavy today?"
- "Show my last leg day: exercises, sets and weights."
- "Is my weight and body fat trending the way I expect?"

**Guardrails.** Claude is not a doctor: it's instructed to describe health data as trends to discuss with a
professional if something looks concerning, not to diagnose.

**Setup and politeness.** It uses the unofficial `garminconnect` library (Garmin's mobile SSO flow; `garth` is
deprecated and no longer logs in), so it can break if Garmin changes things.
- **Garmin tokens:** run `uv run python scripts/garmin_login.py` once locally (prompts for an MFA code if Garmin asks).
  It writes `data/garmin/garmin_tokens.json` (gitignored). The access token auto-refreshes and the refresh token is
  written back to that file, so the server normally never sends your password.
- **Politeness:** at most 1 request/second, 15-minute response cache (6 h for date ranges entirely in the past), a
  429 pauses all Garmin calls for 15 minutes, and a failed login waits 30 minutes before retrying.
- **If tools say the session expired:** re-run the login script and re-upload the token file (see Deploy below).

## Adding a module
Create `modules/<name>/__init__.py` with `register(mcp)`, prefix tool names, add it to `MODULES` in `server.py`.

---

# Setup and operations

## Local setup
1. Register an app at developer.kroger.com, redirect URI `http://localhost:8000/callback`.
2. `cp .env.example .env` and fill in client ID/secret.
3. `uv sync` then `uv run pytest`
4. Inspect: `npx @modelcontextprotocol/inspector uv run python server.py`
5. Claude Desktop config (`claude_desktop_config.json`):
```json
{"mcpServers": {"household": {"command": "uv",
  "args": ["--directory", "<path to your household-mcp folder>", "run", "python", "server.py"]}}}
```
6. In Claude: "set my store from zip 80xxx", then "find chicken thighs". For cart adds, ask Claude to check
   `kroger_auth_status` and open the login link once.

## Deploy (Fly.io)
Runs as one small Fly.io machine with a 1 GB volume at `/data`. This is what makes it work from the Claude mobile app.
Copy `fly.example.toml` to `fly.toml` (gitignored, so your app name and URL never land in the repo) and set your app
name and URL there.

- **Endpoint auth:** single-owner OAuth 2.1 (`auth_provider.py`). Claude registers via DCR, only
  `https://claude.ai/api/mcp/auth_callback` is an allowed redirect, and you approve on `/login` with `OWNER_PASSWORD`.
  Tokens are hashed in SQLite; refresh tokens rotate; 5 bad passwords lock login for 15 minutes.
- **Secrets** (`fly secrets set`): `KROGER_CLIENT_ID`, `KROGER_CLIENT_SECRET`, `KROGER_ZIP`, `TOKEN_ENCRYPTION_KEY`, `OWNER_PASSWORD`, for private ESPN leagues `ESPN_S2` and `SWID`, and optionally `GARMIN_EMAIL` / `GARMIN_PASSWORD` (fallback login only).
  Non-secret config (`PUBLIC_URL`, `KROGER_REDIRECT_URI`) lives in `fly.toml`.
- **Deploy:** `bash scripts/fly.sh deploy --ha=false --yes` (see the deploy token section). Run `uv run pytest` first.
- **Kroger app registration** must list both `http://localhost:8000/callback` and `https://<your-app>.fly.dev/callback`.
- **Connect Claude:** claude.ai -> Settings -> Connectors -> Add custom connector -> `https://<your-app>.fly.dev/mcp`, then enter the owner password.
- **First use:** set the store, then run `kroger_auth_status` and open the login link once (local and cloud keep separate tokens, preferences and history).
- **Garmin tokens on Fly:** the server reads `/data/garmin/garmin_tokens.json`. Upload the file from your local login:
  wake the machine first (it auto-stops when idle, and ssh needs it running) with `curl.exe https://<your-app>.fly.dev/health` (on Windows PowerShell plain `curl` is `Invoke-WebRequest`),
  then `fly ssh console -C "mkdir -p /data/garmin"`, then `fly ssh sftp shell` and
  `put data/garmin/garmin_tokens.json /data/garmin/garmin_tokens.json`. Log in from your own computer rather than
  letting Fly do it: Garmin is much more likely to rate-limit or challenge logins from datacenter IPs.

## Kroger firewall note
Kroger's firewall (Akamai) 403s `/products` from Fly's shared egress IPs (IPv6 first, later the shared IPv4 too).
The fix is a dedicated egress IP (`fly ips allocate-egress -a <your-app> -r <region>`, ~$3.50/mo) and Kroger clients
are forced to IPv4. If searches 403 again: probe from the machine with `fly ssh console`, and compare with a local run.

## Fly deploy token (no more `fly auth login`)
`scripts/fly.sh` runs flyctl with an app-scoped deploy token kept OUTSIDE the repo at `~/.fly/household-mcp-token`
(file permissions limited to the owner). It can deploy, restart, read status/logs/IPs and SSH into `<your-app>`
and nothing else. Created with a 1-year lifetime (Dec 2026); renew with
`fly auth login` then `fly tokens create deploy -a <your-app> -x 8760h > ~/.fly/household-mcp-token`.
Usage: `bash scripts/fly.sh deploy --ha=false --yes`, `bash scripts/fly.sh status`, `bash scripts/fly.sh logs --no-tail`.

## Health checks
A scheduled task in the Claude desktop app tests the King Soopers tools twice a week (Mon and Thu): tests, endpoint auth,
live search, the safety-rail staging check, the Fly egress IP, and that code is committed, pushed and deployed. It fixes
and redeploys problems on its own, but it never adds anything to the real cart.

## Source control and secrets
GitHub repo: https://github.com/davwalker95/household-mcp. No credentials or deployment-specific values are tracked:
secrets live in `.env` (local) and Fly secrets, and your app name, URL and store live in your untracked `fly.toml`,
`.env` and the server database. Guards against leaks:

- `scripts/check_secrets.sh` runs as a pre-commit hook (install on a new clone with `bash scripts/install_hooks.sh`). It
  blocks env files, databases and token/key files, credential-shaped strings, and the actual values in your `.env`.
  Never bypass it with `--no-verify`.
- CI (`.github/workflows/ci.yml`) runs the tests and a gitleaks secret scan on every push and pull request.
- If a secret is ever pushed, rotate it first (Kroger secret, Fly token, owner password), then clean the history.

# Using it yourself
This is a personal project, shared as-is. To run your own copy you need your own accounts and keys: a Kroger
Developer app (free, developer.kroger.com) for King Soopers or any Kroger-family store, optionally your own ESPN league
cookies and Garmin login, and a Fly.io app if you want it on your phone. Nothing in this repo gives access to anyone
else's server, cart or data. Follow [Local setup](#local-setup), then [Deploy](#deploy-flyio).

# Disclaimer
Not affiliated with or endorsed by King Soopers, The Kroger Co., ESPN or Garmin. King Soopers uses the public Kroger
Developer API under your own developer account and its terms. The ESPN and Garmin modules use unofficial, undocumented
APIs that can change or break at any time; use them for your own personal data only and at your own risk. Cart adds are
not orders: always review your cart and check out yourself.

# Security
See [SECURITY.md](SECURITY.md) to report a vulnerability privately.

# License
[MIT](LICENSE)