Skip to main content
Glama
README.md
# open-health

A self-hosted health log you talk to through your own AI. You tell Claude, ChatGPT, Cursor or any
MCP client what you ate, the set you just did, your weight or the pill you took; it calls this
server's MCP tools, and the data lands in a SQLite database (Cloudflare D1) in your own Cloudflare
account. A private dashboard and a web MCP console show it. Wearable data (Apple Health, Android
Health Connect) can be pushed in. The server makes no LLM calls and needs no API keys: your agent
estimates macros, the server stores them.

**Live demo** (fake data, resets daily, no sign-in): https://open-health-demo.jcallahanp.workers.dev ·
[console](https://open-health-demo.jcallahanp.workers.dev/console) · MCP endpoint
`https://open-health-demo.jcallahanp.workers.dev/mcp`

| Dashboard | MCP console |
|---|---|
| ![Dashboard with fake demo data](docs/screenshots/dashboard-1440.png) | ![Web MCP console calling a tool](docs/screenshots/console-1440.png) |

## Try it in 2 minutes

Needs Node.js 22.12 or newer and git. No Cloudflare account, no keys.

```sh
git clone https://github.com/jcallahanp/open-health.git
cd open-health
npm install
npm run demo
```

`npm run demo` creates a local database with 60 days of fake data and serves it. Open:

- Dashboard: http://localhost:8787/
- MCP console: http://localhost:8787/console
- Settings: http://localhost:8787/settings
- MCP endpoint: http://localhost:8787/mcp

It prints these URLs once the server is ready.

Demo mode has no sign-in. Connect Claude Code to it from another terminal:

```sh
claude mcp add --transport http open-health http://localhost:8787/mcp
```

Then ask Claude: "log lunch: chicken burrito bowl" and reload the dashboard. If 8787 is taken, run
`PORT=8790 npm run demo`; the port in `claude mcp add` must match (here
`http://localhost:8790/mcp`). The demo data is reset each time you run `npm run demo`.

Wrangler prints a few warnings while the demo starts. They are harmless:

- "Your types might be out of date": only matters when you edit the bindings.
- "Scheduled Workers are not automatically triggered": the daily demo re-seed cron does not run
  locally; `npm run demo` re-seeds instead.
- "CIMD (Client ID Metadata Document) is disabled": an optional OAuth client feature the demo
  does not use.

## Deploy your own

Each copy has one owner, protected by a passphrase you choose. It uses Workers, D1, KV and a cron
trigger, all available on Cloudflare's free plan.

**Button.** [![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/jcallahanp/open-health)

The button works once this repository is public (Cloudflare requires a public GitHub or GitLab
repo). It forks the repo into your account, creates the D1 database and KV namespace named in
`wrangler.jsonc`, asks for `OWNER_PASSPHRASE` (listed in `.dev.vars.example`), and deploys with
`npm run deploy`, which applies the D1 migrations first.
Docs: [Deploy buttons](https://developers.cloudflare.com/workers/platform/deploy-buttons/).

**Manual, with wrangler:**

```sh
npm install
npx wrangler login
npx wrangler d1 create open-health        # copy database_id into wrangler.jsonc (d1_databases)
npx wrangler kv namespace create OAUTH_KV # copy id into wrangler.jsonc (kv_namespaces)
npm run deploy                            # applies migrations to the remote D1, then deploys
npx wrangler secret put OWNER_PASSPHRASE  # a long passphrase, 4+ random words
```

Open `https://open-health.<your-subdomain>.workers.dev/`, sign in with the passphrase, and go to
`/settings` for your MCP URL and time zone. Until the secret is set nobody can sign in.

## Connect your AI

One URL for every client: `https://<your-worker>/mcp`. The client runs an OAuth sign-in where you
type your passphrase. Steps for Claude (web, Desktop, mobile), Claude Code, ChatGPT, Cursor and
stdio-only clients (via `mcp-remote`) are in [AGENTS.md](AGENTS.md), which also holds the usage
guidance for non-Claude agents. Claude users can add the skill in
[skills/open-health/SKILL.md](skills/open-health/SKILL.md). Every client also receives the same
guidance as MCP server `instructions` when it connects.

## Wearables

Optional. Both push to your server with a token you create on `/settings`, which has step-by-step
setup for each app.

- **Apple Health (iPhone, Apple Watch, anything that writes to Apple Health):** the
  [Health Auto Export](https://apps.apple.com/us/app/health-auto-export-json-csv/id1115567069) app,
  REST API automation. Automatic exports are part of the app's paid Premium tier.
- **Android (Health Connect, and any app or watch that writes to it):** the open-source
  [HC Webhook](https://github.com/mcnaveen/health-connect-webhook) app.

Steps, active calories, resting heart rate, HRV, sleep stages, weight and body fat arrive as daily
metrics and readings. Without a wearable you can log everything by hand.

## Architecture

```mermaid
flowchart LR
  AI["Your AI app<br/>(Claude, ChatGPT, Cursor...)"] -->|"MCP + OAuth"| W["Cloudflare Worker"]
  You["You, in a browser"] -->|"passphrase session"| W
  Phone["Health Auto Export /<br/>HC Webhook"] -->|"POST /ingest + token"| W
  W --> D1[("D1 (SQLite)<br/>all health data")]
  W --> KV[("KV<br/>OAuth tokens")]
  Cron["Hourly cron<br/>(demo reseed only)"] --> W
```

One Worker (`src/index.ts`) serves `/mcp` (tools in `src/*.ts`), the dashboard `/`, the console
`/console`, `/settings`, `/export` and `/ingest/*`. Schema: [`migrations/`](migrations/). Design
notes: [docs/DESIGN.md](docs/DESIGN.md).

## Tools

| Tool | What it does |
|---|---|
| `get_settings` | Time zone and units (metric or imperial) |
| `set_settings` | Change time zone and/or units |
| `log_meal` | Log a meal with kcal, protein, carbs, fat (plus fiber, sugar, sodium) |
| `get_meals` | Meals between two dates, or one by entry_id |
| `get_nutrition_summary` | Daily totals vs the goals in force each day |
| `set_goal` | Daily goal from a date on (kcal, macros, weight, steps, sleep), history kept |
| `get_goals` | Goals in force on a date, optionally their history |
| `log_body_reading` | Weight, body fat, blood pressure, pulse |
| `get_body_readings` | Body readings between two dates |
| `get_daily_metrics` | Per-day wearable data: steps, energy, resting HR, HRV, sleep, weight |
| `create_routine` | Create or replace a workout template |
| `get_routines` | List saved routines and their items |
| `delete_routine` | Delete a routine (logged workouts kept) |
| `log_workout` | Log one set or a whole session |
| `get_workouts` | Logged workouts by date and exercise, every set |
| `get_exercise_history` | Best e1RM, heaviest set, last and recent sessions per exercise |
| `get_med_protocol` | Medication plan in force on a date |
| `update_med_protocol` | Add, change, pause or stop a medication |
| `log_medication` | Log a dose taken |
| `get_med_log` | Doses taken and adherence per day |
| `log_bloodwork` | Lab results from one blood draw |
| `get_bloodwork` | Lab results, latest per marker, trend for one marker |
| `update_entry` | Correct any logged entry by kind + entry_id |
| `delete_entry` | Delete a logged entry (or one set or marker of it) |

## Privacy and security

- One owner per deployment. Everything is private: the dashboard, console, settings, export and
  `/mcp` all need the owner's sign-in. There is no public view.
- AI clients connect through OAuth 2.1 (dynamic client registration); the consent page asks for the
  owner passphrase. Wrong passphrases are rate-limited.
- Your data stays in your Cloudflare account (D1). The server makes no LLM or third-party API calls
  and needs no API keys. What your AI app does with what it reads is up to that app.
- Wearable pushes use a separate token, stored only as a SHA-256 hash.
- `/export` downloads everything as one JSON file, or one CSV file per table.
- The demo (`DEMO_MODE=1`) has no sign-in and holds fake data only; never put real data in a demo.

## Checks

```sh
npm run check
```

Runs `checks/run.sh all`: type check, OAuth flow, sign-in and rate limit, every tool's round trip,
seed, dashboard, console, wearable ingest, UI checks and a secrets scan, each against its own local
`wrangler dev` with a fresh database. Takes a few minutes.

## Known issues and limitations

- Early software (0.1); not security-audited.
- One owner per deployment; no sharing or multi-user accounts.
- Apple Health ingest is tested with fixture payloads, not a live iPhone. The exact unit strings
  Health Auto Export sends for weight, HRV and VO2 max are unverified (`lb`/`kg` and `ms` assumed;
  other units are skipped).
- Apple HRV (SDNN) and Health Connect HRV (RMSSD) are stored in the same field; they are not
  directly comparable.
- ChatGPT: full read/write MCP depends on your ChatGPT plan; on some plans connectors are read-only.
- Claude mobile voice mode with this connector is untested.
- The server does no nutrition lookup: your AI estimates macros, so values are only as good as its
  estimate.
- Not medical software and gives no medical advice.

## License

[MIT](LICENSE)