search_bear_notes
Search notes in Bear App by query, tag, or limit results to find specific information quickly.
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 |
|---|---|---|---|
| query | No | ||
| tag | No | ||
| limit | No |
Implementation Reference
- main.py:154-170 (handler)The main handler function for the 'search_bear_notes' MCP tool. Registered via @mcp.tool() decorator. Provides the tool schema via type hints and docstring, and delegates to the search_notes helper with error handling.@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 implementing the database query logic for searching Bear notes by query text and tags. Constructs dynamic SQL with parameters for safe querying.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 Bear App's SQLite database with row factory for dict-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()