obsidian-sync-mcp 0.5.8 → 0.6.1
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 +1 -0
- package/dist/main.js +32 -9
- package/dist/main.js.map +1 -1
- package/dist/vault-W6NTMJCS.js +10223 -0
- package/dist/vault-W6NTMJCS.js.map +1 -0
- package/package.json +2 -2
- package/dist/vault-JCVXDVR6.js +0 -11232
- package/dist/vault-JCVXDVR6.js.map +0 -1
package/README.md
CHANGED
|
@@ -259,6 +259,7 @@ Without `MCP_AUTH_TOKEN`, the server runs without authentication — suitable fo
|
|
|
259
259
|
| `LOG_LEVEL` | Optional | — | Set to `debug` for verbose logging (library logs, change feed, index sync) |
|
|
260
260
|
| `MCP_REFRESH_DAYS` | Optional | `14` | Days before auth session expires |
|
|
261
261
|
| `READ_ONLY` | Optional | `false` | Set to `true` to disable all write tools (`write_note`, `edit_note`, `delete_note`, `move_note`). Only read tools are exposed via MCP. Useful when sharing the server with multiple AI clients and write access should be opt-in. |
|
|
262
|
+
| `WRITE_FOLDERS` | Optional | — | Comma-separated list of vault-relative folders where writes are allowed (e.g. `MCP,Inbox`). When set, the whole vault stays readable but `write_note`, `edit_note`, `delete_note`, and `move_note` refuse paths outside these folders (`move_note` requires both source and destination to be writable). Enforced server-side, unlike `MCP_INSTRUCTIONS`. Matching is case-sensitive and folder-boundary-aware (`MCP` matches `MCP/note.md` but not `MCP-private/note.md`). Ignored when `READ_ONLY=true`; unset means the whole vault is writable. |
|
|
262
263
|
| `MCP_INSTRUCTIONS` | Optional | — | Extra text appended to the server's MCP `instructions` (the string clients inject into the system prompt). Use this to bake vault-specific conventions into the server — e.g. folder structure, naming rules, folders to avoid — so they apply across every MCP client without per-client config. Best-effort: not all clients respect `instructions`. |
|
|
263
264
|
| `MCP_INSTRUCTIONS_FILE` | Optional | — | Path to a file (e.g. markdown) whose contents are appended to the MCP `instructions`. Easier than `MCP_INSTRUCTIONS` for multi-line conventions. If both are set, the file wins and `MCP_INSTRUCTIONS` is ignored (with a startup warning). Missing/unreadable file or files larger than 32 KB are fatal startup errors. **Store this file somewhere only the service user can write (e.g. `chmod 600`)** — its contents land in every MCP session's system prompt, so write access to it = prompt-injection access to every client. |
|
|
264
265
|
|
package/dist/main.js
CHANGED
|
@@ -605,13 +605,30 @@ function makeDeepLink(vaultName, notePath) {
|
|
|
605
605
|
return `obsidian://open?vault=${encodedVault}&file=${encodedPath}`;
|
|
606
606
|
}
|
|
607
607
|
|
|
608
|
+
// src/write-scope.ts
|
|
609
|
+
function parseWriteFolders(raw) {
|
|
610
|
+
if (raw === void 0) return null;
|
|
611
|
+
const folders = raw.split(",").map((f) => f.trim().replace(/^\/+|\/+$/g, "")).filter(Boolean);
|
|
612
|
+
return folders.length > 0 ? folders : null;
|
|
613
|
+
}
|
|
614
|
+
function isPathWritable(path, writeFolders) {
|
|
615
|
+
if (writeFolders === null) return true;
|
|
616
|
+
const normalized = path.replace(/^\/+/, "");
|
|
617
|
+
if (normalized.split(/[/\\]/).includes("..")) return false;
|
|
618
|
+
return writeFolders.some((folder) => normalized.startsWith(folder + "/"));
|
|
619
|
+
}
|
|
620
|
+
|
|
608
621
|
// src/tools.ts
|
|
609
622
|
var debugLogging = process.env.LOG_LEVEL === "debug";
|
|
610
623
|
var WRITE_TOOLS = ["write_note", "edit_note", "delete_note", "move_note"];
|
|
611
|
-
function registerTools(server2, vault2, searchIndex2, vaultName, readOnly = false) {
|
|
624
|
+
function registerTools(server2, vault2, searchIndex2, vaultName, readOnly = false, writeFolders = null) {
|
|
612
625
|
if (readOnly) {
|
|
613
626
|
console.log(`READ_ONLY mode: write tools disabled (${WRITE_TOOLS.join(", ")}).`);
|
|
627
|
+
} else if (writeFolders) {
|
|
628
|
+
console.log(`WRITE_FOLDERS: writes restricted to ${writeFolders.map((f) => f + "/").join(", ")}.`);
|
|
614
629
|
}
|
|
630
|
+
const writeScopeNote = writeFolders ? ` Writes are only allowed inside: ${writeFolders.map((f) => f + "/").join(", ")}.` : "";
|
|
631
|
+
const denyWrite = (path) => `Write access denied: '${path}' is outside the writable folders (${writeFolders.map((f) => f + "/").join(", ")}).`;
|
|
615
632
|
const _addTool = server2.addTool.bind(server2);
|
|
616
633
|
server2.addTool = (tool) => {
|
|
617
634
|
const original = tool.execute;
|
|
@@ -645,12 +662,13 @@ ${content}`;
|
|
|
645
662
|
});
|
|
646
663
|
if (!readOnly) server2.addTool({
|
|
647
664
|
name: "write_note",
|
|
648
|
-
description: "Write or update a note in the Obsidian vault. Creates the note if it doesn't exist. Replaces the entire content if it does \u2014 read first if you need to preserve existing content.",
|
|
665
|
+
description: "Write or update a note in the Obsidian vault. Creates the note if it doesn't exist. Replaces the entire content if it does \u2014 read first if you need to preserve existing content." + writeScopeNote,
|
|
649
666
|
parameters: z.object({
|
|
650
667
|
path: z.string().describe("Vault-relative path to the note, e.g. 'daily/2026-03-23.md'"),
|
|
651
668
|
content: z.string().describe("Full markdown content for the note")
|
|
652
669
|
}),
|
|
653
670
|
execute: async ({ path, content }) => {
|
|
671
|
+
if (!isPathWritable(path, writeFolders)) return denyWrite(path);
|
|
654
672
|
const ok = await vault2.writeNote(path, content);
|
|
655
673
|
if (!ok) {
|
|
656
674
|
return `Failed to write note: ${path}`;
|
|
@@ -755,7 +773,7 @@ ${content}`;
|
|
|
755
773
|
});
|
|
756
774
|
if (!readOnly) server2.addTool({
|
|
757
775
|
name: "edit_note",
|
|
758
|
-
description: "Edit a note without rewriting it. Use 'append' (default) to add content to the end, 'prepend' to add after frontmatter, or 'replace' to swap old_text with new content. For replace, the old_text must match exactly once.",
|
|
776
|
+
description: "Edit a note without rewriting it. Use 'append' (default) to add content to the end, 'prepend' to add after frontmatter, or 'replace' to swap old_text with new content. For replace, the old_text must match exactly once." + writeScopeNote,
|
|
759
777
|
parameters: z.object({
|
|
760
778
|
path: z.string().describe("Vault-relative path to the note, e.g. 'daily/2026-03-25.md'"),
|
|
761
779
|
content: z.string().describe("Text to append, prepend, or use as replacement for old_text"),
|
|
@@ -763,6 +781,7 @@ ${content}`;
|
|
|
763
781
|
old_text: z.string().optional().describe("Required for replace operation. Exact text to find and replace. Must match exactly once.")
|
|
764
782
|
}),
|
|
765
783
|
execute: async ({ path, content: newContent, operation, old_text }) => {
|
|
784
|
+
if (!isPathWritable(path, writeFolders)) return denyWrite(path);
|
|
766
785
|
const existing = await vault2.readNote(path);
|
|
767
786
|
if (existing === null) {
|
|
768
787
|
return `Note not found: ${path}`;
|
|
@@ -804,11 +823,12 @@ ${content}`;
|
|
|
804
823
|
});
|
|
805
824
|
if (!readOnly) server2.addTool({
|
|
806
825
|
name: "delete_note",
|
|
807
|
-
description: "Delete a note from the Obsidian vault.",
|
|
826
|
+
description: "Delete a note from the Obsidian vault." + writeScopeNote,
|
|
808
827
|
parameters: z.object({
|
|
809
828
|
path: z.string().describe("Vault-relative path to the note to delete")
|
|
810
829
|
}),
|
|
811
830
|
execute: async ({ path }) => {
|
|
831
|
+
if (!isPathWritable(path, writeFolders)) return denyWrite(path);
|
|
812
832
|
const ok = await vault2.deleteNote(path);
|
|
813
833
|
if (ok) searchIndex2.remove(path);
|
|
814
834
|
return ok ? `Deleted: ${path}` : `Failed to delete: ${path}`;
|
|
@@ -816,12 +836,14 @@ ${content}`;
|
|
|
816
836
|
});
|
|
817
837
|
if (!readOnly) server2.addTool({
|
|
818
838
|
name: "move_note",
|
|
819
|
-
description: "Move or rename a note. Use this to rename a note within the same folder, move it to a different folder, or both at once. Creates destination folders automatically.",
|
|
839
|
+
description: "Move or rename a note. Use this to rename a note within the same folder, move it to a different folder, or both at once. Creates destination folders automatically." + writeScopeNote,
|
|
820
840
|
parameters: z.object({
|
|
821
841
|
from: z.string().describe("Current path, e.g. 'daily/old-name.md'"),
|
|
822
842
|
to: z.string().describe("New path, e.g. 'projects/new-name.md'")
|
|
823
843
|
}),
|
|
824
844
|
execute: async ({ from, to }) => {
|
|
845
|
+
if (!isPathWritable(from, writeFolders)) return denyWrite(from);
|
|
846
|
+
if (!isPathWritable(to, writeFolders)) return denyWrite(to);
|
|
825
847
|
const content = await vault2.readNote(from);
|
|
826
848
|
const ok = await vault2.moveNote(from, to);
|
|
827
849
|
if (!ok) {
|
|
@@ -901,6 +923,7 @@ var PORT = parseInt(process.env.PORT ?? "8787");
|
|
|
901
923
|
var BASE_URL = process.env.BASE_URL ?? `http://localhost:${PORT}`;
|
|
902
924
|
var AUTH_TOKEN = process.env.MCP_AUTH_TOKEN;
|
|
903
925
|
var READ_ONLY = process.env.READ_ONLY === "true";
|
|
926
|
+
var WRITE_FOLDERS = parseWriteFolders(process.env.WRITE_FOLDERS);
|
|
904
927
|
var MCP_INSTRUCTIONS_FILE = process.env.MCP_INSTRUCTIONS_FILE?.trim() || void 0;
|
|
905
928
|
var MCP_INSTRUCTIONS_ENV = process.env.MCP_INSTRUCTIONS?.trim() || void 0;
|
|
906
929
|
var MCP_EXTRA_INSTRUCTIONS;
|
|
@@ -932,7 +955,7 @@ if (VAULT_PATH) {
|
|
|
932
955
|
console.error("COUCHDB_PASSWORD is required in remote mode.");
|
|
933
956
|
process.exit(1);
|
|
934
957
|
}
|
|
935
|
-
const { Vault } = await import("./vault-
|
|
958
|
+
const { Vault } = await import("./vault-W6NTMJCS.js");
|
|
936
959
|
vault = new Vault({
|
|
937
960
|
couchdbUrl: COUCHDB_URL,
|
|
938
961
|
couchdbUser: COUCHDB_USER,
|
|
@@ -1053,7 +1076,7 @@ if (VAULT_PATH) {
|
|
|
1053
1076
|
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
1077
|
var serverOptions = {
|
|
1055
1078
|
name: "obsidian-sync-mcp",
|
|
1056
|
-
version: "0.
|
|
1079
|
+
version: "0.6.1",
|
|
1057
1080
|
instructions: MCP_EXTRA_INSTRUCTIONS ? `${BASE_INSTRUCTIONS}
|
|
1058
1081
|
|
|
1059
1082
|
${MCP_EXTRA_INSTRUCTIONS}` : BASE_INSTRUCTIONS
|
|
@@ -1095,7 +1118,7 @@ if (AUTH_TOKEN) {
|
|
|
1095
1118
|
auth = mountPasswordAuth(server.getApp(), BASE_URL, AUTH_TOKEN, tokenPath);
|
|
1096
1119
|
await auth.loadTokens();
|
|
1097
1120
|
}
|
|
1098
|
-
registerTools(server, vault, searchIndex, VAULT_NAME, READ_ONLY);
|
|
1121
|
+
registerTools(server, vault, searchIndex, VAULT_NAME, READ_ONLY, WRITE_FOLDERS);
|
|
1099
1122
|
async function shutdown() {
|
|
1100
1123
|
console.log("Shutting down...");
|
|
1101
1124
|
if (fsWatcher) fsWatcher.close();
|
|
@@ -1117,7 +1140,7 @@ server.start({
|
|
|
1117
1140
|
transportType: "httpStream",
|
|
1118
1141
|
httpStream: { port: PORT, endpoint: "/mcp", host: process.env.HOST ?? "0.0.0.0" }
|
|
1119
1142
|
});
|
|
1120
|
-
console.log(`obsidian-sync-mcp v${"0.
|
|
1143
|
+
console.log(`obsidian-sync-mcp v${"0.6.1"} listening on port ${PORT}`);
|
|
1121
1144
|
process.on("unhandledRejection", (err) => {
|
|
1122
1145
|
console.error("Unhandled rejection:", err);
|
|
1123
1146
|
});
|