Skip to main content
Glama
tomekkorbak

Oura MCP Server

by tomekkorbak

get_today_sleep_data

Retrieve today's sleep metrics from the Oura API to analyze sleep quality, duration, and patterns for health tracking and wellness insights.

Instructions

Get sleep data for today.

Returns:
    Dictionary containing sleep data for today

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function decorated with @mcp.tool(), which registers and implements the 'get_today_sleep_data' tool. It fetches today's sleep data using the OuraClient.
    @mcp.tool()
    def get_today_sleep_data() -> dict[str, Any]:
        """
        Get sleep data for today.
    
        Returns:
            Dictionary containing sleep data for today
        """
        if oura_client is None:
            return {"error": "Oura client not initialized. Please provide an access token."}
    
        try:
            today = date.today()
            return oura_client.get_sleep_data(today, today)
        except Exception as e:
            return {"error": str(e)}
  • The OuraClient method that performs the actual API call and data transformation for sleep data, called by the tool handler.
    def get_sleep_data(
        self, start_date: date, end_date: Optional[date] = None
    ) -> dict[str, Any]:
        """
        Get sleep data for a specific date range.
    
        Args:
            start_date: Start date for the query
            end_date: End date for the query (optional, defaults to start_date)
    
        Returns:
            Dictionary containing sleep data
        """
        if end_date is None:
            end_date = start_date
    
        params = {
            "start_date": start_date.isoformat(),
            "end_date": end_date.isoformat(),
        }
    
        url = f"{self.BASE_URL}/sleep"
        response = self.client.get(url, headers=self.headers, params=params)
    
        if response.status_code != 200:
            error_msg = f"Error {response.status_code}: {response.text}"
            raise Exception(error_msg)
    
        # Get the raw response
        raw_data = response.json()
    
        # Transform the data
        transformed_data = []
    
        for item in raw_data.get("data", []):
            # Format time durations
            awake_time = self._format_duration(item.get("awake_time", 0))
            deep_sleep_duration = self._format_duration(
                item.get("deep_sleep_duration", 0)
            )
            light_sleep_duration = self._format_duration(
                item.get("light_sleep_duration", 0)
            )
            rem_sleep_duration = self._format_duration(
                item.get("rem_sleep_duration", 0)
            )
            total_sleep_duration = self._format_duration(
                item.get("total_sleep_duration", 0)
            )
            time_in_bed = self._format_duration(item.get("time_in_bed", 0))
    
            # Format bedtime timestamps
            bedtime_start = self._format_time(item.get("bedtime_start", ""))
            bedtime_end = self._format_time(item.get("bedtime_end", ""))
    
            # Extract readiness data if available
            readiness = item.get("readiness", {})
            readiness_score = readiness.get("score") if readiness else None
            readiness_contributors = (
                readiness.get("contributors", {}) if readiness else {}
            )
    
            # Create transformed item
            transformed_item = {
                "day": item.get("day"),
                "bedtime_start": bedtime_start,
                "bedtime_end": bedtime_end,
                "awake_time": awake_time,
                "deep_sleep_duration": deep_sleep_duration,
                "light_sleep_duration": light_sleep_duration,
                "rem_sleep_duration": rem_sleep_duration,
                "total_sleep_duration": total_sleep_duration,
                "time_in_bed": time_in_bed,
                "efficiency": item.get("efficiency"),
                "latency": item.get("latency"),
                "restless_periods": item.get("restless_periods"),
                "average_breath": item.get("average_breath"),
                "average_heart_rate": item.get("average_heart_rate"),
                "average_hrv": item.get("average_hrv"),
                "lowest_heart_rate": item.get("lowest_heart_rate"),
            }
    
            # Add readiness data if available
            if readiness_score is not None:
                transformed_item["readiness_score"] = readiness_score
                transformed_item["readiness_contributors"] = readiness_contributors
    
            transformed_data.append(transformed_item)
    
        # Return with the original structure but with transformed data
        return {"data": transformed_data}
  • Helper function to parse date strings, used in other tools but available for date handling.
    def parse_date(date_str: str) -> date:
        """
        Parse a date string in ISO format (YYYY-MM-DD).
    
        Args:
            date_str: Date string in ISO format
    
        Returns:
            Date object
        """
        try:
            return date.fromisoformat(date_str)
        except ValueError as err:
            raise ValueError(
                f"Invalid date format: {date_str}. Expected format: YYYY-MM-DD"
            ) from err
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It states it 'Returns: Dictionary containing sleep data for today', which adds some behavioral context about the output format. However, it lacks details on error handling, data freshness, authentication needs, or rate limits, which are important for a data-fetching tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is very concise with two short sentences, front-loading the purpose and then specifying the return format. There's no wasted text, though the structure could be slightly improved by integrating the return info more seamlessly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (0 parameters, no output schema, no annotations), the description is minimally adequate. It covers the purpose and return format, but lacks context on data sources, update frequency, or error cases, which could help the agent use it more effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has 0 parameters, and schema description coverage is 100%, so no parameter documentation is needed. The description doesn't add parameter info, but that's appropriate here. A baseline of 4 is applied as it adequately addresses the lack of parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Get') and resource ('sleep data for today'), making the purpose immediately understandable. It distinguishes from the sibling 'get_sleep_data' by specifying 'today', though it doesn't explicitly contrast with other siblings like 'get_today_readiness_data'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention its sibling tools (e.g., 'get_sleep_data' for other date ranges or 'get_today_readiness_data' for different data types), leaving the agent to infer usage context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/tomekkorbak/oura-mcp-server'

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