|
| 1 | +# @cardmagic/notes |
| 2 | + |
| 3 | +CLI and MCP server to search and browse Apple Notes with fuzzy matching. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Fuzzy search** - Find notes even with typos using MiniSearch |
| 8 | +- **Full-text search** - Searches note titles, snippets, and body content |
| 9 | +- **PDF text extraction** - Automatically extracts and indexes text from PDF attachments |
| 10 | +- **Folder browsing** - List and filter notes by folder |
| 11 | +- **Fast indexing** - SQLite FTS5 + MiniSearch for quick searches across thousands of notes |
| 12 | +- **Dual mode** - Use as CLI tool or MCP server for Claude Code integration |
| 13 | + |
| 14 | +## Installation |
| 15 | + |
| 16 | +```bash |
| 17 | +# Install globally |
| 18 | +npm install -g @cardmagic/notes |
| 19 | + |
| 20 | +# Or with pnpm |
| 21 | +pnpm add -g @cardmagic/notes |
| 22 | +``` |
| 23 | + |
| 24 | +### Requirements |
| 25 | + |
| 26 | +- **macOS** - Reads from Apple Notes database |
| 27 | +- **Full Disk Access** - Terminal/IDE needs access to `~/Library/Group Containers/` |
| 28 | +- **pdftotext** (optional) - For PDF text extraction |
| 29 | + |
| 30 | +```bash |
| 31 | +# Install pdftotext for PDF support |
| 32 | +brew install poppler |
| 33 | +``` |
| 34 | + |
| 35 | +## CLI Usage |
| 36 | + |
| 37 | +### Search notes |
| 38 | + |
| 39 | +```bash |
| 40 | +# Fuzzy search |
| 41 | +notes search "recipe chocolate" |
| 42 | + |
| 43 | +# Filter by folder |
| 44 | +notes search "taxes" --folder "2024" |
| 45 | + |
| 46 | +# Limit results |
| 47 | +notes search "meeting" --limit 5 |
| 48 | + |
| 49 | +# Filter by date |
| 50 | +notes search "project" --after 2024-01-01 |
| 51 | +``` |
| 52 | + |
| 53 | +### Browse notes |
| 54 | + |
| 55 | +```bash |
| 56 | +# Recent notes |
| 57 | +notes recent |
| 58 | +notes recent --limit 10 |
| 59 | + |
| 60 | +# List all folders |
| 61 | +notes folders |
| 62 | + |
| 63 | +# Notes in a specific folder |
| 64 | +notes folder "Recipes" |
| 65 | +notes folder "Work" --limit 20 |
| 66 | +``` |
| 67 | + |
| 68 | +### Read a note |
| 69 | + |
| 70 | +```bash |
| 71 | +# Get note ID from search results, then read full content |
| 72 | +notes read 12345 |
| 73 | +``` |
| 74 | + |
| 75 | +### Manage index |
| 76 | + |
| 77 | +```bash |
| 78 | +# Show index statistics |
| 79 | +notes stats |
| 80 | + |
| 81 | +# Update index (incremental - only processes changed notes) |
| 82 | +notes index |
| 83 | + |
| 84 | +# Force full rebuild |
| 85 | +notes index --force |
| 86 | +``` |
| 87 | + |
| 88 | +The index uses **incremental updates** by default: |
| 89 | +- Tracks modification timestamps to detect changed notes |
| 90 | +- Only reprocesses notes modified since last index |
| 91 | +- Detects and removes deleted notes |
| 92 | +- Much faster than full rebuild for small changes |
| 93 | + |
| 94 | +## MCP Server |
| 95 | + |
| 96 | +Run as an MCP server for Claude Code integration: |
| 97 | + |
| 98 | +```bash |
| 99 | +notes --mcp |
| 100 | +``` |
| 101 | + |
| 102 | +### Available Tools |
| 103 | + |
| 104 | +| Tool | Description | |
| 105 | +|------|-------------| |
| 106 | +| `search_notes` | Fuzzy search through notes | |
| 107 | +| `recent_notes` | Get recently modified notes | |
| 108 | +| `read_note` | Read full note content by ID | |
| 109 | +| `list_folders` | List all folders with note counts | |
| 110 | +| `notes_in_folder` | List notes in a specific folder | |
| 111 | +| `get_note_stats` | Get index statistics | |
| 112 | + |
| 113 | +### Claude Code Configuration |
| 114 | + |
| 115 | +Add to your MCP settings: |
| 116 | + |
| 117 | +```json |
| 118 | +{ |
| 119 | + "mcpServers": { |
| 120 | + "notes": { |
| 121 | + "command": "notes", |
| 122 | + "args": ["--mcp"] |
| 123 | + } |
| 124 | + } |
| 125 | +} |
| 126 | +``` |
| 127 | + |
| 128 | +## PDF Text Extraction |
| 129 | + |
| 130 | +PDF attachments in Notes are automatically extracted and indexed when: |
| 131 | + |
| 132 | +1. **pdftotext is installed** - `brew install poppler` |
| 133 | +2. **PDF has been viewed** - Notes caches PDFs locally when opened |
| 134 | + |
| 135 | +The extracted text is appended to the note body, making PDF content fully searchable. |
| 136 | + |
| 137 | +### How it works |
| 138 | + |
| 139 | +- PDFs are cached at `~/Library/Group Containers/group.com.apple.notes/Library/Caches/Paper/` |
| 140 | +- Each PDF bundle contains the file in `Assets.bundle/` |
| 141 | +- Text is extracted using `pdftotext` and indexed with the parent note |
| 142 | + |
| 143 | +### Limitations |
| 144 | + |
| 145 | +- PDFs stored only in iCloud (never opened locally) won't be indexed |
| 146 | +- Password-protected PDFs cannot be extracted |
| 147 | +- Scanned PDFs without OCR won't have searchable text |
| 148 | + |
| 149 | +## Data Locations |
| 150 | + |
| 151 | +| Data | Path | |
| 152 | +|------|------| |
| 153 | +| Notes database | `~/Library/Group Containers/group.com.apple.notes/NoteStore.sqlite` | |
| 154 | +| PDF cache | `~/Library/Group Containers/group.com.apple.notes/Library/Caches/Paper/` | |
| 155 | +| Search index | `~/.notes/index.db` | |
| 156 | +| Fuzzy index | `~/.notes/fuzzy.json` | |
| 157 | +| Stats | `~/.notes/stats.json` | |
| 158 | + |
| 159 | +## Development |
| 160 | + |
| 161 | +```bash |
| 162 | +# Clone and install |
| 163 | +git clone https://github.com/cardmagic/notes |
| 164 | +cd notes |
| 165 | +pnpm install |
| 166 | + |
| 167 | +# Build |
| 168 | +pnpm build |
| 169 | + |
| 170 | +# Watch mode |
| 171 | +pnpm dev |
| 172 | + |
| 173 | +# Link globally for testing |
| 174 | +pnpm link --global |
| 175 | + |
| 176 | +# Type check |
| 177 | +pnpm typecheck |
| 178 | + |
| 179 | +# Lint |
| 180 | +pnpm lint |
| 181 | +``` |
| 182 | + |
| 183 | +### Project Structure |
| 184 | + |
| 185 | +``` |
| 186 | +src/ |
| 187 | +├── index.ts # Entry point - routes to CLI or MCP |
| 188 | +├── cli.ts # Commander-based CLI |
| 189 | +├── mcp.ts # MCP server implementation |
| 190 | +├── indexer.ts # Builds search indexes from Notes database |
| 191 | +├── searcher.ts # Query engine with fuzzy matching |
| 192 | +├── attachments.ts # PDF text extraction |
| 193 | +├── formatter.ts # Terminal output formatting |
| 194 | +└── types.ts # TypeScript types and utilities |
| 195 | +``` |
| 196 | + |
| 197 | +## Privacy |
| 198 | + |
| 199 | +This tool only reads your local Notes database. No data is sent externally. The search index is stored locally in `~/.notes/`. |
| 200 | + |
| 201 | +## License |
| 202 | + |
| 203 | +MIT |
| 204 | + |
| 205 | +## Author |
| 206 | + |
| 207 | +Lucas Carlson |
0 commit comments