obsidian-sync-mcp 0.6.0 → 0.6.2
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/dist/main.js +43 -29
- 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 +1 -1
- package/dist/vault-JCVXDVR6.js +0 -11232
- package/dist/vault-JCVXDVR6.js.map +0 -1
package/dist/main.js
CHANGED
|
@@ -46,6 +46,24 @@ function mountPasswordAuth(app, baseUrl, password, persistPath) {
|
|
|
46
46
|
let failedAttempts = 0;
|
|
47
47
|
let lockoutCount = 0;
|
|
48
48
|
let lockedUntil = 0;
|
|
49
|
+
async function persist() {
|
|
50
|
+
if (!persistPath) return;
|
|
51
|
+
try {
|
|
52
|
+
await mkdir(dirname(persistPath), { recursive: true });
|
|
53
|
+
const now = Date.now();
|
|
54
|
+
const activeTokens = [...tokens.entries()].filter(([_, r]) => r.expiresAt > now);
|
|
55
|
+
const activeRefresh = [...refreshTokens.entries()].filter(([_, r]) => r.refreshExpiresAt > now);
|
|
56
|
+
const data = JSON.stringify({
|
|
57
|
+
tokens: Object.fromEntries(activeTokens),
|
|
58
|
+
refreshTokens: Object.fromEntries(activeRefresh),
|
|
59
|
+
clients: Object.fromEntries(clients)
|
|
60
|
+
});
|
|
61
|
+
await writeFile(persistPath, data, { encoding: "utf-8", mode: 384 });
|
|
62
|
+
await chmod(persistPath, 384);
|
|
63
|
+
} catch (err) {
|
|
64
|
+
console.error("Failed to save auth tokens:", err);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
49
67
|
if (!baseUrl.startsWith("https://") && !baseUrl.includes("localhost")) {
|
|
50
68
|
console.warn("WARNING: BASE_URL is not HTTPS. OAuth tokens will be sent in cleartext. Use a tunnel (cloudflared, tailscale, ngrok) to provide TLS.");
|
|
51
69
|
}
|
|
@@ -71,7 +89,18 @@ function mountPasswordAuth(app, baseUrl, password, persistPath) {
|
|
|
71
89
|
});
|
|
72
90
|
app.post("/oauth/register", async (c) => {
|
|
73
91
|
if (clients.size >= MAX_CLIENTS) {
|
|
74
|
-
|
|
92
|
+
const activeClientIds = /* @__PURE__ */ new Set();
|
|
93
|
+
for (const r of tokens.values()) activeClientIds.add(r.clientId);
|
|
94
|
+
for (const r of refreshTokens.values()) activeClientIds.add(r.clientId);
|
|
95
|
+
let oldest;
|
|
96
|
+
for (const client2 of clients.values()) {
|
|
97
|
+
if (activeClientIds.has(client2.clientId)) continue;
|
|
98
|
+
if (!oldest || (client2.createdAt ?? 0) < (oldest.createdAt ?? 0)) oldest = client2;
|
|
99
|
+
}
|
|
100
|
+
if (!oldest) {
|
|
101
|
+
return c.json({ error: "too_many_clients" }, 429);
|
|
102
|
+
}
|
|
103
|
+
clients.delete(oldest.clientId);
|
|
75
104
|
}
|
|
76
105
|
const body = await c.req.json();
|
|
77
106
|
const redirectUris = Array.isArray(body.redirect_uris) ? body.redirect_uris.slice(0, 5) : [];
|
|
@@ -93,9 +122,11 @@ function mountPasswordAuth(app, baseUrl, password, persistPath) {
|
|
|
93
122
|
clientId,
|
|
94
123
|
clientSecret,
|
|
95
124
|
redirectUris,
|
|
96
|
-
clientName
|
|
125
|
+
clientName,
|
|
126
|
+
createdAt: Date.now()
|
|
97
127
|
};
|
|
98
128
|
clients.set(clientId, client);
|
|
129
|
+
await persist();
|
|
99
130
|
return c.json({
|
|
100
131
|
client_id: clientId,
|
|
101
132
|
client_secret: clientSecret,
|
|
@@ -224,6 +255,7 @@ function mountPasswordAuth(app, baseUrl, password, persistPath) {
|
|
|
224
255
|
};
|
|
225
256
|
tokens.set(accessToken, record);
|
|
226
257
|
refreshTokens.set(refreshToken, record);
|
|
258
|
+
await persist();
|
|
227
259
|
return c.json({
|
|
228
260
|
access_token: accessToken,
|
|
229
261
|
token_type: "Bearer",
|
|
@@ -257,6 +289,7 @@ function mountPasswordAuth(app, baseUrl, password, persistPath) {
|
|
|
257
289
|
};
|
|
258
290
|
tokens.set(accessToken, record);
|
|
259
291
|
refreshTokens.set(newRefreshToken, record);
|
|
292
|
+
await persist();
|
|
260
293
|
return c.json({
|
|
261
294
|
access_token: accessToken,
|
|
262
295
|
token_type: "Bearer",
|
|
@@ -279,23 +312,7 @@ function mountPasswordAuth(app, baseUrl, password, persistPath) {
|
|
|
279
312
|
return true;
|
|
280
313
|
},
|
|
281
314
|
async saveTokens() {
|
|
282
|
-
|
|
283
|
-
try {
|
|
284
|
-
await mkdir(dirname(persistPath), { recursive: true });
|
|
285
|
-
const now = Date.now();
|
|
286
|
-
const activeTokens = [...tokens.entries()].filter(([_, r]) => r.expiresAt > now);
|
|
287
|
-
const activeRefresh = [...refreshTokens.entries()].filter(([_, r]) => r.refreshExpiresAt > now);
|
|
288
|
-
const data = JSON.stringify({
|
|
289
|
-
tokens: Object.fromEntries(activeTokens),
|
|
290
|
-
refreshTokens: Object.fromEntries(activeRefresh),
|
|
291
|
-
clients: Object.fromEntries(clients)
|
|
292
|
-
});
|
|
293
|
-
await writeFile(persistPath, data, { encoding: "utf-8", mode: 384 });
|
|
294
|
-
await chmod(persistPath, 384);
|
|
295
|
-
console.log(`Auth tokens saved to disk (${tokens.size} sessions).`);
|
|
296
|
-
} catch (err) {
|
|
297
|
-
console.error("Failed to save auth tokens:", err);
|
|
298
|
-
}
|
|
315
|
+
await persist();
|
|
299
316
|
},
|
|
300
317
|
cleanup() {
|
|
301
318
|
const now = Date.now();
|
|
@@ -305,12 +322,6 @@ function mountPasswordAuth(app, baseUrl, password, persistPath) {
|
|
|
305
322
|
for (const [k, r] of refreshTokens) {
|
|
306
323
|
if (r.refreshExpiresAt <= now) refreshTokens.delete(k);
|
|
307
324
|
}
|
|
308
|
-
const activeClientIds = /* @__PURE__ */ new Set();
|
|
309
|
-
for (const r of tokens.values()) activeClientIds.add(r.clientId);
|
|
310
|
-
for (const r of refreshTokens.values()) activeClientIds.add(r.clientId);
|
|
311
|
-
for (const [k, c] of clients) {
|
|
312
|
-
if (!activeClientIds.has(c.clientId)) clients.delete(k);
|
|
313
|
-
}
|
|
314
325
|
},
|
|
315
326
|
async loadTokens() {
|
|
316
327
|
if (!persistPath) return false;
|
|
@@ -955,7 +966,7 @@ if (VAULT_PATH) {
|
|
|
955
966
|
console.error("COUCHDB_PASSWORD is required in remote mode.");
|
|
956
967
|
process.exit(1);
|
|
957
968
|
}
|
|
958
|
-
const { Vault } = await import("./vault-
|
|
969
|
+
const { Vault } = await import("./vault-W6NTMJCS.js");
|
|
959
970
|
vault = new Vault({
|
|
960
971
|
couchdbUrl: COUCHDB_URL,
|
|
961
972
|
couchdbUser: COUCHDB_USER,
|
|
@@ -1076,7 +1087,7 @@ if (VAULT_PATH) {
|
|
|
1076
1087
|
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.";
|
|
1077
1088
|
var serverOptions = {
|
|
1078
1089
|
name: "obsidian-sync-mcp",
|
|
1079
|
-
version: "0.6.
|
|
1090
|
+
version: "0.6.2",
|
|
1080
1091
|
instructions: MCP_EXTRA_INSTRUCTIONS ? `${BASE_INSTRUCTIONS}
|
|
1081
1092
|
|
|
1082
1093
|
${MCP_EXTRA_INSTRUCTIONS}` : BASE_INSTRUCTIONS
|
|
@@ -1092,7 +1103,10 @@ if (AUTH_TOKEN) {
|
|
|
1092
1103
|
if (auth?.validateToken(header)) {
|
|
1093
1104
|
return { authenticated: true };
|
|
1094
1105
|
}
|
|
1095
|
-
throw new Response("Unauthorized", {
|
|
1106
|
+
throw new Response("Unauthorized", {
|
|
1107
|
+
status: 401,
|
|
1108
|
+
headers: { "WWW-Authenticate": `Bearer resource_metadata="${BASE_URL}/.well-known/oauth-protected-resource"` }
|
|
1109
|
+
});
|
|
1096
1110
|
};
|
|
1097
1111
|
console.log("Auth enabled (password-gated OAuth).");
|
|
1098
1112
|
} else {
|
|
@@ -1140,7 +1154,7 @@ server.start({
|
|
|
1140
1154
|
transportType: "httpStream",
|
|
1141
1155
|
httpStream: { port: PORT, endpoint: "/mcp", host: process.env.HOST ?? "0.0.0.0" }
|
|
1142
1156
|
});
|
|
1143
|
-
console.log(`obsidian-sync-mcp v${"0.6.
|
|
1157
|
+
console.log(`obsidian-sync-mcp v${"0.6.2"} listening on port ${PORT}`);
|
|
1144
1158
|
process.on("unhandledRejection", (err) => {
|
|
1145
1159
|
console.error("Unhandled rejection:", err);
|
|
1146
1160
|
});
|