@fromsko/obsidian-mcp-server 1.1.7 → 1.1.9
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/index.js +37 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ function parseArgs() {
|
|
|
18
18
|
}
|
|
19
19
|
if (!vaultPath) {
|
|
20
20
|
console.error("错误: 请使用 --vault 参数指定 Obsidian 笔记库路径");
|
|
21
|
-
console.error(
|
|
21
|
+
console.error('用法: node dist/index.js --vault "/path/to/your/vault"');
|
|
22
22
|
process.exit(1);
|
|
23
23
|
}
|
|
24
24
|
return { vaultPath };
|
|
@@ -103,13 +103,15 @@ async function listFolder(folderPath = "") {
|
|
|
103
103
|
// 获取笔记库结构
|
|
104
104
|
async function getNoteStructure() {
|
|
105
105
|
const rootContent = await listFolder("");
|
|
106
|
-
const structure = {
|
|
106
|
+
const structure = {
|
|
107
|
+
_notes: rootContent.notes.map((n) => n.name),
|
|
108
|
+
};
|
|
107
109
|
for (const folder of rootContent.folders) {
|
|
108
110
|
try {
|
|
109
111
|
const subContent = await listFolder(folder);
|
|
110
112
|
structure[folder] = {
|
|
111
113
|
folders: subContent.folders,
|
|
112
|
-
notes: subContent.notes.map(n => n.name),
|
|
114
|
+
notes: subContent.notes.map((n) => n.name),
|
|
113
115
|
};
|
|
114
116
|
}
|
|
115
117
|
catch {
|
|
@@ -130,11 +132,11 @@ async function createNote(notePath, content) {
|
|
|
130
132
|
throw new Error(`笔记已存在: ${notePath}`);
|
|
131
133
|
}
|
|
132
134
|
catch (err) {
|
|
133
|
-
if (err.code !==
|
|
135
|
+
if (err.code !== "ENOENT")
|
|
134
136
|
throw err;
|
|
135
137
|
}
|
|
136
138
|
// 写入文件
|
|
137
|
-
await fs.writeFile(fullPath, content,
|
|
139
|
+
await fs.writeFile(fullPath, content, "utf-8");
|
|
138
140
|
return `笔记创建成功: ${notePath}`;
|
|
139
141
|
}
|
|
140
142
|
// 更新笔记
|
|
@@ -148,7 +150,7 @@ async function updateNote(notePath, content) {
|
|
|
148
150
|
throw new Error(`笔记不存在: ${notePath}`);
|
|
149
151
|
}
|
|
150
152
|
// 写入文件
|
|
151
|
-
await fs.writeFile(fullPath, content,
|
|
153
|
+
await fs.writeFile(fullPath, content, "utf-8");
|
|
152
154
|
return `笔记更新成功: ${notePath}`;
|
|
153
155
|
}
|
|
154
156
|
// 创建文件夹
|
|
@@ -165,7 +167,7 @@ async function createFolder(folderPath) {
|
|
|
165
167
|
}
|
|
166
168
|
}
|
|
167
169
|
catch (err) {
|
|
168
|
-
if (err.code !==
|
|
170
|
+
if (err.code !== "ENOENT")
|
|
169
171
|
throw err;
|
|
170
172
|
}
|
|
171
173
|
// 创建文件夹
|
|
@@ -395,9 +397,15 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
395
397
|
inputSchema: {
|
|
396
398
|
type: "object",
|
|
397
399
|
properties: {
|
|
398
|
-
query: {
|
|
400
|
+
query: {
|
|
401
|
+
type: "string",
|
|
402
|
+
description: "搜索关键词(匹配笔记名称和摘要)",
|
|
403
|
+
},
|
|
399
404
|
tag: { type: "string", description: "按标签过滤" },
|
|
400
|
-
category: {
|
|
405
|
+
category: {
|
|
406
|
+
type: "string",
|
|
407
|
+
description: "按分类过滤(如 hardware, ai, backend 等)",
|
|
408
|
+
},
|
|
401
409
|
},
|
|
402
410
|
},
|
|
403
411
|
},
|
|
@@ -407,7 +415,10 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
407
415
|
inputSchema: {
|
|
408
416
|
type: "object",
|
|
409
417
|
properties: {
|
|
410
|
-
path: {
|
|
418
|
+
path: {
|
|
419
|
+
type: "string",
|
|
420
|
+
description: "笔记的相对路径(如 知识点/03-硬件学习/STM32系列选型速查.md)",
|
|
421
|
+
},
|
|
411
422
|
},
|
|
412
423
|
required: ["path"],
|
|
413
424
|
},
|
|
@@ -418,7 +429,10 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
418
429
|
inputSchema: {
|
|
419
430
|
type: "object",
|
|
420
431
|
properties: {
|
|
421
|
-
folder: {
|
|
432
|
+
folder: {
|
|
433
|
+
type: "string",
|
|
434
|
+
description: "文件夹路径(留空则列出根目录)",
|
|
435
|
+
},
|
|
422
436
|
},
|
|
423
437
|
},
|
|
424
438
|
},
|
|
@@ -444,8 +458,14 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
444
458
|
inputSchema: {
|
|
445
459
|
type: "object",
|
|
446
460
|
properties: {
|
|
447
|
-
path: {
|
|
448
|
-
|
|
461
|
+
path: {
|
|
462
|
+
type: "string",
|
|
463
|
+
description: "笔记的相对路径(如 知识点/04-人工智能/MCP/自己制作的MCP/新笔记.md)",
|
|
464
|
+
},
|
|
465
|
+
content: {
|
|
466
|
+
type: "string",
|
|
467
|
+
description: "笔记内容(支持 Markdown 和 Frontmatter)",
|
|
468
|
+
},
|
|
449
469
|
},
|
|
450
470
|
required: ["path", "content"],
|
|
451
471
|
},
|
|
@@ -479,7 +499,10 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
479
499
|
inputSchema: {
|
|
480
500
|
type: "object",
|
|
481
501
|
properties: {
|
|
482
|
-
path: {
|
|
502
|
+
path: {
|
|
503
|
+
type: "string",
|
|
504
|
+
description: "文件夹的相对路径(如 知识点/04-人工智能/MCP/新文件夹)",
|
|
505
|
+
},
|
|
483
506
|
},
|
|
484
507
|
required: ["path"],
|
|
485
508
|
},
|