Skip to main content
Glama
Mi Fitness MCP

Mi Fitness MCP

by kaarlyz
  • Offline-first SQLite cache with incremental watermarks, versioned migrations, and multi-device scoping

  • Full wearable coverage: daily activity, sleep (stages, naps, efficiency, respiratory rate, sleep HR/SpO2), workouts, body measurements, heart rate, SpO2, stress, and daily band/watch metrics (RHR, VO2 max, PAI, vitality, training load)

  • Dual transport: standard stdio for local MCP clients and authenticated Streamable HTTP + Legacy SSE (--transport http)

  • Cross-distro & headless ready: stores credentials in the OS keyring when available, with automatic fallback to a restricted local credentials file (chmod 600) or environment variables on tiling WMs (Hyprland/Sway/i3), SSH, WSL, and containers

Quick Start

1. Install

git clone https://github.com/kaarlyz/mi-fitness-mcp.git
cd mi-fitness-mcp
python3 -m venv .venv
source .venv/bin/activate
pip install -e .

Or with uv:

git clone https://github.com/kaarlyz/mi-fitness-mcp.git
cd mi-fitness-mcp
uv sync

2. Get Xiaomi Credentials

  1. Open https://account.xiaomi.com in your browser and sign in.

  2. Open DevTools → Cookies for account.xiaomi.com.

  3. Copy userId and passToken.

3. Configure & Verify

mi-fitness-mcp setup --mode mi_fitness_cloud --user-id "<userId>" --region sg --timezone Asia/Jakarta
mi-fitness-mcp doctor

Notes:

  • Interactive setup prompts for passToken without echoing it to the terminal.

  • For automation, pass --pass-token-stdin or set MI_FITNESS_USER_ID and MI_FITNESS_PASS_TOKEN.

  • On systems without a running OS Secret Service (NoKeyringError), setup automatically stores credentials in ~/.config/mi-fitness-mcp/credentials.json with 0600 permissions (or pass --credential-store file).

  • Regional backends (cn, de, i2, ru, sg, us) are supported; ru remains the default if omitted, and global/EU accounts automatically discover and persist their accepted region.

4. Sync & Run

mi-fitness-mcp sync --start-date 2026-01-01 --end-date 2026-12-31
mi-fitness-mcp serve

To inspect exact XDG config, credentials, and SQLite database paths (useful before switching distros):

mi-fitness-mcp paths

Related MCP server: Mi Fitness MCP

MCP Client Configuration

stdio (Claude Desktop, Cursor, Antigravity, Zed)

See mcp-server-config.example.json and examples/mcp-stdio.json:

{
  "mcpServers": {
    "mi-fitness": {
      "command": "/path/to/mi-fitness-mcp/.venv/bin/mi-fitness-mcp",
      "args": ["serve"]
    }
  }
}

Streamable HTTP / Legacy SSE

Start the HTTP server (generates a random auth token if MI_FITNESS_MCP_HTTP_TOKEN / --auth-token is omitted):

mi-fitness-mcp serve --transport http --host 127.0.0.1 --port 8765

Connect using either the printed secret URL prefix (/t/<token>/mcp or /t/<token>/sse) or Authorization: Bearer <token> on /mcp. See examples/mcp-http.json and examples/mi-fitness-mcp.service.

Supported Data & MCP Tools

17 MCP tools across 8 synchronized data types (daily_activity, sleep, workouts, body_measurements, heart_rate, spo2, stress, daily_metrics):

Category

Tools

Connection & Sync

get_connection_status, sync_data, get_data_coverage, get_profile

Activity & Trends

get_daily_summary, query_metric_series, query_daily_metrics, get_health_highlights

Sleep & Vitals

query_sleep, query_heart_rate, query_spo2, query_stress, query_body_measurements

Workouts

query_workouts, summarize_workouts, get_workout_records, compare_workout_periods

Full parameter and metric documentation is available in docs/TOOLS.md.

Documentation

  • docs/SETUP.md — installation, credential extraction, CLI commands, and HTTP/stdio setup

  • docs/DISTRO_MIGRATION.md — backing up/moving between Linux distros, Hyprland/Sway/headless setups, and keyring troubleshooting

  • docs/TOOLS.md — full catalog of all 17 MCP tools, data types, and supported metrics

  • SECURITY.md — credential storage model and safe usage guidelines

  • CONTRIBUTING.md — local setup, testing, and PR checklist

Endpoint Probe Utility

For debugging Xiaomi regional endpoints and raw cloud keys locally:

uv run python probe_mifitness.py --user-id "<userId>"

It prompts for passToken silently or accepts --pass-token-stdin / MI_FITNESS_PASS_TOKEN.

Development

ruff check .
pytest -q
python -m build

CI runs on Python 3.11, 3.12, and 3.13, keeps HTTP tests offline via respx, checks ruff, measures coverage, builds a wheel, and smoke-tests CLI subcommands in a clean virtual environment.

Configuration Compatibility

  • SQLite schema upgrades run automatically through the versioned migration runner (LATEST_SCHEMA_VERSION = 10) without losing existing data.

  • busy_timeout configures SQLite lock waiting in milliseconds (default 5000).

  • Legacy keys (auto_sync_on_start, stale_after_minutes, store_raw_payloads, default_lookback_days, logs_path) remain accepted when loading older config.json files as deprecated no-ops, and are omitted when saving fresh configs.

Credits & Disclaimer

Originally based on kubulashvili/mi-fitness-mcp (MIT License), extended with sleep/SpO2/stress/daily band metrics, Streamable HTTP & Legacy SSE transport, and cross-distro credential portability.

This is an unofficial project and is not affiliated with Xiaomi.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      C
      maintenance
      MCP server that provides local caching, sync, and tools for Zepp Life health data including steps, sleep, heart rate, workouts, and body measurements, supporting both file exports and cloud session access.
      10
      17
      MIT
    • A
      license
      C
      quality
      C
      maintenance
      Enables reading and syncing Xiaomi Mi Fitness health data (steps, heart rate, sleep, workouts) from the Chinese cloud region to a local SQLite database via MCP tools.
      10
      21
      MIT
    • A
      license
      A
      quality
      A
      maintenance
      Provides local MCP tools to query your own Xiaomi Mi Fitness health data (sleep, workouts, heart rate, etc.) stored in a local SQLite database, enabling AI assistants to access personal health records without exposing credentials.
      17
      81
      AGPL 3.0