Skip to main content
Glama

get_sleep_details

Retrieve detailed sleep phase data from Withings Health API to analyze sleep patterns and quality over specified date ranges.

Instructions

Get detailed sleep data with all sleep phases

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
startdateNoStart date (YYYY-MM-DD) or Unix timestamp
enddateNoEnd date (YYYY-MM-DD) or Unix timestamp

Implementation Reference

  • The handler function that implements the core logic for the get_sleep_details tool. It prepares the API parameters (action='get', optional startdate/enddate parsed to timestamps) and calls the Withings /v2/sleep endpoint.
    async def _get_sleep_details(self, args: dict) -> dict: """Get detailed sleep data.""" params = {"action": "get"} if "startdate" in args: params["startdate"] = self._parse_date(args["startdate"]) if "enddate" in args: params["enddate"] = self._parse_date(args["enddate"]) return await self._make_request("/v2/sleep", params)
  • The input schema for validating tool arguments: optional startdate and enddate as strings.
    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 registration in list_tools(): defines name, description, and inputSchema for get_sleep_details.
    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", }, }, }, ),
  • Dispatch logic in call_tool(): routes get_sleep_details calls to the _get_sleep_details handler.
    elif name == "get_sleep_details": result = await self._get_sleep_details(arguments)
  • Shared helper for making authenticated HTTP GET requests to Withings API endpoints, used by the handler.
    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