Withings MCP Server

Withings MCP Server

Enables access to Withings Health API data including body measurements, activity tracking, sleep analysis, workouts, and heart rate monitoring through OAuth2 authentication.

Category
访问服务器

README

Withings MCP Server

An MCP (Model Context Protocol) server for integration with the Withings Health API. This server provides access to health data including body measurements, activities, sleep, and more.

Features

  • OAuth2 Authentication with the Withings API
  • Body Measurements: Weight, body fat, muscle mass, blood pressure, heart rate, SpO2, etc.
  • Activity Data: Steps, calories, distance, elevation
  • Sleep Data: Sleep duration, deep sleep, REM sleep, wake-up counts
  • Workout Data: Training sessions and details
  • Heart Rate: Intraday heart rate measurements

Installation

Option 1: Docker (Recommended)

  1. Create Withings API Credentials:

    • Go to Withings Developer Dashboard
    • Create a new application
    • Note your Client ID and Client Secret
    • Set the Redirect URI to http://localhost:8080/callback
  2. Configure environment variables:

# Copy the example file
cp .env.example .env

# Edit .env and add your credentials
WITHINGS_CLIENT_ID=your_client_id_here
WITHINGS_CLIENT_SECRET=your_client_secret_here
WITHINGS_REDIRECT_URI=http://localhost:8080/callback
  1. Generate OAuth tokens:
# First, install locally to run token generation
python -m venv .venv
source .venv/bin/activate
pip install -e .
python generate_tokens.py
  1. Build and run with Docker:
# Build the image
docker build -t withings-mcp-server .

# Run with docker-compose
docker-compose up -d

Option 2: Local Python Installation

  1. Clone repository and install dependencies:
# Create virtual environment (recommended)
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install dependencies
pip install -e .
  1. Create Withings API Credentials:

    • Go to Withings Developer Dashboard
    • Create a new application
    • Note your Client ID and Client Secret
    • Set the Redirect URI to http://localhost:8080/callback
  2. Configure environment variables:

# Copy the example file
cp .env.example .env

# Edit .env and add your credentials
WITHINGS_CLIENT_ID=your_client_id_here
WITHINGS_CLIENT_SECRET=your_client_secret_here
WITHINGS_REDIRECT_URI=http://localhost:8080/callback

Project Structure

withings-mcp-server/
├── src/
│   └── withings_mcp_server/
│       ├── __init__.py
│       ├── auth.py          # OAuth2 authentication
│       └── server.py        # MCP server implementation
├── tests/
│   ├── __init__.py
│   └── test_withings.py     # Manual test script
├── generate_tokens.py       # Token generation script
├── .env.example             # Example environment variables
├── .gitignore
├── pyproject.toml
└── README.md

Testing the Installation

Before using the MCP server, you can verify the connection with the test script:

# Activate virtual environment if not already done
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Run the test script
python tests/test_withings.py

The test script will guide you through the OAuth flow and test various API endpoints:

  • ✓ OAuth authentication
  • ✓ User information
  • ✓ Body measurements (last 30 days)
  • ✓ Activity data (last 7 days)
  • ✓ Sleep data (last 7 days)

Authentication

Before first use, you need to generate OAuth2 tokens. Tokens are automatically saved to the .env file and refreshed when needed.

Quick Start: Token Generation

Use the dedicated token generation script:

python generate_tokens.py

The script will guide you through all steps:

  1. ✓ Check your API credentials
  2. ✓ Generate the authorization URL
  3. ✓ Exchange the code for tokens
  4. ✓ Save tokens automatically to .env
  5. ✓ Verify tokens with a test API call

Alternative: Using Test Script

You can also use the test script which combines OAuth flow and API tests:

python tests/test_withings.py

Manual Authentication

  1. Get authorization URL:

    Use the get_authorization_url tool to generate an OAuth URL

  2. Authenticate in browser:

    Open the URL in your browser and authorize access

  3. Receive authorization code:

    After successful authorization, you'll be redirected to your Redirect URI with a code parameter

  4. Token management:

    Access and Refresh Tokens are automatically:

    • Saved to the .env file
    • Refreshed when expired
    • Updated after each refresh

