Skip to main content
Glama

get_hourly_productivity

Analyze hourly productivity patterns to identify peak performance times and schedule focused work sessions effectively.

Instructions

Get productivity breakdown by hour.

Args: date_str: Date to query - 'today', 'yesterday', or 'YYYY-MM-DD'

Shows when during the day you were most/least productive. Useful for identifying peak productivity hours and scheduling deep work.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
date_strNotoday

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Implements the get_hourly_productivity tool using @mcp.tool() decorator. Resolves date, fetches hourly data via RescueTimeClient, aggregates by hour, computes weighted productivity, and formats a visual hourly breakdown with bars and peak summary.
    @mcp.tool()
    async def get_hourly_productivity(date_str: str = "today") -> str:
        """Get productivity breakdown by hour.
    
        Args:
            date_str: Date to query - 'today', 'yesterday', or 'YYYY-MM-DD'
    
        Shows when during the day you were most/least productive.
        Useful for identifying peak productivity hours and scheduling deep work.
        """
        try:
            client = RescueTimeClient()
            resolved_date = resolve_date(date_str)
    
            hourly = await client.get_hourly_data(
                restrict_begin=resolved_date,
                restrict_end=resolved_date,
            )
    
            if not hourly:
                return f"No hourly data for {resolved_date}."
    
            lines = [f"Hourly Productivity ({resolved_date}):", ""]
    
            # Group by hour and find the peak
            hour_data = {}
            for h in hourly:
                if h.hour not in hour_data:
                    hour_data[h.hour] = {"seconds": 0, "productivity_sum": 0, "count": 0}
                hour_data[h.hour]["seconds"] += h.time_seconds
                hour_data[h.hour]["productivity_sum"] += h.productivity * h.time_seconds
                hour_data[h.hour]["count"] += 1
    
            if not hour_data:
                return f"No hourly data for {resolved_date}."
    
            # Display each hour
            for hour in sorted(hour_data.keys()):
                data = hour_data[hour]
                mins = data["seconds"] / 60
                if mins < 1:
                    continue
    
                # Weighted average productivity
                avg_prod = data["productivity_sum"] / data["seconds"] if data["seconds"] > 0 else 0
    
                # Visual representation
                bar_len = min(int(mins / 6), 10)  # 60 mins = 10 blocks
                bar = "\u2588" * bar_len + "\u2591" * (10 - bar_len)
    
                # Productivity indicator
                prod_char = {
                    2: "++", 1: "+ ", 0: "  ", -1: " -", -2: "--"
                }.get(round(avg_prod), "  ")
    
                hour_str = f"{hour:02d}:00"
                lines.append(f"{hour_str} [{prod_char}] {bar} {mins:.0f}m")
    
            # Summary
            total_mins = sum(d["seconds"] for d in hour_data.values()) / 60
            if hour_data:
                peak_hour = max(hour_data.keys(), key=lambda h: hour_data[h]["seconds"])
                lines.append("")
                lines.append(f"Peak hour: {peak_hour:02d}:00 ({hour_data[peak_hour]['seconds']/60:.0f}m)")
                lines.append(f"Total: {total_mins:.0f} minutes logged")
    
            return "\n".join(lines)
    
        except RescueTimeAuthError as e:
            return f"Authentication error: {e}"
        except RescueTimeAPIError as e:
            return f"API error: {e}"
  • Pydantic BaseModel HourlyData defines the structure for hourly productivity data used by the tool's client method.
    class HourlyData(BaseModel):
        """Hourly productivity data from interval perspective."""
    
        hour: int  # 0-23
        date: str
        time_seconds: int
        productivity: int
    
        @property
        def time_minutes(self) -> float:
            """Time in minutes."""
            return self.time_seconds / 60
  • RescueTimeClient.get_hourly_data() method fetches raw hourly productivity data from RescueTime API using interval perspective, parses rows into HourlyData objects.
    async def get_hourly_data(
        self,
        restrict_begin: Optional[str] = None,
        restrict_end: Optional[str] = None,
    ) -> list[HourlyData]:
        """Get hourly productivity breakdown.
    
        Args:
            restrict_begin: Start date (YYYY-MM-DD), defaults to today
            restrict_end: End date (YYYY-MM-DD), defaults to today
        """
        today = date.today().isoformat()
        params = {
            "perspective": "interval",
            "resolution_time": "hour",
            "restrict_kind": "productivity",
            "restrict_begin": restrict_begin or today,
            "restrict_end": restrict_end or today,
        }
    
        data = await self._request("data", params)
    
        if not data or "rows" not in data:
            return []
    
        hourly = []
        for row in data["rows"]:
            # Row format for interval: [date, time_seconds, num_people, productivity]
            # Date is like "2024-01-15T14:00:00"
            date_str = row[0]
            hour = int(date_str.split("T")[1].split(":")[0])
            date_part = date_str.split("T")[0]
    
            hourly.append(
                HourlyData(
                    hour=hour,
                    date=date_part,
                    time_seconds=row[1],
                    productivity=row[3] if len(row) > 3 else 0,
                )
            )
    
        return hourly
  • resolve_date() utility function converts 'today'/'yesterday' to ISO date strings, used in the tool.
    def resolve_date(date_str: str) -> str:
        """Resolve 'today', 'yesterday', or return as-is."""
        if date_str.lower() == "today":
            return date.today().isoformat()
        elif date_str.lower() == "yesterday":
            return (date.today() - timedelta(days=1)).isoformat()
        return date_str
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions the tool 'Shows when during the day you were most/least productive' which gives some behavioral context about the output format. However, it doesn't disclose important behavioral traits like whether this is a read-only operation, what permissions might be required, whether data is real-time or cached, or any rate limits. For a tool with zero annotation coverage, this leaves significant gaps.

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

Conciseness5/5

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

The description is perfectly structured and concise. It begins with the core purpose, provides parameter documentation in a clear 'Args:' section, then adds usage context. Every sentence earns its place, with no wasted words or redundant information. The information is front-loaded with the most important details first.

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

Completeness4/5

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

Given that there's an output schema (which handles return values), 1 parameter, and no annotations, the description does a reasonably complete job. It explains the tool's purpose, documents the parameter, and provides usage context. The main gap is the lack of behavioral transparency about permissions, data freshness, or operational constraints, which would be important for a productivity tracking tool.

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

Parameters3/5

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

The description explicitly documents the single parameter 'date_str' with its allowed values ('today', 'yesterday', or 'YYYY-MM-DD'), which adds crucial meaning beyond the schema's 0% description coverage. However, with only 1 parameter total, the baseline expectation is higher. The description compensates well for the schema's lack of documentation but doesn't provide additional context about parameter behavior beyond the basic format.

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 tool's purpose: 'Get productivity breakdown by hour' specifies the verb ('Get') and resource ('productivity breakdown by hour'). It distinguishes from siblings like 'get_today_summary' by focusing on hourly granularity rather than daily summaries, though it doesn't explicitly contrast with all siblings like 'get_category_breakdown' or 'get_productivity_trend'.

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

Usage Guidelines4/5

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

The description provides clear context for when to use the tool: 'Useful for identifying peak productivity hours and scheduling deep work.' This gives practical application guidance. However, it doesn't explicitly state when NOT to use it or name specific alternatives among the sibling tools, which would be needed for a perfect score.

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/JasonBates/rescuetime-mcp'

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