obsidian-sync-mcp 0.5.7 → 0.5.8

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
@@ -63,7 +63,7 @@ docker run -p 8787:8787 \
63
63
  ghcr.io/es617/obsidian-sync-mcp:latest
64
64
  ```
65
65
 
66
- Set `COUCHDB_PASSPHRASE` if you use E2E encryption in LiveSync. Set `COUCHDB_OBFUSCATE_PROPERTIES=true` **only if** "Obfuscate Properties" is also enabled in your LiveSync settings — must match, or writes will silently fail to sync. Set `BASE_URL` to your public URL (required for OAuth callbacks when agents connect over HTTPS).
66
+ Set `COUCHDB_PASSPHRASE` if you use E2E encryption in LiveSync. Set `COUCHDB_OBFUSCATE_PROPERTIES=true` if "Obfuscate Properties" is also enabled in your LiveSync settings. For an existing vault the server detects the actual setting from the database at startup and corrects a mismatch with a warning; only for a brand-new empty database does the value need to match your LiveSync settings. Set `BASE_URL` to your public URL (required for OAuth callbacks when agents connect over HTTPS).
67
67
 
68
68
  Your MCP endpoint is `https://your-app.fly.dev/mcp` (Fly.io) or `https://your-server:8787/mcp` (Docker behind HTTPS).
69
69
 
@@ -170,7 +170,7 @@ VAULT_NAME=MyVault \
170
170
  npx obsidian-sync-mcp
171
171
  ```
172
172
 
173
- Omit `COUCHDB_PASSPHRASE` if you don't use E2E encryption in LiveSync. Set `COUCHDB_OBFUSCATE_PROPERTIES=true` **only if** "Obfuscate Properties" is also enabled in your LiveSync settings — must match, or writes will silently fail to sync.
173
+ Omit `COUCHDB_PASSPHRASE` if you don't use E2E encryption in LiveSync. Set `COUCHDB_OBFUSCATE_PROPERTIES=true` if "Obfuscate Properties" is also enabled in your LiveSync settings. For an existing vault the server detects the actual setting from the database at startup and corrects a mismatch with a warning; only for a brand-new empty database does the value need to match your LiveSync settings.
174
174
 
175
175
  **Or with Docker:**
176
176
 
@@ -248,7 +248,7 @@ Without `MCP_AUTH_TOKEN`, the server runs without authentication — suitable fo
248
248
  | `COUCHDB_PASSWORD` | CouchDB mode | — | CouchDB password (required) |
249
249
  | `COUCHDB_DATABASE` | CouchDB mode | `obsidian` | CouchDB database name |
250
250
  | `COUCHDB_PASSPHRASE` | CouchDB mode | — | LiveSync E2E encryption passphrase (must match plugin setting) |
251
- | `COUCHDB_OBFUSCATE_PROPERTIES` | CouchDB mode | `false` | Set to `true` if "Obfuscate Properties" is enabled in LiveSync (obfuscates file paths, sizes, dates in the database) |
251
+ | `COUCHDB_OBFUSCATE_PROPERTIES` | CouchDB mode | `false` | Set to `true` if "Obfuscate Properties" is enabled in LiveSync (obfuscates file paths, sizes, dates in the database). For existing vaults the actual setting is auto-detected at startup; this value only decides the format for a brand-new empty database |
252
252
  | `VAULT_NAME` | Both | `MyVault` | Vault name (used for deep links and index storage) |
253
253
  | `MCP_AUTH_TOKEN` | Optional | — | Password for authentication |
254
254
  | `BASE_URL` | Optional | `http://localhost:PORT` | Public URL (for OAuth callbacks when using a tunnel) |
package/dist/main.js CHANGED
@@ -932,7 +932,7 @@ if (VAULT_PATH) {
932
932
  console.error("COUCHDB_PASSWORD is required in remote mode.");
933
933
  process.exit(1);
934
934
  }
