Skip to main content
Glama

get_recent_touch_events

Retrieve recent keyboard and mouse activity events with timestamps, event types, aggregate counts, and active app. Analyze input patterns, detect idle periods, or time activities. Privacy: no keystroke contents are stored.

Instructions

Return the most recent N keyboard and mouse activity events.

Returns events with timestamp, type (key/click/scroll), aggregate counts (not individual keystrokes — content is not logged), and active app.

USE WHEN: analyzing input patterns, idle detection, or activity timing. NOT FOR: keylogging — actual keystroke contents are NEVER stored, only aggregate event metadata.

BEHAVIOR: pure read. Privacy guarantee: no key contents, no clipboard targets, no scroll positions inside sensitive apps.

PARAMETERS: n: number of events. Range 1-500. Default 50.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Primary handler implementation of get_recent_touch_events tool. Decorated with @mcp_app.tool(), it queries an SQLite activity database for recent keyboard/mouse events (typing bursts, clicks, scrolls, drags, corrections) within a configurable time window and event type filter, returning a formatted string.
    @mcp_app.tool()
    def get_recent_touch_events(seconds: int = 300, event_types: str = "all") -> str:
        """Get recent keyboard and mouse activity events.
    
        Returns typing bursts (word counts, WPM), clicks, scrolls, and drags.
        Privacy-safe: shows activity patterns, not keystrokes.
    
        Args:
            seconds: How many seconds back to look (default 300 = 5 min).
            event_types: Filter — "all", "keyboard", "mouse", or "corrections".
        """
        seconds = max(1, min(seconds, 86400))  # cap at 24h
        valid_types = {"all", "keyboard", "mouse", "corrections"}
        if event_types not in valid_types:
            return f"Invalid event_types '{event_types}'. Must be one of: {', '.join(sorted(valid_types))}"
    
        conn = _get_db()
        if not conn:
            return "No activity database found. Touch module may not have been started yet."
    
        try:
            cutoff = time.time() - seconds
            modality_filter = ""
            if event_types == "keyboard":
                modality_filter = "AND modality = 'keys'"
            elif event_types == "mouse":
                modality_filter = "AND modality = 'flow'"
            elif event_types == "corrections":
                modality_filter = "AND event_type = 'correction_detected'"
    
            rows = conn.execute(
                f"SELECT timestamp, modality, event_type, app_name, payload FROM events "
                f"WHERE (modality IN ('keys', 'flow')) {modality_filter} "
                f"AND timestamp > ? ORDER BY timestamp DESC LIMIT 50",
                (cutoff,),
            ).fetchall()
            conn.close()
    
            if not rows:
                return f"No touch events in the last {seconds} seconds."
    
            lines = [f"=== Recent Touch Events (last {seconds}s) ===\n"]
            for row in rows:
                payload = json.loads(row["payload"])
                ts = time.strftime("%H:%M:%S", time.localtime(row["timestamp"]))
                et = row["event_type"]
                app = row["app_name"] or ""
    
                if et == "typing_burst":
                    chars = payload.get("char_count", 0)
                    wpm = payload.get("wpm", 0)
                    bs = payload.get("backspace_count", 0)
                    lines.append(f"[{ts}] BURST {chars} chars, {wpm} WPM, {bs} backspaces")
                elif et == "click":
                    btn = payload.get("button", "?")
                    x, y = payload.get("x", 0), payload.get("y", 0)
                    lines.append(f"[{ts}] CLICK {btn} ({x},{y}) in {app}")
                elif et == "scroll":
                    dy = payload.get("dy", 0)
                    lines.append(f"[{ts}] SCROLL dy={dy} in {app}")
                elif et == "drag":
                    lines.append(f"[{ts}] DRAG in {app}")
                elif et == "correction_detected":
                    orig = payload.get("original_text", "?")
                    corr = payload.get("corrected_text", "?")
                    conf = payload.get("confidence", 0)
                    lines.append(f"[{ts}] CORRECTION: {orig!r} -> {corr!r} (conf={conf:.0%})")
                else:
                    lines.append(f"[{ts}] {et} in {app}")
    
            return "\n".join(lines)
        except Exception as e:
            return f"Error reading touch events: {e}"
  • Registration via @mcp_app.tool() decorator on the FastMCP instance, making get_recent_touch_events available as an MCP tool.
    @mcp_app.tool()
    def get_recent_touch_events(seconds: int = 300, event_types: str = "all") -> str:
  • Input schema defined via function signature: seconds (int, default 300) and event_types (str, default 'all') with validation constraints (1-86400 seconds, one of 'all'/'keyboard'/'mouse'/'corrections').
    def get_recent_touch_events(seconds: int = 300, event_types: str = "all") -> str:
        """Get recent keyboard and mouse activity events.
    
        Returns typing bursts (word counts, WPM), clicks, scrolls, and drags.
        Privacy-safe: shows activity patterns, not keystrokes.
    
        Args:
            seconds: How many seconds back to look (default 300 = 5 min).
            event_types: Filter — "all", "keyboard", "mouse", or "corrections".
        """
        seconds = max(1, min(seconds, 86400))  # cap at 24h
        valid_types = {"all", "keyboard", "mouse", "corrections"}
        if event_types not in valid_types:
            return f"Invalid event_types '{event_types}'. Must be one of: {', '.join(sorted(valid_types))}"
  • Helper function _get_db() that connects to the SQLite activity database at ACTIVITY_DB_PATH, returning None if the DB doesn't exist yet.
    def _get_db() -> sqlite3.Connection | None:
        if not _DB_PATH.exists():
            return None
        conn = sqlite3.connect(str(_DB_PATH), timeout=5)
        conn.row_factory = sqlite3.Row
        return conn
  • Secondary/glama stub handler for get_recent_touch_events — returns a local-only message placeholder (does not contain the real implementation).
    @mcp_app.tool()
    def get_recent_touch_events(n: int = 50) -> str:
        """Return the most recent N keyboard and mouse activity events.
    
        Returns events with timestamp, type (key/click/scroll), aggregate counts
        (not individual keystrokes — content is not logged), and active app.
    
        USE WHEN: analyzing input patterns, idle detection, or activity timing.
        NOT FOR: keylogging — actual keystroke contents are NEVER stored, only
        aggregate event metadata.
    
        BEHAVIOR: pure read. Privacy guarantee: no key contents, no clipboard
        targets, no scroll positions inside sensitive apps.
    
        PARAMETERS:
          n: number of events. Range 1-500. Default 50.
        """
        return _LOCAL_ONLY_MSG
Behavior5/5

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

No annotations provided, but description fully discloses behavior: pure read operation, privacy guarantee (no key contents, no clipboard targets, no scroll positions inside sensitive apps). Adds significant context beyond the schema.

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?

Well-structured with clear sections: function, return format, usage guidance, behavior, parameters. Every sentence adds value, no redundancy. Efficient and front-loaded.

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

Completeness5/5

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

Given the simple single-parameter tool and presence of output schema, the description is complete. It explains the return data sufficiently and addresses privacy concerns, leaving no gaps for the agent.

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

Parameters5/5

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

Parameter 'n' has no schema description (0% coverage), but the description adds meaning: 'number of events. Range 1-500. Default 50.' This compensates fully, providing constraints and defaults not in schema.

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

Purpose5/5

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

Clearly states the tool returns the most recent N keyboard and mouse activity events, with specific details on the returned data (timestamp, type, aggregate counts, active app). Distinguishes from siblings like get_touch_stats and get_activity_summary by focusing on event-level data.

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

Usage Guidelines5/5

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

Explicitly states when to use (analyzing input patterns, idle detection, activity timing) and when not to use (keylogging). Provides a clear privacy guarantee, helping the agent avoid misuse.

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/ContextPulse/contextpulse'

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