obsidian-sync-mcp 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -38,7 +38,7 @@ Both modes expose the same MCP tools over HTTP, so any MCP-compatible agent can
38
38
 
39
39
  You already have LiveSync and CouchDB on an always-on server. You just need the MCP server deployed alongside it.
40
40
 
41
- **Using Fly.io setup script:**
41
+ **Using Fly.io setup script** (macOS/Linux, or WSL on Windows):
42
42
 
43
43
  ```bash
44
44
  git clone https://github.com/es617/obsidian-sync-mcp.git
@@ -55,11 +55,15 @@ docker run -p 8787:8787 \
55
55
  -e COUCHDB_URL=https://your-couchdb:5984 \
56
56
  -e COUCHDB_USER=admin -e COUCHDB_PASSWORD=yourpassword \
57
57
  -e COUCHDB_DATABASE=obsidian -e VAULT_NAME=MyVault \
58
+ -e COUCHDB_PASSPHRASE=your-encryption-passphrase \
58
59
  -e MCP_AUTH_TOKEN=yourpassword \
60
+ -e BASE_URL=https://your-server-url \
59
61
  ghcr.io/es617/obsidian-sync-mcp:latest
60
62
  ```
61
63
 
62
- Your MCP endpoint is `https://your-app.fly.dev/mcp` (Fly.io) or `http://your-server:8787/mcp` (Docker).
64
+ Set `COUCHDB_PASSPHRASE` if you use E2E encryption in LiveSync. Set `BASE_URL` to your public URL (required for OAuth callbacks when agents connect over HTTPS).
65
+
66
+ Your MCP endpoint is `https://your-app.fly.dev/mcp` (Fly.io) or `https://your-server:8787/mcp` (Docker behind HTTPS).
63
67
 
