How health4.ai works
Apple has no server-side HealthKit API — there is no webhook, no OAuth flow, no REST endpoint that lets a remote server pull your health data. health4.ai solves this with a tiny iOS app that syncs HealthKit directly to a Postgres database you control, then an open-source MCP server gives any AI structured access to it. Your data never touches health4.ai's servers.
Setup — step by step
Create a free Supabase project
Go to supabase.com and create a free project. Then run the health4.ai schema against it — this creates the two tables the app writes to:
# From Settings → Database → Connection String → URI
psql "$SUPABASE_DB_URL" < https://health4.ai/schema.sql Or use any Postgres 14+ — Neon, local Docker, self-hosted. Download schema.sql
Install the iOS app and connect your database
Download health4.ai from the App Store. Tap through the Welcome and Privacy screens, then open the Connect tab. Select Supabase, paste your project URL and anon key, then tap Sign In.
https://abc123.supabase.co — Settings → APIeyJ… — Settings → API → anon publicGrant HealthKit access — sync begins
Tap Allow Health Access during onboarding. iOS shows the standard HealthKit permission sheet — you choose which types to share. The app immediately begins a full historical backfill (your entire Apple Health archive), then switches to live incremental sync via HKObserverQuery — iOS wakes the app in the background whenever new data arrives.
Run the MCP server on your Mac
Clone the repo and configure the server with your Supabase credentials:
git clone https://github.com/jefflitt1/health4ai
cd health4ai/mcp-server
pip install -r requirements.txt
cp .env.example .env
# Edit .env: SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY, HEALTHKIT_USER_ID Add to your AI client
Add one block to your AI's MCP config. Works with Claude Desktop, Cursor, Continue, and any MCP-compatible client:
{
"mcpServers": {
"health4ai": {
"command": "python3",
"args": ["/path/to/health4ai/mcp-server/main.py"]
}
}
} Ask your AI about your health
Once the backfill completes (usually 2–10 minutes depending on your history), go to your AI and ask:
Common questions
Can I use Neon or a local Postgres instead of Supabase? ▾
Yes. In the app's Connect tab, switch to REST / Webhook and enter any HTTPS endpoint that accepts JSON POST requests. For Neon or self-hosted Postgres, point the endpoint at a lightweight ingest function you deploy. The schema.sql is compatible with any Postgres 14+.
Can I use health4.ai with multiple AI clients? ▾
Yes. The MCP server is a local stdio process — point as many AI clients as you like at the same main.py. Add the server entry to Claude Desktop, Cursor, Continue, or any MCP-compatible client. All clients read from the same Supabase database.
Does health4.ai ever see my health data? ▾
No. The iOS app syncs directly from your iPhone to your Supabase database — health4.ai's servers are never in the path. The MCP server runs locally on your Mac and reads from your database. We never see your health data.
How do I revoke HealthKit access? ▾
Go to iPhone Settings → Privacy & Security → Health → health4ai and toggle off any or all data types. The app stops receiving new data immediately. Your historical data stays in your own Supabase database — delete it there directly if you want it gone.
Under the hood
iPhone (health4.ai iOS app)
└─ HKObserverQuery ──► fires on every new HealthKit sample
└─ BGProcessingTask ──► runs full sync while charging
│ POST /rest/v1/healthkit_metrics (Supabase PostgREST)
▼
Your Supabase project (you own this — health4.ai has no access)
├── healthkit_metrics (raw samples, 30-day rolling window)
└── healthkit_daily_summaries (pre-aggregated, multi-year)
│ read via PostgREST
▼
health4ai MCP server (local stdio, runs on your Mac)
11 tools: get_sleep · get_hrv_trend · get_workouts · get_daily_snapshot
query_metric · get_health_summary · get_long_term_trend
search_records · get_metric_stats · compare_periods
get_coaching_brief
│
▼
Claude Desktop / Cursor / Continue / Ollama Open source, MIT licensed. The full source for the iOS app and MCP server is at github.com/jefflitt1/health4ai.