android-health-mcp
by imatefx
README.md
# android-health-mcp
Let Claude (or any MCP client) query your phone's health data **live**: Galaxy Watch / Samsung Health, Google Fit, Fitbit, and anything else that writes to **Health Connect**.
```
Galaxy Watch ─► Samsung Health ─┐
Google Fit / Fitbit / … ────────┴─► Health Connect (on the phone)
▲ live queries + de-duplicating aggregates
│
apps/android (foreground service)
│ outbound WebSocket, Bearer DEVICE_TOKEN
▼
Claude ──MCP + OAuth 2.1──► services/mcp-relay (Moleculer + Express, stores no health data)
```
- **Phone:** does all the querying and processing. It sends its tool list when it connects, so tools are defined only in Kotlin.
- **Relay:** only a communication layer. It handles MCP and OAuth for Claude and forwards each tool call to the phone over the WebSocket. If the phone is offline, tools return a clear "phone offline" error.
- **Why a relay at all:** Health Connect has no cloud API, and phones can't accept inbound connections. A small public relay solves both.
- **Google Fit:** its APIs are deprecated. Its data reaches this app through Fit's own Health Connect sync.
## Layout
| Path | What |
|------|------|
| `apps/android` | Kotlin/Compose app: Health Connect permissions, the relay foreground service, and the health tools. See its README. |
| `packages/relay-core` | The reusable transport: the protocol schemas, `DeviceHub` (one phone connection), and the MCP bridge over a `RelayBackend` interface. It has no auth, accounts or billing. |
| `services/mcp-relay` | The self-hosted, single-user relay built on relay-core. Moleculer services: `relay` holds the phone connection, and `api` runs Express with the OAuth server, `/mcp` and the `/device/ws` upgrade. |
| `docs/relay-protocol.md` | The WebSocket contract between the phone and the relay. Change both sides together. |
## Run the relay
```bash
pnpm install
cd services/mcp-relay
cp .env.example .env # set DEVICE_TOKEN (openssl rand -hex 32), ADMIN_PASSWORD, PUBLIC_URL
set -a; source .env; set +a
pnpm dev # or: pnpm build && pnpm start
pnpm test
```
### Docker
```bash
docker build -f services/mcp-relay/Dockerfile -t mcp-relay . # from the repo root
docker run -d --name mcp-relay -p 3000:3000 \
-e PUBLIC_URL=https://health.example.com \
-e DEVICE_TOKEN=... -e ADMIN_PASSWORD=... \
-v mcp-relay-data:/data mcp-relay
```
The image runs as a non-root user, keeps its state in the `/data` volume, and has a health check on `/healthz`.
Deploy it somewhere both the phone and your AI client can reach over **HTTPS**, such as a small VPS behind Caddy, Fly.io, or `tailscale funnel`. Set `PUBLIC_URL` to that origin, and `TRUST_PROXY=1` when behind a reverse proxy. `DATA_DIR` holds only these files: the cached tool list, the OAuth clients and refresh tokens, and the JWT signing key.
## Connect an AI client
The relay is an OAuth 2.1 authorization server. It supports protected-resource metadata, dynamic client registration and PKCE, which is what Claude and other MCP clients expect. You only need the URL:
- **claude.ai / Claude Desktop:** Settings → Connectors → Add custom connector → `https://<your-host>/mcp`.
- **Claude Code:** `claude mcp add --transport http android-health https://<your-host>/mcp`, then run `/mcp` to sign in.
A consent page opens and shows the exact address it will send access to. Enter `ADMIN_PASSWORD`, then click **Allow**. Access tokens last 1 hour. Refresh tokens last 60 days and are rotated on every use.
Other ways to sign in:
- **Other clients:** registration only accepts redirects to `OAUTH_REDIRECT_HOSTS` (default `claude.ai,claude.com`) and loopback addresses. Add hosts such as `chatgpt.com`, or custom schemes through `OAUTH_REDIRECT_SCHEMES`, to allow other clients.
- **Scripts:** set `MCP_TOKEN` and send `Authorization: Bearer $MCP_TOKEN`.
To sign every client out, change `ADMIN_PASSWORD` and restart.
## Tools
The phone defines the tools, and `tools/list` passes them through. The relay adds `get_phone_status` (connected, last seen, device, timezone).
The phone provides overview, daily summaries, sleep, exercise, heart rate and HRV, vitals, body measurements, nutrition, and raw records. All dates are local calendar dates on the phone. Totals use Health Connect's aggregate API, which removes duplicates between apps (for example Samsung Health and Google Fit both counting steps) according to your app priority.
## License
| Part | License |
|------|---------|
| `packages/relay-core`, `docs/relay-protocol.md` | [Apache-2.0](packages/relay-core/LICENSE) |
| Everything else (`apps/android`, `services/mcp-relay`, …) | [AGPL-3.0-only](LICENSE) |
- **Apache-2.0 for the protocol and transport:** anyone can build a compatible phone app or relay.
- **AGPL for the app and self-hosted server:** anyone can run, audit and modify them. Anyone who offers a modified version as a network service must publish their changes.
Copyright © 2026 Stalin Pereira.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues