fitbit-mcp

fitbit-mcp

MCP server for the Fitbit Web API with OAuth PKCE, local cache, and trend analysis.

Category
访问服务器

README

fitbit-mcp

CI License: GPL v3 Python 3.13+ Glama MCP Server

MCP server for the Fitbit Web API with OAuth PKCE, local SQLite cache, and trend analysis.

Designed for Claude Code and other MCP clients. Syncs your Fitbit data to a local database for fast, offline queries - no API calls needed after the initial sync.

Features

  • OAuth 2.0 PKCE - Secure auth flow, no client secret needed
  • Local SQLite cache - Sync once, query instantly
  • Incremental sync - Only fetches new data since last sync
  • 9 MCP tools - Sync, query (7 data types), and trend analysis
  • Live mode - Bypass cache and query the API directly
  • CLI - Auth setup, sync, and JSON import from the command line
  • Rate limit handling - Automatic retry on 429 responses

Data types

Tool Data
fitbit_get_heart_rate Resting HR, HR zones
fitbit_get_activity Steps, calories, active minutes, distance
fitbit_get_exercises Exercise sessions (name, duration, HR, calories)
fitbit_get_sleep Duration, efficiency, sleep stages
fitbit_get_weight Weight, BMI, body fat %
fitbit_get_spo2 Blood oxygen saturation (avg/min/max)
fitbit_get_hrv Heart rate variability (RMSSD)
fitbit_trends Aggregated averages (weekly/monthly/quarterly)

Requirements

Setup

1. Install

pip install .

Or for development:

pip install -e ".[dev]"

2. Register a Fitbit app

  1. Go to dev.fitbit.com/apps and create a new app
  2. Set OAuth 2.0 Application Type to Personal
  3. Set Redirect URL to http://localhost:8080
  4. Note your Client ID (you won't need the client secret - PKCE doesn't use one)

3. Authenticate

fitbit-mcp auth

This opens your browser for Fitbit login, exchanges the auth code via PKCE, and saves tokens locally.

Tokens are stored in ~/.config/fitbit-mcp/fitbit_tokens.json with 0600 permissions. Access tokens expire in 8 hours and are refreshed automatically. Refresh tokens expire after 90 days of inactivity.

4. Register with Claude Code

claude mcp add -s user fitbit -- fitbit-mcp

5. First sync (optional)

Query tools auto-sync on first use, so you can skip this step. To pre-populate the cache or sync a longer history, run:

fitbit-mcp sync --days 30

CLI usage

fitbit-mcp              Start the MCP server (stdio transport)
fitbit-mcp auth         Interactive OAuth setup
fitbit-mcp sync         Sync data to local cache
  --days N              Days of history for first sync (default: 30)
  --types TYPE,...      Data types to sync (default: all)
fitbit-mcp import       Import existing JSON data files
  --data-dir PATH       Directory containing JSON files

MCP tool reference

Query tools auto-sync on the first query of each day per data type. Use live=True to bypass the cache entirely and fetch directly from the API.

All query tools accept these common parameters:

  • start_date - Start date as YYYY-MM-DD, YYYY-MM, or 30d (relative). Default: last 30 days.
  • end_date - End date as YYYY-MM-DD. Default: today.
  • live - If true, fetch from Fitbit API instead of cache (bypasses auto-sync).

fitbit_get_exercises also accepts:

  • exercise_type - Filter by activity name (case-insensitive substring match), e.g. "cycling", "walk", "run". Default: all types.

fitbit_sync

Syncs data from the Fitbit API to the local SQLite cache. Query tools call this automatically on first use of the day, so explicit calls are only needed for longer history or forced refresh.

  • data_types - What to sync: all, heart_rate, activity, exercises, sleep, weight, spo2, hrv. Comma-separated. Default: all.
  • days - Days of history for first sync (default: 30). Subsequent syncs are incremental.

fitbit_trends

Aggregated trend analysis from cached data.

  • data_type - What to analyse: heart_rate, activity, exercises, sleep, weight, spo2, hrv. Default: activity.
  • period - Aggregation: weekly, monthly, quarterly. Default: monthly.
  • start_date - Start date. Default: last 12 months (365 days).
  • end_date - End date. Default: today.
  • compare - Compare two periods: last_30d vs previous_30d, 2026-03 vs 2026-02, 2026-Q1 vs 2025-Q4. When set, period/start_date/end_date are ignored.

OAuth scopes

The following Fitbit API scopes are requested during setup:

Scope Data accessed
activity Steps, calories, active minutes, distance
heartrate Resting HR and HR zones
sleep Sleep duration and stages
weight Weight, BMI, body fat %
oxygen_saturation SpO2 (blood oxygen)
profile User profile (user ID, display name)

These are the minimum scopes needed for all 9 tools. If you only need a subset, you can edit FITBIT_SCOPES in config.py before setup.

Configuration

Paths are overridable via environment variables:

Variable Default Description
FITBIT_MCP_CONFIG_DIR ~/.config/fitbit-mcp/ Directory for OAuth credentials
FITBIT_MCP_DB_PATH ~/.local/share/fitbit-mcp/fitbit.db SQLite database path

Rate limits

The Fitbit API allows 150 requests per hour. The sync tool handles rate limits automatically, but be aware:

  • Activity sync uses 1 API call per day (no date-range endpoint available)
  • A 30-day initial sync uses ~30 of your 150/hour quota
  • Heart rate, sleep, weight, SpO2, and HRV use date-range endpoints and are much more efficient

Use live=False (the default) to query from cache and avoid API calls entirely.

Data safety

This project includes a pre-commit hook (scripts/check-no-data.sh) that prevents accidentally committing:

  • Database files (*.db, *.db-journal, *.db-wal)
  • Config/credentials (config/*.json)
  • Large files (>100KB)

Install it after cloning:

cp scripts/check-no-data.sh .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

Importing existing data

If you have existing Fitbit data as JSON files (e.g. from a previous export or script), you can bulk-import them:

fitbit-mcp import --data-dir /path/to/json/files/

Expected file names: heart_rate.json, activity.json, exercises.json, sleep.json, weight.json, spo2.json, hrv.json. See src/fitbit_mcp/importer.py for the expected JSON format.

Contributing

See CONTRIBUTING.md for development setup, the test workflow, and the pre-commit hook. Changes are tracked in CHANGELOG.md.

License

GPL-3.0-or-later

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选