Skip to content

ykawanabe/mf-sync

Repository files navigation

MF Sync

MacroFactor computes a trend weight it never syncs anywhere. MF Sync rebuilds it, on your phone, from the nutrition and body-weight data MacroFactor does write into Apple Health — then derives your rate of change and a projection to your goal. No API, no extra apps. You get a weekly cut review in three places: on the phone, on the command line, and as an MCP tool an AI agent can call.

Why

MacroFactor has no public API, and in May 2026 it turned on Firebase App Check, so every third-party client now gets a 401. That leaves HealthKit as the only durable way to get your data out, except macOS has no HealthKit. So the producer is a small native iOS app. It reads Health on the phone and writes one tiny JSON file per day to iCloud; a Mac (or an agent) reads those back and reconstructs what MacroFactor won't export.

iPhone:  MacroFactor → Apple Health → [MFSync app] → iCloud (one JSON/day)
Mac:     iCloud files → MFSyncKit (engine) → cut review  (CLI · MCP · agent)

What Apple Health carries: calories, protein/carb/fat, body weight. What it doesn't: MacroFactor's trend weight (reconstructed here via EWMA) and its adaptive targets (not synced, so a manual input).

Components

  • MFSyncKit — pure SwiftPM engine (no HealthKit/UIKit): trend EWMA, cut metrics (rate / projection), calorie + PFC averages. Fully unit-tested.
  • MFSync — thin SwiftUI iOS app (xcodegen): reads Health → writes per-day JSON to its iCloud container, background-delivery refresh, a dashboard.
  • mfsync — CLI: reads the day-files → prints the cut review (--json for agents).
  • mcp/mf_sync_mcp.py — a local stdio MCP server exposing the cut review as typed tools.

Design

Trend-first. Trend weight, rate, and projection are the validated core — they reproduce MacroFactor's trend to a few grams. The cut review pairs them with your recent calorie/PFC averages and protein-floor status.

Requirements

  • macOS with Xcode (Swift 6 toolchain), an iOS device for the producer app.
  • xcodegen (brew install xcodegen).
  • A MacroFactor account exporting to Apple Health; a paid Apple Developer account if you want the iCloud container on device.

Setup

Just want the steps? See QUICKSTART.md — follow it top to bottom.

# 1. Engine — runs anywhere, no setup:
swift test

# 2. The iOS app:
cp App/Signing.xcconfig.example App/Signing.xcconfig   # set DEVELOPMENT_TEAM + a unique bundle id
( cd App && xcodegen generate )
open App/MFSync.xcodeproj
#   In Xcode: add the iCloud + HealthKit (Background Delivery) capabilities, run on device.
#   On the phone: MacroFactor → Integrations → Apple Health (on); tap "Enable Sync", grant Health.

The app's iCloud container syncs to your Mac. The CLI finds it automatically:

swift run mfsync --target 64 --protein-floor 155     # human-readable cut review
swift run mfsync --json                               # structured (for agents)
# override the data dir with MFSYNC_DIR=/path, or pass a directory as the first arg.

MCP (optional)

A local stdio server so any MCP client (Claude Code, Claude desktop, …) can call cut_review:

// .mcp.json
{ "mcpServers": { "mf-sync": {
  "command": "uv",
  "args": ["run", "--python", "3.13", "--with", "mcp==1.28.0", "mcp/mf_sync_mcp.py"]
} } }

Privacy

No network, no account, no backend. Health data flows phone → your iCloud → your Mac, and the reconstruction runs locally. The MCP server is stdio-only (no port). Personal data and signing identity stay in gitignored files.

Limitations & disclaimer

  • Not affiliated with, endorsed by, or connected to MacroFactor or Stronger By Science. "MacroFactor" is their trademark. This project only reads data you exported to Apple Health and reconstructs metrics locally.
  • The trend weight is reconstructed locally via EWMA; it is not MacroFactor's official number, though it reproduces it closely on real data. Treat the rate and projection as a guide.
  • iCloud and HealthKit on a real device require a paid Apple Developer account.
  • The CLI/MCP consumer is macOS-only; the producer app is iOS.

License

MIT.

About

Reconstruct MacroFactor's expenditure (TDEE) and trend weight locally from Apple Health — on-device, no API, no account. iOS app + Swift engine + CLI + local MCP server.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors