search_bear_notes
Search and filter notes from the Bear App by query, tag, and limit to retrieve relevant results with metadata, enabling efficient organization and access to information.
Instructions
Search Bear App notes
Args: query: Text to search for (searches in title and content) tag: Tag to filter by (without # symbol) limit: Maximum number of results
Returns: List of matching notes with metadata
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| query | No | ||
| tag | No |
Implementation Reference
- main.py:154-170 (handler)The handler function for the 'search_bear_notes' tool. It is registered via the @mcp.tool() decorator and delegates the core search logic to the search_notes helper function, handling errors gracefully.@mcp.tool() def search_bear_notes(query: str = "", tag: str = "", limit: int = 20) -> List[Dict[str, Any]]: """ Search Bear App notes Args: query: Text to search for (searches in title and content) tag: Tag to filter by (without # symbol) limit: Maximum number of results Returns: List of matching notes with metadata """ try: return search_notes(query, tag, limit) except Exception as e: return [{"error": f"Search error: {str(e)}"}]
- main.py:28-79 (helper)Core helper function that executes the SQL query against the Bear database to search notes by query string and/or tag, constructs result dictionaries with metadata including preview and word count.def search_notes(query: str = "", tag: str = "", limit: int = 20) -> List[Dict[str, Any]]: """Search Bear notes""" conn = get_bear_db_connection() try: # Base query sql = """ SELECT ZUNIQUEIDENTIFIER as id, ZTITLE as title, ZTEXT as content, ZCREATIONDATE as created_date, ZMODIFICATIONDATE as modified_date, ZTRASHED as is_trashed FROM ZSFNOTE WHERE ZTRASHED = 0 """ params = [] # Add search criteria if query: sql += " AND (ZTITLE LIKE ? OR ZTEXT LIKE ?)" params.extend([f"%{query}%", f"%{query}%"]) # Add tag filter if tag: sql += " AND ZTEXT LIKE ?" params.append(f"%#{tag}%") sql += " ORDER BY ZMODIFICATIONDATE DESC LIMIT ?" params.append(limit) cursor = conn.execute(sql, params) 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 }) return results finally: conn.close()
- main.py:19-26 (helper)Helper function to establish a connection to the Bear App SQLite database, setting row_factory for dictionary-like 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
- main.py:154-154 (registration)The @mcp.tool() decorator registers the search_bear_notes function as an MCP tool.@mcp.tool()