Available Tools

get_authorization_url

Generates an OAuth2 authorization URL.

Parameters:

  • scope (optional): OAuth scopes (default: "user.info,user.metrics,user.activity")

get_user_info

Retrieves user information.

get_measurements

Retrieves body measurements.

Parameters:

  • meastype (optional): Measurement type
    • 1: Weight (kg)
    • 4: Height (m)
    • 5: Fat-free mass (kg)
    • 6: Body fat percentage (%)
    • 8: Fat mass (kg)
    • 9: Diastolic blood pressure (mmHg)
    • 10: Systolic blood pressure (mmHg)
    • 11: Heart rate (bpm)
    • 12: Temperature (°C)
    • 54: SpO2 (%)
    • 71: Body temperature (°C)
    • 76: Muscle mass (kg)
    • 88: Bone mass (kg)
    • 91: Pulse wave velocity (m/s)
  • category (optional): Category (1=real, 2=user_objective)
  • startdate (optional): Start date (YYYY-MM-DD or Unix timestamp)
  • enddate (optional): End date (YYYY-MM-DD or Unix timestamp)
  • lastupdate (optional): Only measurements since this timestamp

get_activity

Retrieves daily activity data.

Parameters:

  • startdateymd (optional): Start date (YYYY-MM-DD)
  • enddateymd (optional): End date (YYYY-MM-DD)
  • lastupdate (optional): Only activities since this timestamp

get_sleep_summary

Retrieves sleep summary.

Parameters:

  • startdateymd (optional): Start date (YYYY-MM-DD)
  • enddateymd (optional): End date (YYYY-MM-DD)
  • lastupdate (optional): Only sleep data since this timestamp

get_sleep_details

Retrieves detailed sleep data with all sleep phases.

Parameters:

  • startdate (optional): Start date (YYYY-MM-DD or Unix timestamp)
  • enddate (optional): End date (YYYY-MM-DD or Unix timestamp)

get_workouts

Retrieves workout/training sessions.

Parameters:

  • startdateymd (optional): Start date (YYYY-MM-DD)
  • enddateymd (optional): End date (YYYY-MM-DD)

get_heart_rate

Retrieves heart rate measurements over a time period.

Parameters:

  • startdate (optional): Start date (YYYY-MM-DD or Unix timestamp)
  • enddate (optional): End date (YYYY-MM-DD or Unix timestamp)

MCP Configuration

To use the server with Claude Desktop, add the following to your MCP configuration:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json

Docker Configuration

{
  "mcpServers": {
    "withings": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e", "WITHINGS_CLIENT_ID=your_client_id",
        "-e", "WITHINGS_CLIENT_SECRET=your_client_secret",
        "-e", "WITHINGS_ACCESS_TOKEN=your_access_token",
        "-e", "WITHINGS_REFRESH_TOKEN=your_refresh_token",
        "withings-mcp-server"
      ]
    }
  }
}

Local Python Configuration

{
  "mcpServers": {
    "withings": {
      "command": "/path/to/.venv/bin/python",
      "args": ["-m", "withings_mcp_server"],
      "env": {
        "WITHINGS_CLIENT_ID": "your_client_id",
        "WITHINGS_CLIENT_SECRET": "your_client_secret",
        "WITHINGS_ACCESS_TOKEN": "your_access_token",
        "WITHINGS_REFRESH_TOKEN": "your_refresh_token"
      }
    }
  }
}

Example Usage

After configuration, you can make the following requests in Claude Desktop:

"Show me my weight measurements from the last 7 days"
"How many steps did I walk today?"
"How was my sleep quality last night?"
"Show me my heart rate data from today"

API Documentation

For more details about the Withings API:

License

MIT

Notes

  • Tokens are automatically refreshed when they expire
  • All dates can be specified as YYYY-MM-DD or Unix timestamp
  • The API is subject to Withings rate limits (see API documentation)

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选