Labsco
bejaminjones logo

Bear MCP Server

β˜… 34

from bejaminjones

Provides direct access to your Bear notes database for comprehensive note management, bypassing standard API limitations.

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedFreeQuick setup

Bear MCP Server

A Model Context Protocol (MCP) server that provides Claude with comprehensive access to your Bear notes using a hybrid sync-safe approach - combining direct database reads with Bear's API for writes.

πŸ”„ Sync-Safe Hybrid Mode: All operations now work safely with iCloud sync!

⚠️ Disclaimer

This tool uses a hybrid approach: direct database reads + Bear API writes. While comprehensive safety measures are implemented:

  • Read operations access Bear's database directly (read-only, safe)
  • Write operations use Bear's official API (sync-safe)
  • The tool is not affiliated with Bear's developers
  • Always maintain regular Bear backups as good practice

✨ What You Can Do

πŸ“– Read Operations (26 tools) - βœ… ACTIVE

  • Search & Discovery: Full-text search, find similar notes, get suggestions
  • Organization: Browse by tags, analyze note relationships, get statistics
  • Content Analysis: Extract metadata, analyze attachments, find patterns
  • Advanced Queries: Complex filtering, date ranges, content criteria

✏️ Write Operations (6 tools) - βœ… ACTIVE (Sync-Safe)

  • Create Notes: βœ… Via Bear API (sync-safe)
  • Edit Notes: βœ… Via Bear API (sync-safe)
  • Organize: βœ… Via Bear API (sync-safe)
  • Tag Management: βœ… Via Bear API (sync-safe)
  • Hashtag Parsing: βœ… Via Bear API (sync-safe)

How it works: Uses Bear's x-callback-url API for writes, database for reads!

πŸ›‘οΈ Safety Features

  • Hybrid Architecture: Database reads + API writes for maximum safety
  • iCloud Sync Safe: All write operations use Bear's API
  • Conflict Detection: Prevents overwriting concurrent changes
  • Tag Validation: Automatic tag sanitization with warnings
  • Error Handling: Robust error management for all operations

πŸ“Š Capabilities Overview

CategoryToolsStatusKey Features
Basic Operations6βœ… ActiveGet notes, search, browse tags, database stats
Advanced Search8βœ… ActiveFull-text search, similarity matching, complex queries
Analytics6βœ… ActiveContent analysis, relationship mapping, usage patterns
Metadata6βœ… ActiveFile attachments, content structure, organization insights
Write Operations6βœ… ActiveSync-safe via Bear API - full write capability restored!

πŸ›‘οΈ Safety & Best Practices

⚠️ Safety Guidelines

  1. Bear can run during operations - Write operations use Bear's API safely
  2. Automatic tag validation - Tags are sanitized with warnings
  3. iCloud sync compatible - No conflicts or sync issues
  4. Keep Bear updated - Ensure API compatibility

πŸ’‘ Best Practices

  • Read operations are instant - direct database access
  • Write operations work with Bear running or closed
  • Tag warnings show when tags are auto-corrected
  • Use specific search terms for better results
  • Archive notes instead of deleting when possible

🏷️ Tag Formatting Guidelines

βœ… RECOMMENDED TAG FORMATS:

  • Simple tags: work, personal, urgent, meeting
  • Nested categories: work/projects, personal/health, study/math
  • Time-based: 2024, january, q1
  • Project codes: proj001, alpha, beta

❌ AVOID THESE FORMATS (auto-corrected):

  • Hyphens: project-alpha β†’ becomes projectalpha
  • Spaces: work meeting β†’ becomes workmeeting
  • Mixed case: ProjectAlpha β†’ becomes projectalpha

πŸ”§ Automatic Tag Sanitization: The server automatically validates and sanitizes all tags:

  • Lowercase only: Project β†’ project
  • No spaces: tag name β†’ tagname
  • No hyphens: project-alpha β†’ projectalpha
  • No commas: tag,name β†’ tagname
  • βœ… Forward slashes preserved: project/alpha β†’ project/alpha (for nested tags)

Tag warnings are returned when tags are modified, so you'll know exactly what changes were made.

πŸ—οΈ REFACTORED SERVICE ARCHITECTURE

βœ… Completely refactored from monolith to modern service-oriented architecture!

Transformation Overview

We've completely rebuilt the system from a 2,589-line monolithic BearService into a modern, testable, service-oriented architecture:

πŸ”§ Service-Based Design

  • 7 specialized services with clear responsibilities
  • Dependency injection for testability and flexibility
  • Interface-driven development for maintainability
  • 384 comprehensive tests across all services

πŸ›‘οΈ Hybrid Sync-Safe Architecture

  • Read Operations: Direct SQLite database access for maximum performance
  • Write Operations: Bear's x-callback-url API for sync safety
  • Perfect coordination using ZUNIQUEIDENTIFIER bridge

πŸ“Š Quality & Performance

  • 100% TypeScript with strict type checking
  • Comprehensive error handling and validation
  • Multi-level caching for performance optimization
  • Structured logging and health monitoring

Service Architecture