64
68
  See [Cost](#cost-flyio) for Fly.io pricing.
65
69
 
@@ -77,7 +81,7 @@ fly auth login
77
81
 
78
82
  Starting fresh — no LiveSync yet. Deploy CouchDB and MCP together, then set up LiveSync in Obsidian.
79
83
 
80
- **Using Fly.io setup script:**
84
+ **Using Fly.io setup script** (macOS/Linux, or WSL on Windows):
81
85
 
82
86
  ```bash
83
87
  git clone https://github.com/es617/obsidian-sync-mcp.git
@@ -158,10 +162,13 @@ COUCHDB_URL=http://localhost:5984 \
158
162
  COUCHDB_USER=admin \
159
163
  COUCHDB_PASSWORD=yourpassword \
160
164
  COUCHDB_DATABASE=obsidian \
165
+ COUCHDB_PASSPHRASE=your-encryption-passphrase \
161
166
  VAULT_NAME=MyVault \
162
167
  npx obsidian-sync-mcp
163
168
  ```
164
169
 
170
+ Omit `COUCHDB_PASSPHRASE` if you don't use E2E encryption in LiveSync.
171
+
165
172
  **Or with Docker:**
166
173
 
167
174
  ```bash
@@ -190,16 +197,19 @@ Set `BASE_URL` to the tunnel URL when using authentication.
190
197
  | Tool | Description |
191
198
  |---|---|
192
199
  | `read_note` | Read a note's markdown content by path |
193
- | `write_note` | Create or overwrite a note (preserves creation time on updates) |
194
- | `list_notes` | List all `.md` files, optionally filtered by folder |
195
- | `search_vault` | Sub-millisecond full-text search across all notes (capped at 50 results) |
200
+ | `write_note` | Create or overwrite a note (replaces entire content) |
201
+ | `edit_note` | Edit a note without rewriting it — append, prepend (after frontmatter), or replace exact text |
202
+ | `list_folders` | List all folders in the vault with note counts — use to discover folder names |
203
+ | `list_tags` | List all tags in the vault with counts — use to discover tags before filtering |
204
+ | `list_notes` | List notes with timestamps. Filter by folder, tag, or date. Sort by name or modified. |
205
+ | `search_vault` | Full-text search across all notes. Filter by tag or date, optionally include content snippets. |
196
206
  | `delete_note` | Delete a note |
197
207
  | `move_note` | Move or rename a note — works across folders, creates destination folders automatically |
198
- | `get_note_metadata` | Get frontmatter, tags, links, size, and timestamps without reading the full content |
208
+ | `get_note_metadata` | Get frontmatter, tags, outgoing links, backlinks, size, and timestamps — navigate the knowledge graph |
199
209
 
200
210
  Every tool response includes an [Obsidian deep link](https://help.obsidian.md/Extending+Obsidian/Obsidian+URI) (`obsidian://open?vault=...&file=...`) that works on Mac and iOS.
201
211
 
202
- > "List all my notes in the projects/ folder, then read the one about the MCP server."
212
+ > "Add a bullet point to my daily note." "Find my notes about the MCP server and fix the typo in the second one."
203
213
 
204
214
  ---
205
215
 
@@ -232,15 +242,16 @@ Without `MCP_AUTH_TOKEN`, the server runs without authentication — suitable fo
232
242
  | `VAULT_PATH` | Filesystem mode | — | Path to your Obsidian vault directory |
233
243
  | `COUCHDB_URL` | CouchDB mode | — | CouchDB server URL |
234
244
  | `COUCHDB_USER` | CouchDB mode | `admin` | CouchDB username |
235
- | `COUCHDB_PASSWORD` | CouchDB mode | `password` | CouchDB password |
245
+ | `COUCHDB_PASSWORD` | CouchDB mode | — | CouchDB password (required) |
236
246
  | `COUCHDB_DATABASE` | CouchDB mode | `obsidian` | CouchDB database name |
237
247
  | `COUCHDB_PASSPHRASE` | CouchDB mode | — | LiveSync E2E encryption passphrase (must match plugin setting) |
238
- | `VAULT_NAME` | Both | `MyVault` | Vault name for Obsidian deep links |
248
+ | `VAULT_NAME` | Both | `MyVault` | Vault name (used for deep links and index storage) |
239
249
  | `MCP_AUTH_TOKEN` | Optional | — | Password for authentication |
240
250
  | `BASE_URL` | Optional | `http://localhost:PORT` | Public URL (for OAuth callbacks when using a tunnel) |
241
251
  | `PORT` | Optional | `8787` | HTTP port |
242
252
  | `HOST` | Optional | `0.0.0.0` | Bind address (`127.0.0.1` to restrict to localhost) |
243
253
  | `DATA_DIR` | Optional | `~/.obsidian-mcp` | Directory for persisted data (search index, auth tokens) |
254
+ | `LOG_LEVEL` | Optional | — | Set to `debug` for verbose logging (library logs, change feed, index sync) |
244
255
  | `MCP_REFRESH_DAYS` | Optional | `14` | Days before auth session expires |
245
256
 
246
257
  Set `VAULT_PATH` for filesystem mode or `COUCHDB_URL` for CouchDB mode.
@@ -278,6 +289,7 @@ Set transport to **Streamable HTTP**, enter `http://localhost:8787/mcp`, and con
278
289
  - **Text only.** Binary attachments are not exposed through MCP tools.
279
290
  - **Deep links depend on the client.** Obsidian `obsidian://` deep links are included in every tool response. They work on Claude Mobile and in browsers, but some clients (Claude Desktop) may not render them as clickable links.
280
291
  - **Node 22+ required.**
292
+ - **Setup script requires bash.** The `deploy/setup.sh` script works on macOS and Linux. On Windows, use WSL or Git Bash.
281
293
 
282
294
  ---
283
295
 
@@ -66,7 +66,48 @@ function parseFrontmatterAndLinks(content) {
66
66
  return { frontmatter, tags: [...tags], links: [...new Set(links)] };
67
67
  }
68
68
  function extractSnippet(content, query, context = 80) {
69
- const idx = content.toLowerCase().indexOf(query.toLowerCase());
69
+ const lower = content.toLowerCase();
70
+ let idx = lower.indexOf(query.toLowerCase());
71
+ if (idx === -1) {
72
+ const words = query.split(/\s+/).filter((w) => w.length >= 3).map((w) => w.toLowerCase());
73
+ if (words.length > 1) {
74
+ let bestStart = -1;
75
+ let bestLen = Infinity;
76
+ const first = words[0];
77
+ let pos = 0;
78
+ while (pos < lower.length) {
79
+ const start2 = lower.indexOf(first, pos);
80
+ if (start2 === -1) break;
81
+ let spanEnd = start2 + first.length;
82
+ let allFound = true;
83
+ for (let i = 1; i < words.length; i++) {
84
+ const wi = lower.indexOf(words[i], Math.max(0, start2 - 200));
85
+ if (wi === -1) {
86
+ allFound = false;
87
+ break;
88
+ }
89
+ spanEnd = Math.max(spanEnd, wi + words[i].length);
90
+ }
91
+ if (allFound) {
92
+ const spanStart = Math.min(start2, ...words.map((w) => lower.indexOf(w, Math.max(0, start2 - 200))).filter((i) => i >= 0));
93
+ const len = spanEnd - spanStart;
94
+ if (len < bestLen) {
95
+ bestStart = spanStart;
96
+ bestLen = len;
97
+ }
98
+ }
99
+ pos = start2 + 1;
100
+ }
101
+ if (bestStart >= 0 && bestLen <= 500) idx = bestStart;
102
+ }
103
+ }
104
+ if (idx === -1) {
105
+ const words = query.split(/\s+/).filter((w) => w.length >= 3).sort((a, b) => b.length - a.length);
106
+ for (const word of words) {
107
+ idx = lower.indexOf(word.toLowerCase());
108
+ if (idx !== -1) break;
109
+ }
110
+ }
70
111
  if (idx === -1) {
71
112
  return content.slice(0, 160) + (content.length > 160 ? "..." : "");
72
113
  }
@@ -80,4 +121,4 @@ export {
80
121
  parseFrontmatterAndLinks,
81
122
  extractSnippet
82
123
  };
83
- //# sourceMappingURL=chunk-TFJDIQK4.js.map
124
+ //# sourceMappingURL=chunk-GK3PAZZJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/parse.ts"],"sourcesContent":["/**\n * Parse Obsidian markdown content for frontmatter, tags, and links.\n */\n\nexport interface NoteMetadata {\n frontmatter: Record<string, string>;\n tags: string[];\n links: string[];\n}\n\nexport function parseFrontmatterAndLinks(content: string): NoteMetadata {\n const frontmatter: Record<string, any> = {};\n const tags = new Set<string>();\n const links: string[] = [];\n\n // Parse YAML frontmatter\n if (content.startsWith(\"---\\n\")) {\n const end = content.indexOf(\"\\n---\", 4);\n if (end !== -1) {\n const yaml = content.slice(4, end);\n let inTagsList = false;\n for (const line of yaml.split(\"\\n\")) {\n // Multi-line tags list item: \" - tagname\"\n if (inTagsList) {\n const listItem = line.match(/^\\s+-\\s+(.+)/);\n if (listItem) {\n const trimmed = listItem[1].trim();\n if (trimmed) tags.add(trimmed);\n continue;\n }\n inTagsList = false;\n }\n\n const match = line.match(/^(\\w[\\w-]*)\\s*:\\s*(.+)/);\n if (match) {\n frontmatter[match[1]] = match[2].trim();\n }\n // Frontmatter tags (inline: [a, b] or start of multi-line list)\n if (/^tags\\s*:/.test(line)) {\n const value = line.replace(/^tags\\s*:\\s*/, \"\").trim();\n if (value) {\n // Inline: tags: [a, b] or tags: a, b\n const tagValues = value.replace(/[[\\]]/g, \"\");\n for (const t of tagValues.split(\",\")) {\n const trimmed = t.trim();\n if (trimmed) tags.add(trimmed);\n }\n } else {\n // Multi-line list follows\n inTagsList = true;\n }\n }\n }\n }\n }\n\n // Inline #tags\n for (const match of content.matchAll(/(^|\\s)#([\\w/-]+)/g)) {\n tags.add(match[2]);\n }\n\n // [[wikilinks]]\n for (const match of content.matchAll(/\\[\\[([^\\]|]+)(?:\\|[^\\]]+)?\\]\\]/g)) {\n links.push(match[1]);\n }\n\n // [markdown links](path.md)\n for (const match of content.matchAll(/\\[([^\\]]+)\\]\\(([^)]+\\.md)\\)/g)) {\n links.push(match[2]);\n }\n\n return { frontmatter, tags: [...tags], links: [...new Set(links)] };\n}\n\nexport function extractSnippet(content: string, query: string, context = 80): string {\n const lower = content.toLowerCase();\n\n // Try exact phrase first\n let idx = lower.indexOf(query.toLowerCase());\n\n // Try to find the smallest span containing all query words\n if (idx === -1) {\n const words = query.split(/\\s+/).filter((w) => w.length >= 3).map((w) => w.toLowerCase());\n if (words.length > 1) {\n let bestStart = -1;\n let bestLen = Infinity;\n // For each occurrence of the first word, find the nearest span containing all words\n const first = words[0];\n let pos = 0;\n while (pos < lower.length) {\n const start = lower.indexOf(first, pos);\n if (start === -1) break;\n // Find last position needed to include all words from this start\n let spanEnd = start + first.length;\n let allFound = true;\n for (let i = 1; i < words.length; i++) {\n const wi = lower.indexOf(words[i], Math.max(0, start - 200));\n if (wi === -1) { allFound = false; break; }\n spanEnd = Math.max(spanEnd, wi + words[i].length);\n }\n if (allFound) {\n const spanStart = Math.min(start, ...words.map((w) => lower.indexOf(w, Math.max(0, start - 200))).filter((i) => i >= 0));\n const len = spanEnd - spanStart;\n if (len < bestLen) { bestStart = spanStart; bestLen = len; }\n }\n pos = start + 1;\n }\n if (bestStart >= 0 && bestLen <= 500) idx = bestStart;\n }\n }\n\n // Fall back to longest matching word\n if (idx === -1) {\n const words = query.split(/\\s+/).filter((w) => w.length >= 3).sort((a, b) => b.length - a.length);\n for (const word of words) {\n idx = lower.indexOf(word.toLowerCase());\n if (idx !== -1) break;\n }\n }\n\n if (idx === -1) {\n return content.slice(0, 160) + (content.length > 160 ? \"...\" : \"\");\n }\n const start = Math.max(0, idx - context);\n const end = Math.min(content.length, idx + query.length + context);\n return (start > 0 ? \"...\" : \"\") + content.slice(start, end) + (end < content.length ? \"...\" : \"\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAUO,SAAS,yBAAyB,SAA+B;AACpE,QAAM,cAAmC,CAAC;AAC1C,QAAM,OAAO,oBAAI,IAAY;AAC7B,QAAM,QAAkB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