935
- const { Vault } = await import("./vault-BL4NJC75.js");
935
+ const { Vault } = await import("./vault-JCVXDVR6.js");
936
936
  vault = new Vault({
937
937
  couchdbUrl: COUCHDB_URL,
938
938
  couchdbUser: COUCHDB_USER,
@@ -1053,7 +1053,7 @@ if (VAULT_PATH) {
1053
1053
  var BASE_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.";
1054
1054
  var serverOptions = {
1055
1055
  name: "obsidian-sync-mcp",
1056
- version: "0.5.7",
1056
+ version: "0.5.8",
1057
1057
  instructions: MCP_EXTRA_INSTRUCTIONS ? `${BASE_INSTRUCTIONS}
1058
1058
 
1059
1059
  ${MCP_EXTRA_INSTRUCTIONS}` : BASE_INSTRUCTIONS
@@ -1117,7 +1117,7 @@ server.start({
1117
1117
  transportType: "httpStream",
1118
1118
  httpStream: { port: PORT, endpoint: "/mcp", host: process.env.HOST ?? "0.0.0.0" }
1119
1119
  });
1120
- console.log(`obsidian-sync-mcp v${"0.5.7"} listening on port ${PORT}`);
1120
+ console.log(`obsidian-sync-mcp v${"0.5.8"} listening on port ${PORT}`);
1121
1121
  process.on("unhandledRejection", (err) => {
1122
1122
  console.error("Unhandled rejection:", err);
1123
1123
  });
@@ -10995,27 +10995,102 @@ var DirectFileManipulator = class {
10995
10995
 
10996
10996
  // src/vault.ts
10997
10997
  import { isPathProbablyObfuscated as isPathProbablyObfuscated2, decrypt as decrypt4 } from "octagonal-wheels/encryption/encryption";
10998
+
10999
+ // src/id-format.ts
11000
+ function classifyIds(ids) {
11001
+ let obfuscated = 0;
11002
+ let plain = 0;
11003
+ for (const id of ids) {
11004
+ if (id.startsWith("f:")) obfuscated++;
11005
+ else plain++;
11006
+ }
11007
+ if (obfuscated === 0 && plain === 0) return "empty";
11008
+ if (obfuscated > 0 && plain > 0) return "mixed";
11009
+ return obfuscated > 0 ? "obfuscated" : "plain";
11010
+ }
11011
+
11012
+ // src/vault.ts
10998
11013
  var Vault = class _Vault {
10999
11014
  manipulator;
11000
11015
  passphrase;
11016
+ config;
11001
11017
  constructor(config) {
11018
+ this.config = config;
11002
11019
  this.passphrase = config.passphrase;
11003
- const opts = {
11020
+ this.manipulator = new DirectFileManipulator(_Vault.buildOptions(config, !!config.obfuscatePaths));
11021
+ }
11022
+ static buildOptions(config, obfuscatePaths) {
11023
+ return {
11004
11024
  url: config.couchdbUrl,
11005
11025
  username: config.couchdbUser,
11006
11026
  password: config.couchdbPassword,
11007
11027
  database: config.database,
11008
11028
  passphrase: config.passphrase,
11009
- obfuscatePassphrase: config.obfuscatePaths ? config.passphrase : void 0,
11029
+ obfuscatePassphrase: obfuscatePaths ? config.passphrase : void 0,
11010
11030
  useEden: false,
11011
11031
  enableCompression: false,
11012
11032
  handleFilenameCaseSensitive: false,
11013
11033
  doNotUseFixedRevisionForChunks: false
11014
11034
  };
11015
- this.manipulator = new DirectFileManipulator(opts);
11016
11035
  }
11017
11036
  async init() {
11018
11037
  await this.manipulator.ready.promise;
11038
+ await this.reconcileObfuscation();
11039
+ }
11040
+ /**
11041
+ * Detect whether the vault's document IDs are obfuscated and, if the
11042
+ * configured COUCHDB_OBFUSCATE_PROPERTIES doesn't match, correct it.
11043
+ * A mismatched setting can never work: path→id resolution misses every
11044
+ * existing note on read, and writes produce docs LiveSync clients ignore
11045
+ * (issues #4, #10). The database is the ground truth.
11046
+ */
11047
+ async reconcileObfuscation() {
11048
+ const configured = !!this.config.obfuscatePaths;
11049
+ const format = await this.detectIdFormat();
11050
+ if (format === "empty") return;
11051
+ if (format === "mixed") {
11052
+ console.warn(
11053
+ `Warning: vault contains both obfuscated and plaintext document IDs. Keeping COUCHDB_OBFUSCATE_PROPERTIES=${configured}. This usually means "Obfuscate properties" was toggled without rebuilding the database \u2014 consider rebuilding it from LiveSync.`
11054
+ );
11055
+ return;
11056
+ }
11057
+ const actual = format === "obfuscated";
11058
+ if (actual === configured) return;
11059
+ if (actual && !this.passphrase) {
11060
+ throw new Error(
11061
+ 'Vault uses obfuscated document IDs (LiveSync "Obfuscate properties"), which requires the E2E passphrase. Set COUCHDB_PASSPHRASE and COUCHDB_OBFUSCATE_PROPERTIES=true.'
11062
+ );
11063
+ }
11064
+ console.warn(
11065
+ actual ? "Warning: vault uses obfuscated document IDs but COUCHDB_OBFUSCATE_PROPERTIES is not set to true. Enabling path obfuscation automatically \u2014 set COUCHDB_OBFUSCATE_PROPERTIES=true to silence this warning." : "Warning: COUCHDB_OBFUSCATE_PROPERTIES=true but vault uses plaintext document IDs. Disabling path obfuscation automatically \u2014 set COUCHDB_OBFUSCATE_PROPERTIES=false to silence this warning."
11066
+ );
11067
+ await this.manipulator.close();
11068
+ this.manipulator = new DirectFileManipulator(_Vault.buildOptions(this.config, actual));
11069
+ await this.manipulator.ready.promise;
11070
+ }
11071
+ /** Sample file-entry docs from the changes feed and classify their IDs. */
11072
+ async detectIdFormat() {
11073
+ const SAMPLE_TARGET = 20;
11074
+ const BATCH_SIZE2 = 100;
11075
+ const db = this.manipulator.liveSyncLocalDB.localDatabase;
11076
+ const ids = [];
11077
+ let since = 0;
11078
+ while (ids.length < SAMPLE_TARGET) {
11079
+ const result = await db.changes({
11080
+ since,
11081
+ limit: BATCH_SIZE2,
11082
+ // Only real file entries — excludes chunks, versioninfo, milestones, sync params.
11083
+ selector: { type: { $in: ["plain", "newnote"] } },
11084
+ live: false
11085
+ });
11086
+ for (const change of result.results) {
11087
+ if (ids.length >= SAMPLE_TARGET) break;
11088
+ ids.push(change.id);
11089
+ }
11090
+ if (result.results.length < BATCH_SIZE2) break;
11091
+ since = result.last_seq;
11092
+ }
11093
+ return classifyIds(ids);
11019
11094
  }
11020
11095
  async close() {
11021
11096
  this.manipulator.endWatch();
@@ -11154,4 +11229,4 @@ var Vault = class _Vault {
11154
11229
  export {
11155
11230
  Vault
11156
11231
  };
11157
- //# sourceMappingURL=vault-BL4NJC75.js.map
11232
+ //# sourceMappingURL=vault-JCVXDVR6.js.map