get_recent_notes
Retrieve recently modified notes from the Bear App by specifying the number of days to look back and the maximum results to return.
Instructions
Get recently modified notes
Args: days: Number of days to look back limit: Maximum number of results
Returns: Recently modified notes
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| days | No | ||
| limit | No |
Implementation Reference
- main.py:370-426 (handler)The handler function that executes the get_recent_notes tool. It connects to the Bear database, calculates the timestamp for the specified number of days ago using the Core Data epoch, queries for non-trashed notes modified since then, orders by modification date descending, limits results, and returns formatted note dictionaries with preview and word count.def get_recent_notes(days: int = 7, limit: int = 20) -> List[Dict[str, Any]]: """ Get recently modified notes Args: days: Number of days to look back limit: Maximum number of results Returns: Recently modified notes """ try: conn = get_bear_db_connection() # Calculate timestamp for N days ago # Bear uses Core Data timestamps (seconds since 2001-01-01) import time import datetime now = datetime.datetime.now() days_ago = now - datetime.timedelta(days=days) # Convert to Core Data timestamp core_data_epoch = datetime.datetime(2001, 1, 1) timestamp = (days_ago - core_data_epoch).total_seconds() cursor = conn.execute(""" SELECT ZUNIQUEIDENTIFIER as id, ZTITLE as title, ZTEXT as content, ZCREATIONDATE as created_date, ZMODIFICATIONDATE as modified_date FROM ZSFNOTE WHERE ZTRASHED = 0 AND ZMODIFICATIONDATE > ? ORDER BY ZMODIFICATIONDATE DESC LIMIT ? """, (timestamp, limit)) results = [] for row in cursor.fetchall(): content = row["content"] or "" results.append({ "id": row["id"], "title": row["title"] or "Untitled", "content": content, "created_date": row["created_date"], "modified_date": row["modified_date"], "preview": content[:200] + "..." if len(content) > 200 else content, "word_count": len(content.split()) if content else 0 }) conn.close() return results except Exception as e: return [{"error": f"Error getting recent notes: {str(e)}"}]
- main.py:369-369 (registration)The @mcp.tool() decorator registers the get_recent_notes function as an MCP tool in the FastMCP server.@mcp.tool()
- main.py:19-26 (helper)Helper function used by get_recent_notes to establish a connection to the Bear App's SQLite database, setting row_factory for named access.def get_bear_db_connection(): """Connect to Bear database""" if not os.path.exists(BEAR_DB_PATH): raise FileNotFoundError(f"Bear database not found: {BEAR_DB_PATH}") conn = sqlite3.connect(BEAR_DB_PATH) conn.row_factory = sqlite3.Row # Enable column name access return conn