get_measurements
Retrieve body measurements such as weight, fat mass, and muscle mass by specifying measurement type, date range, or last update timestamp.
Instructions
Get body measurements (weight, fat mass, muscle mass, etc.)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| meastype | No | Measurement type: weight=1, height=4, fat_free_mass=5, fat_ratio=6, fat_mass_weight=8, diastolic_bp=9, systolic_bp=10, heart_rate=11, temperature=12, spo2=54, body_temp=71, muscle_mass=76, bone_mass=88, pulse_wave_velocity=91 | |
| category | No | Measurement category: 1=real, 2=user_objective | 1 |
| startdate | No | Start date (YYYY-MM-DD) or Unix timestamp | |
| enddate | No | End date (YYYY-MM-DD) or Unix timestamp | |
| lastupdate | No | Get measurements modified since this timestamp |
Implementation Reference
- src/withings_mcp_server/server.py:46-189 (registration)Tool registration for 'get_measurements' inside the list_tools handler, defining its name, description, and inputSchema with parameters meastype, category, startdate, enddate, lastupdate.
Tool( name="get_measurements", description="Get body measurements (weight, fat mass, muscle mass, etc.)", inputSchema={ "type": "object", "properties": { "meastype": { "type": "string", "description": "Measurement type: weight=1, height=4, fat_free_mass=5, fat_ratio=6, fat_mass_weight=8, diastolic_bp=9, systolic_bp=10, heart_rate=11, temperature=12, spo2=54, body_temp=71, muscle_mass=76, bone_mass=88, pulse_wave_velocity=91", "enum": ["1", "4", "5", "6", "8", "9", "10", "11", "12", "54", "71", "76", "88", "91"], }, "category": { "type": "string", "description": "Measurement category: 1=real, 2=user_objective", "enum": ["1", "2"], "default": "1", }, "startdate": { "type": "string", "description": "Start date (YYYY-MM-DD) or Unix timestamp", }, "enddate": { "type": "string", "description": "End date (YYYY-MM-DD) or Unix timestamp", }, "lastupdate": { "type": "string", "description": "Get measurements modified since this timestamp", }, }, }, ), Tool( name="get_activity", description="Get daily activity data (steps, calories, distance, elevation)", inputSchema={ "type": "object", "properties": { "startdateymd": { "type": "string", "description": "Start date in YYYY-MM-DD format", }, "enddateymd": { "type": "string", "description": "End date in YYYY-MM-DD format", }, "lastupdate": { "type": "string", "description": "Get activities modified since this timestamp", }, }, }, ), Tool( name="get_sleep_summary", description="Get sleep summary data (duration, deep sleep, REM, wake up count, breathing disturbances, apnea, etc.)", inputSchema={ "type": "object", "properties": { "startdateymd": { "type": "string", "description": "Start date in YYYY-MM-DD format", }, "enddateymd": { "type": "string", "description": "End date in YYYY-MM-DD format", }, "lastupdate": { "type": "string", "description": "Get sleep data modified since this timestamp", }, "data_fields": { "type": "string", "description": "Comma-separated list of data fields to include (e.g., 'breathing_disturbances_intensity,apnea_hypopnea_index,snoring,rr_average'). If not specified, returns default fields.", }, }, }, ), Tool( name="get_sleep_details", description="Get detailed sleep data with all sleep phases", inputSchema={ "type": "object", "properties": { "startdate": { "type": "string", "description": "Start date (YYYY-MM-DD) or Unix timestamp", }, "enddate": { "type": "string", "description": "End date (YYYY-MM-DD) or Unix timestamp", }, }, }, ), Tool( name="get_workouts", description="Get workout/training sessions data", inputSchema={ "type": "object", "properties": { "startdateymd": { "type": "string", "description": "Start date in YYYY-MM-DD format", }, "enddateymd": { "type": "string", "description": "End date in YYYY-MM-DD format", }, }, }, ), Tool( name="get_heart_rate", description="Get heart rate measurements over a time period", inputSchema={ "type": "object", "properties": { "startdate": { "type": "string", "description": "Start date (YYYY-MM-DD) or Unix timestamp", }, "enddate": { "type": "string", "description": "End date (YYYY-MM-DD) or Unix timestamp", }, }, }, ), Tool( name="get_authorization_url", description="Get OAuth2 authorization URL to authenticate with Withings", inputSchema={ "type": "object", "properties": { "scope": { "type": "string", "description": "OAuth scopes (comma-separated): user.info, user.metrics, user.activity", "default": "user.info,user.metrics,user.activity", }, }, }, ), ] - Input schema for 'get_measurements' tool defining all supported parameters and their types/enums.
inputSchema={ "type": "object", "properties": { "meastype": { "type": "string", "description": "Measurement type: weight=1, height=4, fat_free_mass=5, fat_ratio=6, fat_mass_weight=8, diastolic_bp=9, systolic_bp=10, heart_rate=11, temperature=12, spo2=54, body_temp=71, muscle_mass=76, bone_mass=88, pulse_wave_velocity=91", "enum": ["1", "4", "5", "6", "8", "9", "10", "11", "12", "54", "71", "76", "88", "91"], }, "category": { "type": "string", "description": "Measurement category: 1=real, 2=user_objective", "enum": ["1", "2"], "default": "1", }, "startdate": { "type": "string", "description": "Start date (YYYY-MM-DD) or Unix timestamp", }, "enddate": { "type": "string", "description": "End date (YYYY-MM-DD) or Unix timestamp", }, "lastupdate": { "type": "string", "description": "Get measurements modified since this timestamp", }, }, }, ), - Core handler for 'get_measurements' - builds the API request parameters with action='getmeas' and optional filters, then calls the Withings /measure endpoint.
async def _get_measurements(self, args: dict) -> dict: """Get body measurements.""" params = {"action": "getmeas"} if "meastype" in args: params["meastype"] = args["meastype"] if "category" in args: params["category"] = args["category"] if "startdate" in args: params["startdate"] = self._parse_date(args["startdate"]) if "enddate" in args: params["enddate"] = self._parse_date(args["enddate"], end_of_day=True) if "lastupdate" in args: params["lastupdate"] = self._parse_date(args["lastupdate"]) return await self._make_request("/measure", params) - Helper method _make_request used by get_measurements to make authenticated requests to the Withings API, with automatic token refresh on 401 errors.
async def _make_request(self, endpoint: str, params: dict, retry_on_401: bool = True) -> dict: """Make authenticated request to Withings API.""" headers = self.auth.get_headers() async with httpx.AsyncClient() as client: response = await client.get( f"{self.base_url}{endpoint}", headers=headers, params=params, ) # Don't raise for status yet - check for 401 first data = response.json() # Handle 401 - token expired, try refresh and retry once if data.get("status") == 401 and retry_on_401: await self.auth.refresh_access_token() # Retry the request with new token return await self._make_request(endpoint, params, retry_on_401=False) # Check for other API errors if data.get("status") != 0: raise Exception(f"API error: {data}") return data.get("body", {}) - src/withings_mcp_server/server.py:210-211 (registration)Tool call routing: dispatches 'get_measurements' tool name to the _get_measurements handler method.
elif name == "get_measurements": result = await self._get_measurements(arguments)