Skip to main content
Glama

get_sleep_summary

Retrieve detailed sleep analysis data including duration, deep sleep, REM cycles, and wake-up counts from Withings health tracking devices.

Instructions

Get sleep summary data (duration, deep sleep, REM, wake up count, etc.)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
startdateymdNoStart date in YYYY-MM-DD format
enddateymdNoEnd date in YYYY-MM-DD format
lastupdateNoGet sleep data modified since this timestamp

Implementation Reference

  • Registers the 'get_sleep_summary' tool with MCP server, including description and input schema.
    Tool( name="get_sleep_summary", description="Get sleep summary data (duration, deep sleep, REM, wake up count, 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", }, }, }, ), Tool(
  • The handler function that processes arguments, builds API parameters, and calls the Withings sleep summary endpoint.
    async def _get_sleep_summary(self, args: dict) -> dict: """Get sleep summary.""" params = {"action": "getsummary"} if "startdateymd" in args: params["startdateymd"] = args["startdateymd"] if "enddateymd" in args: params["enddateymd"] = args["enddateymd"] if "lastupdate" in args: params["lastupdate"] = self._parse_date(args["lastupdate"]) return await self._make_request("/v2/sleep", params)
  • Defines the input schema for the get_sleep_summary tool, specifying optional date parameters.
    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", }, }, },
  • Helper function to parse date strings or timestamps, used in get_sleep_summary for 'lastupdate' parameter.
    def _parse_date(self, date_str: Optional[str]) -> Optional[int]: """Parse date string to Unix timestamp.""" if not date_str: return None # If already a timestamp if date_str.isdigit(): return int(date_str) # Parse YYYY-MM-DD format try: dt = datetime.strptime(date_str, "%Y-%m-%d") return int(dt.timestamp()) except ValueError: raise ValueError(f"Invalid date format: {date_str}. Use YYYY-MM-DD or Unix timestamp")
  • Shared helper to make authenticated HTTP requests to Withings API endpoints, called by get_sleep_summary.
    async def _make_request(self, endpoint: str, params: dict) -> 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, ) response.raise_for_status() data = response.json() if data.get("status") != 0: raise Exception(f"API error: {data}") return data.get("body", {})

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/schimmmi/withings-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server