obsidian-sync-mcp 0.4.1 → 0.4.3
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
|
@@ -247,6 +247,7 @@ Without `MCP_AUTH_TOKEN`, the server runs without authentication — suitable fo
|
|
|
247
247
|
| `COUCHDB_PASSWORD` | CouchDB mode | — | CouchDB password (required) |
|
|
248
248
|
| `COUCHDB_DATABASE` | CouchDB mode | `obsidian` | CouchDB database name |
|
|
249
249
|
| `COUCHDB_PASSPHRASE` | CouchDB mode | — | LiveSync E2E encryption passphrase (must match plugin setting) |
|
|
250
|
+
| `COUCHDB_OBFUSCATE_PROPERTIES` | CouchDB mode | `false` | Set to `true` if "Obfuscate Properties" is enabled in LiveSync (obfuscates file paths, sizes, dates in the database) |
|
|
250
251
|
| `VAULT_NAME` | Both | `MyVault` | Vault name (used for deep links and index storage) |
|
|
251
252
|
| `MCP_AUTH_TOKEN` | Optional | — | Password for authentication |
|
|
252
253
|
| `BASE_URL` | Optional | `http://localhost:PORT` | Public URL (for OAuth callbacks when using a tunnel) |
|
package/dist/main.js
CHANGED
|
@@ -611,7 +611,20 @@ function makeDeepLink(vaultName, notePath) {
|
|
|
611
611
|
}
|
|
612
612
|
|
|
613
613
|
// src/tools.ts
|
|
614
|
+
var debugLogging = process.env.LOG_LEVEL === "debug";
|
|
614
615
|
function registerTools(server2, vault2, searchIndex2, vaultName) {
|
|
616
|
+
const _addTool = server2.addTool.bind(server2);
|
|
617
|
+
server2.addTool = (tool) => {
|
|
618
|
+
const original = tool.execute;
|
|
619
|
+
tool.execute = async (args, ctx) => {
|
|
620
|
+
if (debugLogging) console.log(`[tool] ${tool.name}(${JSON.stringify(args)})`);
|
|
621
|
+
const start2 = performance.now();
|
|
622
|
+
const result = await original(args, ctx);
|
|
623
|
+
if (debugLogging) console.log(`[tool] ${tool.name} \u2192 ${(performance.now() - start2).toFixed(0)}ms`);
|
|
624
|
+
return result;
|
|
625
|
+
};
|
|
626
|
+
return _addTool(tool);
|
|
627
|
+
};
|
|
615
628
|
server2.addTool({
|
|
616
629
|
name: "read_note",
|
|
617
630
|
description: "Read the content of a note from the Obsidian vault. Returns the markdown content and a deep link to open it in Obsidian.",
|
|
@@ -657,7 +670,7 @@ ${content}`;
|
|
|
657
670
|
tag: z.string().optional().describe("Filter by tag, e.g. 'project' or 'daily'. Use list_tags to discover available tags."),
|
|
658
671
|
sort_by: z.enum(["name", "modified"]).optional().describe("Sort order: 'name' (default) or 'modified' (most recent first)."),
|
|
659
672
|
modified_after: z.string().optional().describe("Only include notes modified after this ISO date, e.g. '2026-03-25' or '2026-03-25T10:00'."),
|
|
660
|
-
limit: z.number().optional().describe("Max number of notes to return. Default 100.")
|
|
673
|
+
limit: z.coerce.number().optional().describe("Max number of notes to return. Default 100.")
|
|
661
674
|
}),
|
|
662
675
|
execute: async ({ folder, tag, sort_by, modified_after, limit }) => {
|
|
663
676
|
let notes = searchIndex2.listWithMtime(folder);
|
|
@@ -743,7 +756,7 @@ ${content}`;
|
|
|
743
756
|
query: z.string().describe("Text to search for (case-insensitive)"),
|
|
744
757
|
tag: z.string().optional().describe("Filter results by tag, e.g. 'project'. Use list_tags to discover available tags."),
|
|
745
758
|
modified_after: z.string().optional().describe("Only include notes modified after this ISO date, e.g. '2026-03-25'."),
|
|
746
|
-
include_snippets: z.boolean().optional().describe("Fetch content snippets for each result. Default false (paths only).")
|
|
759
|
+
include_snippets: z.coerce.boolean().optional().describe("Fetch content snippets for each result. Default false (paths only).")
|
|
747
760
|
}),
|
|
748
761
|
execute: async ({ query, tag, modified_after, include_snippets }) => {
|
|
749
762
|
let paths = searchIndex2.search(query);
|
|
@@ -902,11 +915,12 @@ Backlinks: ${backlinks.join(", ")}`);
|
|
|
902
915
|
}
|
|
903
916
|
|
|
904
917
|
// src/main.ts
|
|
905
|
-
var
|
|
918
|
+
var debugLogging2 = process.env.LOG_LEVEL === "debug";
|
|
906
919
|
setGlobalLogFunction((message, level = LEVEL_INFO) => {
|
|
907
920
|
if (level < LEVEL_INFO) return;
|
|
908
|
-
if (!
|
|
909
|
-
if (/^(GET|PUT|DELETE|WATCH|FOLLOW|Sensible merge|Object merge
|
|
921
|
+
if (!debugLogging2 && typeof message === "string") {
|
|
922
|
+
if (/^(GET|PUT|DELETE|WATCH|FOLLOW|Sensible merge|Object merge):/.test(message)) return;
|
|
923
|
+
if (message.includes("replicator") || message.includes("Replicator") || message.includes("ReplicatorService")) return;
|
|
910
924
|
}
|
|
911
925
|
console.log(message);
|
|
912
926
|
});
|
|
@@ -916,6 +930,7 @@ var COUCHDB_USER = process.env.COUCHDB_USER ?? "admin";
|
|
|
916
930
|
var COUCHDB_PASSWORD = process.env.COUCHDB_PASSWORD;
|
|
917
931
|
var COUCHDB_DATABASE = process.env.COUCHDB_DATABASE ?? "obsidian";
|
|
918
932
|
var COUCHDB_PASSPHRASE = process.env.COUCHDB_PASSPHRASE || void 0;
|
|
933
|
+
var COUCHDB_OBFUSCATE_PROPERTIES = process.env.COUCHDB_OBFUSCATE_PROPERTIES === "true";
|
|
919
934
|
var VAULT_NAME = process.env.VAULT_NAME ?? "MyVault";
|
|
920
935
|
var PORT = parseInt(process.env.PORT ?? "8787");
|
|
921
936
|
var BASE_URL = process.env.BASE_URL ?? `http://localhost:${PORT}`;
|
|
@@ -930,13 +945,14 @@ if (VAULT_PATH) {
|
|
|
930
945
|
console.error("COUCHDB_PASSWORD is required in remote mode.");
|
|
931
946
|
process.exit(1);
|
|
932
947
|
}
|
|
933
|
-
const { Vault } = await import("./vault-
|
|
948
|
+
const { Vault } = await import("./vault-M7UWXU7J.js");
|
|
934
949
|
vault = new Vault({
|
|
935
950
|
couchdbUrl: COUCHDB_URL,
|
|
936
951
|
couchdbUser: COUCHDB_USER,
|
|
937
952
|
couchdbPassword: COUCHDB_PASSWORD,
|
|
938
953
|
database: COUCHDB_DATABASE,
|
|
939
|
-
passphrase: COUCHDB_PASSPHRASE
|
|
954
|
+
passphrase: COUCHDB_PASSPHRASE,
|
|
955
|
+
obfuscatePaths: COUCHDB_OBFUSCATE_PROPERTIES
|
|
940
956
|
});
|
|
941
957
|
console.log(`Remote mode: ${COUCHDB_URL}`);
|
|
942
958
|
} else {
|
|
@@ -951,7 +967,7 @@ var dataDir = join(baseDataDir, vaultId);
|
|
|
951
967
|
var indexPath = join(dataDir, "search-index.json");
|
|
952
968
|
var searchIndex = new SearchIndex(indexPath, COUCHDB_PASSPHRASE);
|
|
953
969
|
var hadPersistedIndex = await searchIndex.loadFromDisk();
|
|
954
|
-
if (
|
|
970
|
+
if (debugLogging2 && hadPersistedIndex) {
|
|
955
971
|
console.log(`[debug] Persisted index: ${searchIndex.size} notes, FlexSearch ready: ${!searchIndex.needsRebuild}, since: ${searchIndex.since || "(none)"}`);
|
|
956
972
|
}
|
|
957
973
|
var start = performance.now();
|
|
@@ -964,12 +980,12 @@ if (COUCHDB_URL && vault.catchUp) {
|
|
|
964
980
|
}
|
|
965
981
|
};
|
|
966
982
|
let since = searchIndex.since || "0";
|
|
967
|
-
if (
|
|
983
|
+
if (debugLogging2) console.log(`[debug] CouchDB catch-up from since: ${since}`);
|
|
968
984
|
let changes = 0;
|
|
969
985
|
try {
|
|
970
986
|
const countingCallback = (path, content, mtime) => {
|
|
971
987
|
changes++;
|
|
972
|
-
if (
|
|
988
|
+
if (debugLogging2) console.log(`[debug] Change: ${path} ${content ? "(update)" : "(delete)"}`);
|
|
973
989
|
changeCallback(path, content, mtime);
|
|
974
990
|
};
|
|
975
991
|
const newSince = await vault.catchUp(since, countingCallback);
|
|
@@ -991,18 +1007,18 @@ if (COUCHDB_URL && vault.catchUp) {
|
|
|
991
1007
|
}
|
|
992
1008
|
} else if (VAULT_PATH) {
|
|
993
1009
|
const notesWithMtime = await vault.listNotesWithMtime();
|
|
994
|
-
if (
|
|
1010
|
+
if (debugLogging2) console.log(`[debug] Vault has ${notesWithMtime.length} notes`);
|
|
995
1011
|
if (hadPersistedIndex && !searchIndex.needsRebuild && notesWithMtime.length > 0) {
|
|
996
1012
|
const vaultPaths = new Set(notesWithMtime.map((n) => n.path));
|
|
997
1013
|
const stale = searchIndex.listPaths().filter((p) => !vaultPaths.has(p));
|
|
998
1014
|
for (const p of stale) {
|
|
999
|
-
if (
|
|
1015
|
+
if (debugLogging2) console.log(`[debug] Removing stale: ${p}`);
|
|
1000
1016
|
searchIndex.remove(p);
|
|
1001
1017
|
}
|
|
1002
1018
|
const toRead = notesWithMtime.filter((n) => n.mtime > searchIndex.getMtime(n.path));
|
|
1003
1019
|
if (toRead.length > 0 || stale.length > 0) {
|
|
1004
1020
|
for (const { path, mtime } of toRead) {
|
|
1005
|
-
if (
|
|
1021
|
+
if (debugLogging2) console.log(`[debug] Reading changed: ${path}`);
|
|
1006
1022
|
const content = await vault.readNote(path);
|
|
1007
1023
|
if (content) searchIndex.update(path, content, mtime);
|
|
1008
1024
|
}
|
|
@@ -1011,7 +1027,7 @@ if (COUCHDB_URL && vault.catchUp) {
|
|
|
1011
1027
|
console.log(`Search index up to date (${searchIndex.size} notes).`);
|
|
1012
1028
|
}
|
|
1013
1029
|
} else if (notesWithMtime.length > 0) {
|
|
1014
|
-
if (
|
|
1030
|
+
if (debugLogging2) console.log(`[debug] Full rebuild (persisted: ${hadPersistedIndex}, flexsearch ready: ${!searchIndex.needsRebuild})`);
|
|
1015
1031
|
console.log(`Building search index (${notesWithMtime.length} notes)...`);
|
|
1016
1032
|
for (let i = 0; i < notesWithMtime.length; i++) {
|
|
1017
1033
|
const { path, mtime } = notesWithMtime[i];
|
|
@@ -1052,10 +1068,10 @@ if (VAULT_PATH) {
|
|
|
1052
1068
|
} else if (COUCHDB_URL && vault.watchChanges) {
|
|
1053
1069
|
vault.watchChanges((path, content, mtime, seq) => {
|
|
1054
1070
|
if (content) {
|
|
1055
|
-
if (
|
|
1071
|
+
if (debugLogging2) console.log(`[debug] CouchDB change: ${path} (mtime: ${mtime})`);
|
|
1056
1072
|
searchIndex.update(path, content, mtime);
|
|
1057
1073
|
} else {
|
|
1058
|
-
if (
|
|
1074
|
+
if (debugLogging2) console.log(`[debug] CouchDB delete: ${path}`);
|
|
1059
1075
|
searchIndex.remove(path);
|
|
1060
1076
|
}
|
|
1061
1077
|
if (seq) searchIndex.since = String(seq);
|
|
@@ -1064,7 +1080,7 @@ if (VAULT_PATH) {
|
|
|
1064
1080
|
}
|
|
1065
1081
|
var serverOptions = {
|
|
1066
1082
|
name: "obsidian-sync-mcp",
|
|
1067
|
-
version: "0.4.
|
|
1083
|
+
version: "0.4.3",
|
|
1068
1084
|
instructions: "Access and manage an Obsidian vault. You can read, write, list, search, move, and delete markdown notes. Every tool response includes an Obsidian deep link. Always show this link to the user using the format [obsidian://open?vault=...&file=...](obsidian://open?vault=...&file=...) so it is both clickable and visible as a URL."
|
|
1069
1085
|
};
|
|
1070
1086
|
var auth = null;
|
|
@@ -1117,7 +1133,7 @@ server.start({
|
|
|
1117
1133
|
transportType: "httpStream",
|
|
1118
1134
|
httpStream: { port: PORT, endpoint: "/mcp", host: process.env.HOST ?? "0.0.0.0" }
|
|
1119
1135
|
});
|
|
1120
|
-
console.log(`obsidian-sync-mcp v${"0.4.
|
|
1136
|
+
console.log(`obsidian-sync-mcp v${"0.4.3"} listening on port ${PORT}`);
|
|
1121
1137
|
process.on("unhandledRejection", (err) => {
|
|
1122
1138
|
console.error("Unhandled rejection:", err);
|
|
1123
1139
|
});
|