Quantified Self MCP Server
<div align="center">
# Quantified Self MCP
**Local SQLite health storage, Python analytics, and an MCP server — with source provenance and data-quality caveats.**
A local-first Model Context Protocol (MCP) server for personal health exports (Apple Health, Health Auto Export, Garmin, Fitbit, Oura, Health Connect, Google Fit, WHOOP v2 JSON, and CSV). Keep storage and math on your machine, use **LM Studio / Ollama** for local inference or connect **Claude Desktop / Cursor / Windsurf** with field-level redaction.
<!-- mcp-name: io.github.Thecimal/quantified-self-mcp -->
<p align="center">
<a href="https://github.com/Thecimal/quantified-self-mcp/actions/workflows/ci.yml"><img src="https://github.com/Thecimal/quantified-self-mcp/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
<a href="https://github.com/Thecimal/quantified-self-mcp/actions/workflows/codeql.yml"><img src="https://github.com/Thecimal/quantified-self-mcp/actions/workflows/codeql.yml/badge.svg" alt="CodeQL"></a>
<a href="https://pypi.org/project/quantified-self-mcp/"><img src="https://img.shields.io/pypi/v/quantified-self-mcp.svg" alt="PyPI"></a>
<a href="https://pypi.org/project/quantified-self-mcp/"><img src="https://img.shields.io/pypi/pyversions/quantified-self-mcp.svg" alt="Python Versions"></a>
<a href="https://github.com/Thecimal/quantified-self-mcp/blob/main/LICENSE"><img src="https://img.shields.io/github/license/Thecimal/quantified-self-mcp" alt="License"></a>
<a href="https://glama.ai/mcp/servers/Thecimal/quantified-self-mcp"><img src="https://glama.ai/mcp/servers/Thecimal/quantified-self-mcp/badges/score.svg" alt="Glama Score"></a>
<a href="https://m8ven.ai/mcp/thecimal-quantified-self-mcp-v6tlvp"><img src="https://m8ven.ai/badge/mcp/thecimal-quantified-self-mcp-v6tlvp" alt="M8ven Score"></a>
<a href="https://mcpservers.org/servers/thecimal/quantified-self-mcp"><img src="https://mcpservers.org/badge.svg" alt="Listed on mcpservers.org"></a>
<a href="https://github.com/astral-sh/ruff"><img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff"></a>
</p>
<p align="center">
<a href="#-instant-client-setup"><b>⚡ Instant Client Setup</b></a> •
<a href="#-quick-start"><b>🚀 Quick Start</b></a> •
<a href="#-why-quantified-self-mcp"><b>💡 Why This?</b></a> •
<a href="#-data-quality-caveats--provenance"><b>🔎 Data-Quality Checks</b></a> •
<a href="#-supported-data--integrations"><b>📊 Supported Data</b></a> •
<a href="https://github.com/Thecimal/quantified-self-mcp/discussions"><b>💬 Community & Discussions</b></a> •
<a href="docs/"><b>📚 Documentation</b></a>
</p>
<img width="1200" height="420" alt="Quantified Self MCP Architecture" src="https://raw.githubusercontent.com/Thecimal/quantified-self-mcp/main/docs/assets/banner.svg" />
</div>
---
## ⚡ Instant Client Setup
Try it in 20 seconds with 60 days of synthetic sample data (no health export required):
```bash
pip install quantified-self-mcp
quantified-self-init-db --demo
```
Then connect your AI client. **Storage and analytics always stay in local SQLite** — choose a **100% local model** (LM Studio / Ollama) for zero-cloud inference, or a **cloud assistant** (Claude Desktop / Cursor / Windsurf) with optional `HEALTH_PRIVATE_FIELDS` redaction:
### 100% Local AI: LM Studio & Ollama (Zero Cloud Inference)
* **LM Studio:** Open **Program → Install → Edit `mcp.json`** (see [LM Studio Setup Guide](docs/clients/lm-studio.md)) and load any tool-calling model (e.g., Qwen or Llama):
```json
{
"mcpServers": {
"quantified-self": {
"command": "uvx",
"args": ["quantified-self-mcp"]
}
}
}
```
* **Ollama + Open WebUI:** Bridge stdio MCP to Open WebUI via `mcpo` (see [Open WebUI Setup Guide](docs/clients/open-webui.md)):
```bash
mcpo --port 8765 -- uvx quantified-self-mcp
```
Then add `http://localhost:8765` under **Settings → Tools → Add Tool Server** in Open WebUI.
### Cloud Assistants (Local SQLite + Cloud LLM)
* **Claude Desktop:** Add to `claude_desktop_config.json` (`~/Library/Application Support/Claude/` on macOS, `%APPDATA%\Claude\` on Windows, `~/.config/Claude/` on Linux):
```json
{
"mcpServers": {
"quantified-self": {
"command": "uvx",
"args": ["quantified-self-mcp"]
}
}
}
```
*(Or point `"command"` to your installed `quantified-self-mcp` binary if installed via pip).*
* **Cursor:** Add to `.cursor/mcp.json` or **Settings → Features → MCP Servers → Add New MCP Server** using the same JSON block above ([Cursor Guide](docs/clients/cursor.md)).
* **Windsurf:** Add the same JSON block to your `mcp_config.json`.
> [!TIP]
> **Need step-by-step setup for Android Health Connect or Automated Apple Health Sync?**
> See [Client Guides](docs/clients/) and [Automated Apple Health Sync](docs/apple-health-auto-sync.md).
---
## 🚀 Quick Start
### 1. Install
```bash
pip install quantified-self-mcp
```
### 2. Initialize (Try in 10 Seconds with Demo Data)
Quantified Self MCP automatically creates and manages a local SQLite database (`health.db`). You can test it immediately with 60 days of realistic sample data, or import your personal health history:
```bash
# Instant demo mode (seeds 60 days of synthetic health data):
quantified-self-init-db --demo
# Or import your own wearable exports:
quantified-self-init-db export.zip # Apple Health (.zip or export.xml)
quantified-self-init-db hae.json --source health-auto-export # Health Auto Export JSON (iOS)
quantified-self-init-db garmin_export.zip --source garmin # Garmin Connect GDPR JSON / CSV
quantified-self-init-db takeout-fitbit.zip --source fitbit # Fitbit Google Takeout JSON / CSV
quantified-self-init-db oura.json --source oura # Oura Ring API (v2)
quantified-self-init-db health_connect_export.json --source health-connect # Android Health Connect
quantified-self-init-db takeout-fit.zip --source google-fit # Google Fit (Google Takeout)
quantified-self-init-db whoop.json --source whoop # WHOOP Developer API (v2, synthetic-tested)
quantified-self-init-db your-health-data.csv # CSV
```
### 3. Verify Setup
Run the built-in diagnostic tool to verify Python dependencies, schema integrity, and database readiness:
```bash
quantified-self-doctor
```
### 4. Ask Your AI
Open your MCP-connected assistant and ask questions in plain English:
```text
"How has my sleep and resting heart rate changed over the last 30 days?"
"Why did my HRV drop last week?"
"What patterns exist between my workout minutes and sleep quality?"
"Which of my health metrics changed the most this month?"
```
---
## 💡 Why Quantified Self MCP?
Most health apps either trap your data in a closed cloud dashboard or feed raw numbers blindly into an LLM. Quantified Self MCP provides a **trustworthy, analytical bridge**:
| Feature | Standard Health Dashboards | Naive LLM Prompts | Quantified Self MCP |
| :--- | :---: | :---: | :---: |
| **Data Ownership** | ❌ Locked in Cloud | ⚠️ Raw exports pasted to cloud | ✅ **Local SQLite (`health.db`)** |
| **Privacy Redaction** | ❌ All or nothing | ❌ Raw data dumped | ✅ **Granular Field Exclusion** |
| **Data-Quality Checks** | ⚠️ Uncalibrated percentages | ❌ Hallucinated correlations | ✅ **Sample, Gap & Source Caveats** |
| **Provenance Tracking** | ❌ Opaque | ❌ None | ✅ **Per-device origin resolution** |
| **Atomic Snapshots** | ⚠️ Manual exports | ❌ None | ✅ **WAL-safe backup/restore** |
### 🔒 Local Storage vs. Where Inference Runs
Your database and MCP server run locally in SQLite with no proprietary health cloud or telemetry. **Local storage is not local inference:** if you connect a cloud assistant (like Claude Desktop or Cursor), the JSON returned by tool calls goes to that LLM provider. For end-to-end local privacy, pair the server with a local model via **LM Studio** or **Ollama**.
You can also redact specific sensitive metrics from being exposed to any AI client:
```bash
export HEALTH_PRIVATE_FIELDS=weight_kg,mood
```
*Private fields remain stored in SQLite for your own records, but are blocked from all AI queries and analytics.*
---
## 🔎 Data-Quality Caveats & Provenance
When an AI summarizes your personal health logs, **a percentage without coverage context is easy to misread**.
If an LLM sees a 24% drop in HRV, did it come from 30 continuous days of wearable data, or 14 sparse readings with a 5-day gap or a mid-month device switch?
Quantified Self MCP runs deterministic N=1 data-quality checks in Python (`qs_evidence/registry.yaml`) alongside every analytical result:
```text
Analysis Result
↓
claim: ClaimEvidence
├── evidence → Raw coverage observed (days logged, max gap, freshness)
├── profile → Dimension checks (sample size, temporal spread, missingness, provenance)
└── decision → Claim tier + mandatory caveats (must_state):
[ insufficient | suggestive | detectable_not_meaningful | supported ]
```
### Example: Naive vs. Caveated AI Response
<img width="1200" height="400" alt="Naive LLM vs Quantified Self MCP ClaimEvidence Output" src="https://raw.githubusercontent.com/Thecimal/quantified-self-mcp/main/docs/assets/demo.svg" />
* **Without Caveats (Naive LLM)**:
> *"Your HRV dropped 24% over the last month. You may be overtraining."*
* **With Quantified Self MCP Caveats**:
> *"Your HRV decreased 24% over the last 30 days — though HRV was logged on 71% of days with a 5-day gap, so this is capped at `suggestive` rather than `supported`. (Source: Apple Watch)."*
> [!NOTE]
> The cutoffs in [`qs_evidence/registry.yaml`](qs_evidence/registry.yaml) are conservative engineering heuristics (not clinical criteria). Today, trends, comparisons, correlations, and anomalies cap at `suggestive` (`practical_not_evaluated`) until practical effect-size checking is implemented; only `baseline` can reach `supported`. See [Evidence Thresholds & Claim Tiers](docs/tools.md#evidence-thresholds--claim-tiers) for the exact numbers.
---
## 📊 Supported Data & Integrations
Quantified Self MCP ships with 20 specialized tools spanning raw measurements, longitudinal statistics, and data health:
```text
AI Agent (Claude / Cursor / LM Studio)
│
MCP Protocol
│
▼
┌──────────────────────────────────────────────────┐
│ Quantified Self MCP │
│ │
│ • Data Access • Longitudinal Analytics │
│ • Workout Tracking • ClaimEvidence Engine │
│ • Provenance Resolver • Data Freshness/Health │
└────────────────────────┬─────────────────────────┘
│
▼
Local SQLite (health.db)
```
### Metrics Supported Out of the Box
| Metric | Category | Standard Unit | Notes |
| :--- | :--- | :--- | :--- |
| 👟 **Steps** | Activity | count | Summed per day with multi-source deduplication |
| 😴 **Sleep** | Recovery | hours | Provenance-checked interval handling |
| ❤️ **Resting Heart Rate** | Cardiovascular | bpm | Daily baseline tracking & anomaly detection |
| 📈 **HRV** (Heart Rate Variability) | Recovery | ms | RMSSD/SDNN normalized |
| ⚖️ **Weight & Body Fat** | Measurements | kg / % | High-precision episodic measurement tracking |
| 🏋️ **Workouts** | Activity | minutes / kcal | Individual workout sessions with sport metadata |
| 🙂 **Mood** | Wellness | 1-5 scale | Subjective well-being logs |
| 💧 **Water Intake** | Nutrition | ml | Daily fluid tracking |
*The schema is fully extensible with custom metric definitions in `metric_registry.py`.*
---
## 🔌 Client Compatibility
| Client / Assistant | Compatibility | Documentation |
| :--- | :---: | :--- |
| **Claude Desktop** | ✅ Official Support | [Claude Desktop Setup Guide](docs/clients/claude-desktop.md) |
| **Cursor** | ✅ Full Support | [Cursor IDE Setup Guide](docs/clients/cursor.md) |
| **Windsurf** | ✅ Full Support | Configure via `mcp_config.json` |
| **LM Studio** | ✅ Local AI | [LM Studio Setup Guide](docs/clients/lm-studio.md) |
| **Open WebUI** | ✅ Self-Hosted | [Open WebUI Setup Guide](docs/clients/open-webui.md) |
| **Android Health Connect** | ✅ Export & Ingest | [Health Connect Guide](docs/clients/android-health-connect.md) |
---
## 🛠️ Operations & Data Safety
### Atomic WAL Backups
Never copy `health.db` while your server or MCP client is running: SQLite runs in WAL mode, meaning uncommitted writes live in `health.db-wal`.
Use the built-in backup CLI, which takes a live, consistent snapshot:
```bash
# Create a verified snapshot:
quantified-self-backup create ~/backups/health-2026-11-04.db
# Safe restore (checks schema integrity before moving old DB aside):
quantified-self-backup restore ~/backups/health-2026-11-04.db
```
### Diagnostics
Run anytime to check your Python runtime, database version, and environment configuration:
```bash
quantified-self-doctor
```
---
## 📚 Documentation
Deep-dive documentation and technical specs:
* **[Complete Tool Catalog (20 Tools)](docs/tools.md)**
* **[Data Import Guide (Apple Health, Health Auto Export, Garmin, Fitbit, Oura, Health Connect, Google Fit, WHOOP, CSV)](docs/importing.md)**
* **[Automated Apple Health Sync (iOS Shortcuts & `launchd`/`cron`)](docs/apple-health-auto-sync.md)**
* **[Client Setup Guides](docs/clients/)**
* **[Security & Threat Model](SECURITY.md)**
* **[Contribution Guidelines](CONTRIBUTING.md)**
* **[Changelog](CHANGELOG.md)**
---
## 🤝 Contributing
Contributions are warmly welcomed! We are actively looking for contributions in:
- New wearable & CGM adapters (Dexcom Clarity CSV, binary Garmin `.fit`)
- Real-account validation & fixtures for the WHOOP v2, Fitbit, and Garmin adapters
- Practical effect-size / minimum-detectable-change evaluators
- Shareable automated local sync recipes (iOS `.shortcut` templates, companion collectors)
Please review [`CONTRIBUTING.md`](CONTRIBUTING.md) and [`CODE_OF_CONDUCT.md`](CODE_OF_CONDUCT.md) before opening a pull request.
---
## 📄 License
Licensed under the [MIT License](LICENSE).
TDQS
Scored across 20 tools
The tools are cleanly separated by purpose: raw vs daily logging, workouts, several read granularities, status, analytics, provenance, export, and clearing. Descriptions include explicit "Do not use this tool when" guidance that resolves subtle overlaps such as read_health_data vs get_metric_history vs read_measurements, and get_recent_changes vs explain_metric_change.
All names use consistent snake_case with a leading verb, e.g. log_measurement, read_health_data, get_baseline, detect_metric_anomalies. The verbs vary by operation but follow a predictable verb_noun pattern with no camelCase or arbitrary style mixing.
At 20 tools the surface is heavy for an agent to navigate, even though each tool targets a real operation. The analytics and read families are defensible individually, but the overall set would benefit from grouping or consolidation.
The server covers logging, daily/raw reading, workouts, analytics, data/import status, provenance, export, and clearing. Minor gaps remain: workout sessions cannot be updated or deleted, individual measurement rows cannot be deleted except via clear_metric, and there is no import-trigger tool despite import status being exposed.