ServiceContainer (Dependency Injection)
β”œβ”€β”€ DatabaseService      (SQLite operations & connection management)
β”œβ”€β”€ CacheService        (Performance optimization & intelligent caching)
β”œβ”€β”€ LoggingService      (Structured logging with Winston)
β”œβ”€β”€ HealthService       (System monitoring & health checks)
β”œβ”€β”€ ValidationService   (Input validation & data sanitization)
β”œβ”€β”€ NoteService         (Note CRUD & lifecycle management)
β”œβ”€β”€ SearchService       (Advanced search & content discovery)
└── TagService          (Tag management & organization)

Why This Architecture Works

The Problem: Monolithic code was hard to test, maintain, and extend.

The Solution: Service-oriented architecture with clear separation of concerns.

The Result:

  • βœ… Maintainable code - Clear service boundaries and responsibilities
  • βœ… 100% test coverage - 384 tests across all services
  • βœ… Type safety - Eliminated 50+ any types
  • βœ… Performance optimized - Multi-level caching and query optimization
  • βœ… Production ready - Comprehensive logging, monitoring, and error handling
  • βœ… Sync-safe operations - Hybrid approach eliminates iCloud conflicts

Current Status

  • βœ… All read operations - Direct database access (26 tools)
  • βœ… All write operations - Sync-safe Bear API (6 tools)
  • βœ… Full feature parity - Everything works as designed
  • βœ… iCloud sync compatible - No conflicts or issues
  • βœ… Duplicate title fix - Notes display titles correctly (no duplication)

πŸ™ Thanks to Bear Team

Special thanks to Danilo from the Bear team who provided the key insight that led to this solution!


🀝 Contributing & Community

The iCloud sync challenge has been solved! πŸŽ‰ Now we're focused on making this the best Bear integration possible. Whether you're a:

  • macOS/iOS developer with API experience
  • Database expert familiar with SQLite optimization
  • Bear power user with workflow insights
  • Developer wanting to contribute to MCP ecosystem

Your contribution can help thousands of Bear users get even more from their AI assistants!

Current Priorities

  1. πŸš€ Add new features - More ways to analyze and work with notes
  2. πŸ“– Improve documentation - Help others understand and contribute
  3. πŸ§ͺ Expand test coverage - Ensure reliability across Bear versions
  4. ⚑ Performance optimization - Make operations even faster

Quick Ways to Help

  • ⭐ Star the repo if you find it useful
  • πŸ› Report issues you encounter
  • πŸ’‘ Share ideas for new features or solutions
  • πŸ”— Spread the word to developers who might help
  • πŸ“ Contribute documentation improvements

Together, we can build the most powerful Bear integration for AI assistants!

πŸ” All Available Tools

<details> <summary><strong>πŸ“– Read Operations (26 tools) - βœ… ACTIVE</strong></summary>

Basic Operations (6 tools)

  • get_database_stats - Overview of your Bear database
  • get_notes - List notes with filtering options
  • get_note_by_id - Get specific note by ID
  • get_note_by_title - Find note by exact title
  • get_tags - List all tags with usage counts
  • get_notes_by_tag - Find notes with specific tag

Advanced Search (8 tools)

  • get_notes_advanced - Complex filtering and sorting
  • get_notes_with_criteria - Multi-criteria search
  • search_notes_fulltext - Full-text search with relevance scoring
  • get_search_suggestions - Auto-complete for searches
  • find_similar_notes - Content similarity matching
  • get_related_notes - Find related notes by tags and content
  • get_recent_notes - Recently created or modified notes
  • get_note_counts_by_status - Statistics by note status

Analytics & Insights (6 tools)

  • get_note_analytics - Comprehensive note statistics
  • analyze_note_metadata - Content pattern analysis
  • get_notes_with_metadata - Filter by content characteristics
  • get_file_attachments - File attachment management
  • get_tag_hierarchy - Tag relationship analysis
  • get_tag_analytics - Tag usage patterns

Content Analysis (6 tools)

  • analyze_tag_relationships - Tag optimization suggestions
  • get_tag_usage_trends - Tag usage over time
  • search_notes_regex - Pattern matching (when available)
  • Advanced content categorization
  • Link and reference analysis
  • Writing pattern insights
</details> <details> <summary><strong>✏️ Write Operations (6 tools) - βœ… ACTIVE (Sync-Safe)</strong></summary>

Note Management - SYNC-SAFE VIA BEAR API

  • create_note - βœ… Create new notes with tags and content
  • update_note - βœ… Update existing notes safely
  • duplicate_note - βœ… Create copies of existing notes
  • archive_note - βœ… Archive/unarchive notes
  • trigger_hashtag_parsing - βœ… Force hashtag reprocessing
  • batch_trigger_hashtag_parsing - βœ… Bulk hashtag processing

βœ… All operations are now sync-safe:

  • Uses Bear's x-callback-url API for all writes
  • No iCloud sync conflicts or data corruption
  • Respects Bear's internal sync coordination
  • Full write functionality restored

Perfect integration between database reads and API writes!

</details>

πŸ“ˆ Performance

  • Read operations: Instant (direct database access)
  • Write operations: 1-2 seconds (Bear API processing)
  • Large databases: Tested with 10,000+ notes
  • Memory usage: ~50MB typical, ~100MB for complex operations
  • Concurrent operations: Read operations can run simultaneously
  • API operations: Processed through Bear's URL scheme

πŸ“„ License

MIT License - see LICENSE file for details.


Made with ❀️ for the Bear community