Health4AI
This MCP server lets you query and analyze your Apple Health data from a Postgres database using natural language via any MCP-compatible AI client. Key capabilities include:
Get a health summary (
get_health_summary): Overview of key metrics (steps, sleep, HRV, resting HR, workouts) for a specified number of days.Analyze sleep (
get_sleep): Per-night sleep breakdown with stage durations (REM, Deep/Core, Light, Awake).Track HRV trends (
get_hrv_trend): Daily HRV averages, rolling comparisons, and trend direction.Query any HealthKit metric (
query_metric): Raw time-series data or daily aggregates for any metric type.View workouts (
get_workouts): Recent workout details including type, duration, distance, and calories.Get a daily snapshot (
get_daily_snapshot): All recorded health data for a specific date.Analyze long-term trends (
get_long_term_trend): Multi-year or seasonal trends using raw and summarized data.Generate a coaching brief (
get_coaching_brief): Structured summary of recovery, sleep, training load, and fitness trajectory.Search records by threshold (
search_records): Days where a metric crossed a min/max value.Calculate metric statistics (
get_metric_stats): Personal baselines (min, max, mean, percentiles) for any metric.Compare time periods (
compare_periods): Compare a metric between two custom date ranges with stats and deltas.
health4.ai — Apple Health × AI
What it does
iPhone HealthKit → Your Postgres database → MCP server → Any AIApple Health holds years of your biometric data — sleep stages, HRV, heart rate, workouts, VO₂ max, and 150+ other metrics. health4.ai makes all of it queryable from Claude, ChatGPT, Cursor, Ollama, or any MCP-compatible client via 8 purpose-built tools.
You control the data. It syncs to a Postgres database you configure — Supabase, Neon, or a local Docker container. health4.ai never stores or has access to your health data.
Related MCP server: Health Export AI
Why it exists
Problem | health4.ai fix |
Apple has no HealthKit server API — all access requires an on-device app | Native iOS app with |
Health Auto Export only works on the same WiFi | Your data lands in Postgres — queryable from any AI, anywhere |
The claude.ai Apple Health connector doesn't reach Claude Code CLI or Cursor | Standard MCP (stdio) — one config block works everywhere |
Most solutions require a managed cloud service | Bring your own Postgres: Supabase, Neon, or fully local |
Demo
Demo video coming. Here's what a typical conversation looks like:
You: How was my recovery this week? Anything standing out?
Claude: Your recovery this week was mixed but trending positive.
• HRV averaged 58ms (Tue–Thu strong at 64–68ms; Monday low at 44ms after Saturday's long run)
• Sleep averaged 7h 12m — Wednesday and Thursday were your best nights (7h 40m+)
• Resting HR dropped from 54bpm Monday to 49bpm Friday — a good sign
Recommendation: today looks like a solid day for a moderate-intensity session.Quick start
Choose your Postgres backend first:
# 1. Create a project at supabase.com
# 2. Run the schema
psql "$DATABASE_URL" < web/public/schema.sql
# or use the Supabase dashboard SQL editor# 1. Create a project at neon.tech
# 2. Run the schema
psql "$DATABASE_URL" < web/public/schema.sqldocker run -d \
--name health4ai-postgres \
-e POSTGRES_PASSWORD=yourpassword \
-p 5432:5432 \
postgres:16
psql "postgresql://postgres:yourpassword@localhost:5432/postgres" \
< web/public/schema.sqlThen set up the MCP server:
git clone https://github.com/jefflitt1/health4ai.git
cd health4ai
cp mcp-server/.env.example mcp-server/.envEdit mcp-server/.env:
DATABASE_URL=postgresql://... # your Postgres connection string
HEALTHKIT_USER_ID=your_user_id # any string to identify your dataAdd to your AI client:
{
"mcpServers": {
"health4ai": {
"command": "python",
"args": ["/path/to/health4ai/mcp-server/main.py"],
"env": {
"DATABASE_URL": "postgresql://...",
"HEALTHKIT_USER_ID": "your_user_id"
}
}
}
}Same block → ~/.cursor/mcp.json
Pair with mcphost or mcp-client-for-ollama:
mcphost --model ollama/llama3.2 \
--mcp-server "health4ai:python /path/to/health4ai/mcp-server/main.py"Your health data and the model both stay on your hardware — nothing leaves your machine.
Install the iOS app: Configure a database and Supabase account that you control, then sign in and tap Start Sync. For a private TestFlight beta, follow the tester-isolation guide; never use another person's backend or credentials.
MCP tools
Tool | What it answers |
| Overview of key metrics for the past N days |
| Per-night sleep breakdown with REM, Deep, Core stages |
| Daily HRV (SDNN) with rolling comparison and trend |
| Everything recorded for a specific date |
| Recent workouts with type, duration, distance, calories |
| Raw time-series for any HealthKit metric type |
| Monthly aggregates over years (raw + summary tiers) |
| Recovery status, sleep quality, training load, fitness markers |
| Find days where a metric crossed a threshold |
| Personal baseline: min/max/mean/percentiles |
| Compare a metric between two date ranges |
Architecture
┌─────────────────────────────────────────────────────────────┐
│ iPhone │
│ HKObserverQuery + BGTaskScheduler │
│ → continuous background sync │
└──────────────────────────┬──────────────────────────────────┘
│ HTTPS
▼
┌─────────────────────────────────────────────────────────────┐
│ Your Postgres database (Supabase / Neon / local Docker) │
│ healthkit_metrics · healthkit_daily_summaries │
│ v_healthkit_daily_quantity (unified view) │
└──────────────────────────┬──────────────────────────────────┘
│ SQL (service-role key, server-side only)
▼
┌─────────────────────────────────────────────────────────────┐
│ FastMCP server (mcp-server/main.py) │
│ 11 tools · stdio transport │
└──────────────────────────┬──────────────────────────────────┘
│ MCP
▼
Claude · ChatGPT · Cursor · Ollama · any clientData tiers: queries within the last 30 days return raw samples; older data transparently switches to pre-aggregated daily summaries — so long-term trend queries stay fast regardless of data volume.
Repo structure
health4ai/
├── ios/ # Swift/SwiftUI iOS app (iOS 17+)
│ └── Health4AI/ # HealthKit sync engine, auth, settings
├── mcp-server/
│ ├── main.py # FastMCP server entry point
│ ├── tools.py # 11 tool implementations
│ └── .env.example # Required environment variables
├── web/
│ ├── public/schema.sql # Portable Postgres schema (all backends)
│ └── src/ # Astro marketing site
├── scripts/
│ ├── import_health_export.py # One-time XML backfill from Apple Health export
│ └── summarize_historical.py # Backfill daily summaries table
└── docs/
└── SETUP.md # Detailed setup guidePrivacy
Your health data goes directly from your iPhone to your Postgres database. health4.ai never receives, stores, or has access to it. The MCP server runs locally with your own credentials — your data never touches our infrastructure.
See the Privacy Policy for full details.
Contributing
MIT licensed. PRs welcome.
Good first areas: additional metric aggregations, multi-user support with JWT/RLS, Android, and more MCP client integration guides.
License
MIT — see LICENSE.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseAqualityAmaintenanceLocal-first MCP server that reads Apple Health export files (export.xml/zip) and exposes activity, sleep, HRV, and workout data to AI agents, keeping all data on your machine.181711MIT
- AlicenseAqualityAmaintenanceAn MCP server that enables AI agents to query Apple Health data (190+ metrics) in natural language, including trends, comparisons, and structured exports.72882MIT
- Alicense-qualityCmaintenanceExposes read-only Apple Health data (current status, sleep details, trends) to AI via a Cloudflare-deployed MCP server and iPhone Shortcuts.MIT
- Alicense-qualityCmaintenanceHosted MCP server that syncs health data from Apple Health, Fitbit, Oura, and Google Health Connect, enabling Claude and ChatGPT to query workouts, sleep, nutrition, and recovery in plain English with interactive charts.MIT
Related MCP Connectors
63 tools for Apple Health, Fitbit, Oura & Health Connect data in Claude, ChatGPT, Grok & Mistral.
Garmin data in Claude: 135 tools — activities, sleep, HRV, training, workouts. Free, open source.
WHOOP recovery, strain, sleep and workouts in Claude via official WHOOP OAuth. Free, open source.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/jefflitt1/health4ai'
If you have feedback or need assistance with the MCP directory API, please join our Discord server