Polar Health Data (self-hosted)

io.github.StuMason由 GitHub 帳號 StuMason 發布v1.6.2更新於 Oct 24, 2026

Self-hosted Polar health analytics with a built-in MCP server: sleep, HRV, workouts, baselines.

概覽

AI 產生的概覽

自架的 Polar 健康資料分析伺服器,內建 MCP 端點,讓助理讀取你的睡眠、HRV、訓練紀錄與個人基準。

可以做什麼
  • 取得一次性的健康評估與訓練準備度結論
  • 讀取睡眠、恢復、夜間充電、活動與訓練紀錄
  • 查詢連續心率、血氧、ECG、皮膚溫度等生物感測資料流
  • 將數值與個人基準比對,找出模式與異常
  • 觸發並控制從 Polar AccessLink 同步資料
適用情境
適合配戴 Polar 裝置、希望把完整歷史保存在自己的 PostgreSQL 而非 Polar 僅 28-30 天視窗內,並想讓助理依據這些資料回答訓練與恢復問題的人。
執行需求
以自架 Docker 容器(或從原始碼)執行,需要 PostgreSQL 資料庫(DATABASE_URL)。需要 Polar AccessLink OAuth 憑證 POLAR_CLIENT_ID 與 POLAR_CLIENT_SECRET,正式環境還需 ENCRYPTION_KEY。設定 BASE_URL 可啟用 MCP 連接器的 OAuth 登入;無介面用戶端可用 X-API-Key 標頭。
安裝前請注意
它保存敏感健康資料與 Polar OAuth 權杖,需妥善保護 DATABASE_URL、POLAR_CLIENT_SECRET 與 ENCRYPTION_KEY,並讓部署維持驗證,因為 API 端點會暴露健康紀錄。主 API_KEY 會略過速率限制。同步會寫入資料庫,預設每小時執行一次。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Polar Health Data (self-hosted),將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

polar-flow-server

Self-hosted health analytics for Polar devices — own your data, analyze it against your own baselines, and let your AI assistant read it.

[Tests] [Docs] [Docker] [MCP] [License: MIT]

[Dashboard]

Full Documentation · MCP Server · Integration Guide · API Reference

What This Does

Your watch knows more about you than you do — and Polar's API only lets you see the last 28-30 days of it. This server syncs everything, keeps it forever, and turns it into answers:

  1. Syncs all 13 Polar API endpoints automatically — sleep, HRV, activity, workouts, SpO2, ECG, skin temperature, the lot
  2. Stores everything in PostgreSQL. Your data, your server, no cloud between you and it
  3. Computes personal baselines (rolling averages, IQR anomaly bounds) so "is this normal?" means normal for you
  4. Ships a built-in MCP server with OAuth sign-in — ask Claude "should I train hard today?" and it answers from your overnight HRV vs your baseline
  5. Admin dashboard (HTMX), REST API, per-user API keys, multi-user ready

Ask Your AI About Your Body (MCP)

A built-in Model Context Protocol server — protocol revision 2026-07-28, streamable HTTP — runs inside the main server at /mcp. Ten curated tools cover the one-shot health assessment, sleep, recovery, activity, workouts, seven biosensing streams, personal baselines, patterns/anomalies, and sync control.

In clients that render MCP Apps (claude.ai, Claude Desktop, VS Code), asking "how am I doing?" draws an actual card in the conversation:

[MCP Apps card]

Connecting is a sign-in, not a paste. With BASE_URL set, the server is its own OAuth 2.1 authorization server: add https://your-server/mcp as a custom connector in Claude Desktop or claude.ai, click Connect, log in on your server, approve the consent screen. Tokens are user-scoped, expire hourly, refresh automatically, and every connected app is revocable from Settings. API keys still work for headless clients:

bash
claude mcp add polar-health https://your-server.example.com/mcp \  --transport http \  --header "X-API-Key: pfk_your_key_here"

Full setup in the MCP docs.

Architecture

Polar API → polar-flow SDK → Sync Service → PostgreSQL                                                  ↓                                           Admin Dashboard (HTMX)                                                  ↓                                             REST API

Stack:

  • Litestar (async web framework)
  • SQLAlchemy 2.0 (async ORM)
  • PostgreSQL
  • HTMX + Tailwind (admin UI)
  • polar-flow SDK v1.5.0

Don't fancy running a server? A hosted version is in the works — join the waitlist. Self-hosting stays free forever.

Quick Start

Option 1: Docker (Recommended)

bash
# Pull and runcurl -O https://raw.githubusercontent.com/StuMason/polar-flow-server/main/docker-compose.prod.ymldocker-compose -f docker-compose.prod.yml up -d
# That's it. Open http://localhost:8000/admin

Option 2: From Source

bash
git clone https://github.com/StuMason/polar-flow-server.gitcd polar-flow-serverdocker-compose up -d

Setup

  1. Open http://localhost:8000/admin
  2. Get Polar credentials from admin.polaraccesslink.com (set redirect URI to http://localhost:8000/admin/oauth/callback)
  3. Enter credentials and click "Connect with Polar"
  4. Hit "Sync Now" to pull your data

The server syncs data every hour automatically.

Dashboard

The admin panel at /admin/dashboard is organised into tabs (with a floating tab bar on mobile):

  • Overview - stat tiles (HRV, resting HR, SpO2, skin temp, steps, strain, sleep score, alertness...), Today's Readiness recommendations, and "Today at a Glance" mini-charts (sleep stages, heart rate, steps)
  • Trends & Baselines - personal baselines and detected patterns
  • Sleep - sleep score and stage-duration charts
  • Heart Rate - daily HR, HRV and ANS charge charts, biosensing panel
  • Training Load - activity and cardio load charts

[Trends and baselines]

Charts have a selectable 7/14/30-day range and CSV export. API keys are managed from the settings page, with rate limit tracking. All frontend assets are vendored - the dashboard works offline and on a LAN with no CDNs.

Data Synced (13 Endpoints)

EndpointData
SleepScore, stages (light/deep/REM), duration
Nightly RechargeHRV, ANS charge, recovery status
Daily ActivitySteps, distance, calories, active time
ExercisesSport, duration, HR zones, training load
Cardio LoadStrain, tolerance, load ratio, status
SleepWise AlertnessHourly alertness predictions
SleepWise BedtimeOptimal sleep timing recommendations
Activity SamplesMinute-by-minute step data
Continuous HRAll-day heart rate (5-min intervals)
SpO2Blood oxygen tests (compatible devices)
ECGElectrocardiogram tests (compatible devices)
Body TemperatureContinuous body temperature
Skin TemperatureNightly skin temperature with baseline deviation

Configuration

Required Environment Variables

VariableDescriptionRequired
DATABASE_URLPostgreSQL connection stringYes
ENCRYPTION_KEY32-byte Fernet key for token encryptionYes (production)

Generate an encryption key:

bash
python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"

Optional Environment Variables

VariableDescriptionDefault
DEPLOYMENT_MODEself_hosted or saasself_hosted
SYNC_INTERVAL_HOURSAuto-sync frequency1
SYNC_ON_STARTUPSync when server startsfalse
SYNC_DAYS_LOOKBACKDays of history to sync28
LOG_LEVELLogging verbosityINFO
API_KEYMaster API key (bypasses rate limits)None

API Authentication

API endpoints require authentication. Health data should never be publicly accessible.

Authentication Methods

  1. Per-User API Keys (recommended) - Create from the admin dashboard or via OAuth flow
  2. Master API Key - Set API_KEY env var for full access (bypasses rate limits)

Using API Keys

bash
# With per-user API key (includes rate limit headers)curl -H "X-API-Key: pfk_your_api_key_here" \  http://localhost:8000/api/v1/users/{user_id}/sleep?days=7
# Response headers include:# X-RateLimit-Limit: 1000# X-RateLimit-Remaining: 999# X-RateLimit-Reset: 1704067200

Rate Limiting

  • Default: 1000 requests per hour per API key
  • Rate limits reset hourly
  • Master API key (API_KEY env var) bypasses rate limiting
  • Rate limit info returned in response headers

OAuth Integration (SaaS / Multi-User)

For applications that need to integrate with polar-flow-server (e.g., Laravel, mobile apps, web frontends).

This allows any Polar user to connect their account to your application.

OAuth Flow

┌─────────────────┐     ┌─────────────────────┐     ┌─────────────────┐│  Your App       │────▶│  polar-flow-server  │────▶│  Polar Flow     ││  (Laravel etc)  │     │                     │     │  (OAuth)        ││                 │◀────│                     │◀────│                 │└─────────────────┘     └─────────────────────┘     └─────────────────┘

Step 1: Redirect user to start OAuth

GET /oauth/start?callback_url=https://yourapp.com/callback&client_id=your-app-name
ParameterRequiredDescription
callback_urlYesWhere to redirect after OAuth (your app's callback endpoint)
client_idNoIdentifier for your app (validated during exchange)

Step 2: User authorizes on Polar

User is redirected to Polar, logs in with their credentials, and authorizes your app.

Step 3: User redirected to your callback

https://yourapp.com/callback?code=TEMP_CODE_HERE

Step 4: Exchange temp code for API key (server-to-server)

bash
POST /oauth/exchangeContent-Type: application/json
{  "code": "TEMP_CODE_HERE",  "client_id": "your-app-name"}

Response:

json
{  "api_key": "pfk_abc123...",  "polar_user_id": "12345678",  "expires_at": null}

Step 5: Store and use the API key

Store api_key and polar_user_id for this user. Use the API key for all data requests:

bash
curl -H "X-API-Key: pfk_abc123..." \  "https://your-polar-server.com/api/v1/users/12345678/sleep?days=7"

Polar Admin Setup

In admin.polaraccesslink.com, set your app's redirect URI to:

https://your-polar-server.com/oauth/callback

Key Management

bash
# Get key infoGET /api/v1/users/{user_id}/api-key/infoX-API-Key: pfk_...
# Regenerate key (invalidates old key)POST /api/v1/users/{user_id}/api-key/regenerateX-API-Key: pfk_...
# Revoke keyPOST /api/v1/users/{user_id}/api-key/revokeX-API-Key: pfk_...

API Endpoints

bash
# Health check (no auth required)curl http://localhost:8000/health
# Get sleep data (last 7 days)curl -H "X-API-Key: pfk_..." \  "http://localhost:8000/api/v1/users/{user_id}/sleep?days=7"
# Get activity datacurl -H "X-API-Key: pfk_..." \  "http://localhost:8000/api/v1/users/{user_id}/activity?days=7"
# Get nightly recharge (HRV)curl -H "X-API-Key: pfk_..." \  "http://localhost:8000/api/v1/users/{user_id}/recharge?days=7"
# Get exercisescurl -H "X-API-Key: pfk_..." \  "http://localhost:8000/api/v1/users/{user_id}/exercises?days=30"
# Export summarycurl -H "X-API-Key: pfk_..." \  "http://localhost:8000/api/v1/users/{user_id}/export/summary?days=30"

Development

bash
# Install dependenciesuv sync --all-extras
# Start PostgreSQLdocker-compose up -d postgres
# Run server with hot reloaduv run uvicorn polar_flow_server.app:app --reload
# Run testsuv run pytest
# Type checkuv run mypy src/polar_flow_server
# Lintuv run ruff check src/

Production Deployment

Deploy anywhere that runs Docker:

bash
# Download and runcurl -O https://raw.githubusercontent.com/StuMason/polar-flow-server/main/docker-compose.prod.ymldocker-compose -f docker-compose.prod.yml up -d

Coolify, Railway, Render, etc. - Point at the GitHub repo, it builds from the Dockerfile.

Required for production:

  • Set ENCRYPTION_KEY environment variable (tokens won't persist across restarts otherwise)
  • Set DATABASE_URL to your PostgreSQL instance

Database migrations run automatically on startup.

Multi-Tenancy

The server supports multiple users out of the box:

  • Every table includes user_id column
  • All queries scoped by user_id
  • Per-user API keys ensure users can only access their own data
  • Self-hosted: typically one user
  • Multi-user: many users, same codebase

Built With

License

MIT

來源:README.md,提交 dfe3fc2

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

5
  1. v1.6.2最新Oct 19, 2026
  2. v1.6.1Oct 2, 2026
  3. v1.6.0Oct 2, 2026
  4. v1.5.2Oct 2, 2026
  5. v1.5.1Sep 16, 2026

評分

已滿足適用檢查項的 40%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分

    請在儲存庫或註冊中心條目中宣告授權條款。