@fromsko/obsidian-mcp-server 1.1.9 → 1.2.0

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.
@@ -0,0 +1,208 @@
1
+ import { createNoteService } from "../services/notes.js";
2
+ import { getPromptGuide, suggestFolder, fillTemplate } from "../services/prompt.js";
3
+ export function buildTools(vaultPath) {
4
+ const notes = createNoteService(vaultPath);
5
+ const tools = [
6
+ {
7
+ name: "search_notes",
8
+ description: "搜索 Obsidian 笔记库中的笔记,支持关键词、标签、分类过滤",
9
+ inputSchema: {
10
+ type: "object",
11
+ properties: {
12
+ query: {
13
+ type: "string",
14
+ description: "搜索关键词(匹配笔记名称和摘要)",
15
+ },
16
+ tag: { type: "string", description: "按标签过滤" },
17
+ category: {
18
+ type: "string",
19
+ description: "按分类过滤(如 hardware, ai, backend 等)",
20
+ },
21
+ },
22
+ },
23
+ },
24
+ {
25
+ name: "read_note",
26
+ description: "读取指定笔记的完整内容",
27
+ inputSchema: {
28
+ type: "object",
29
+ properties: {
30
+ path: {
31
+ type: "string",
32
+ description: "笔记的相对路径(如 知识点/03-硬件学习/STM32系列选型速查.md)",
33
+ },
34
+ },
35
+ required: ["path"],
36
+ },
37
+ },
38
+ {
39
+ name: "list_folder",
40
+ description: "列出指定文件夹下的子文件夹和笔记",
41
+ inputSchema: {
42
+ type: "object",
43
+ properties: {
44
+ folder: {
45
+ type: "string",
46
+ description: "文件夹路径(留空则列出根目录)",
47
+ },
48
+ },
49
+ },
50
+ },
51
+ {
52
+ name: "get_note_structure",
53
+ description: "获取整个笔记库的目录结构概览",
54
+ inputSchema: { type: "object", properties: {} },
55
+ },
56
+ {
57
+ name: "full_text_search",
58
+ description: "在所有笔记中进行全文搜索",
59
+ inputSchema: {
60
+ type: "object",
61
+ properties: {
62
+ keyword: { type: "string", description: "要搜索的关键词" },
63
+ },
64
+ required: ["keyword"],
65
+ },
66
+ },
67
+ {
68
+ name: "create_note",
69
+ description: "创建新笔记",
70
+ inputSchema: {
71
+ type: "object",
72
+ properties: {
73
+ path: {
74
+ type: "string",
75
+ description: "笔记的相对路径(如 知识点/04-人工智能/MCP/自己制作的MCP/新笔记.md)",
76
+ },
77
+ content: {
78
+ type: "string",
79
+ description: "笔记内容(支持 Markdown 和 Frontmatter)",
80
+ },
81
+ },
82
+ required: ["path", "content"],
83
+ },
84
+ },
85
+ {
86
+ name: "update_note",
87
+ description: "更新已存在的笔记内容",
88
+ inputSchema: {
89
+ type: "object",
90
+ properties: {
91
+ path: { type: "string", description: "笔记的相对路径" },
92
+ content: { type: "string", description: "新的笔记内容" },
93
+ },
94
+ required: ["path", "content"],
95
+ },
96
+ },
97
+ {
98
+ name: "delete_note",
99
+ description: "删除指定笔记",
100
+ inputSchema: {
101
+ type: "object",
102
+ properties: {
103
+ path: { type: "string", description: "笔记的相对路径" },
104
+ },
105
+ required: ["path"],
106
+ },
107
+ },
108
+ {
109
+ name: "create_folder",
110
+ description: "创建新文件夹",
111
+ inputSchema: {
112
+ type: "object",
113
+ properties: {
114
+ path: {
115
+ type: "string",
116
+ description: "文件夹的相对路径(如 知识点/04-人工智能/MCP/新文件夹)",
117
+ },
118
+ },
119
+ required: ["path"],
120
+ },
121
+ },
122
+ {
123
+ name: "get_prompt_guide",
124
+ description: "获取 Obsidian 知识库整理助手提示词的使用指南,展示如何添加和使用这个提示词",
125
+ inputSchema: {
126
+ type: "object",
127
+ properties: {},
128
+ },
129
+ },
130
+ {
131
+ name: "auto_archive_note",
132
+ description: "根据分类自动归档笔记到建议的文件夹",
133
+ inputSchema: {
134
+ type: "object",
135
+ properties: {
136
+ path: { type: "string", description: "当前笔记路径" },
137
+ category: { type: "string", description: "笔记分类" },
138
+ },
139
+ required: ["path", "category"],
140
+ },
141
+ },
142
+ {
143
+ name: "generate_from_template",
144
+ description: "使用指定模板生成新笔记",
145
+ inputSchema: {
146
+ type: "object",
147
+ properties: {
148
+ templateName: {
149
+ type: "string",
150
+ description: "模板名称(如:概念卡、读书笔记、问题链、本质拆解、扩展思路、灵感启发、复盘行动)"
151
+ },
152
+ noteName: { type: "string", description: "新笔记的文件名(不含路径,如:React学习笔记)" },
153
+ data: {
154
+ type: "object",
155
+ description: "要填充到模板中的键值对数据",
156
+ additionalProperties: { type: "string" }
157
+ },
158
+ category: { type: "string", description: "分类(可选,用于自动决定存放路径)" },
159
+ folder: { type: "string", description: "显式指定的文件夹路径(可选)" }
160
+ },
161
+ required: ["templateName", "noteName", "data"],
162
+ },
163
+ },
164
+ ];
165
+ async function handleTool(name, args) {
166
+ switch (name) {
167
+ case "search_notes":
168
+ return notes.searchNotes(args?.query || "", args?.tag, args?.category);
169
+ case "read_note":
170
+ return notes.readNote(args?.path);
171
+ case "list_folder":
172
+ return notes.listFolder(args?.folder || "");
173
+ case "get_note_structure":
174
+ return notes.getNoteStructure();
175
+ case "full_text_search":
176
+ return notes.fullTextSearch(args?.keyword);
177
+ case "create_note":
178
+ return notes.createNote(args?.path, args?.content);
179
+ case "update_note":
180
+ return notes.updateNote(args?.path, args?.content);
181
+ case "delete_note":
182
+ return notes.deleteNote(args?.path);
183
+ case "create_folder":
184
+ return notes.createFolder(args?.path);
185
+ case "get_prompt_guide":
186
+ return getPromptGuide();
187
+ case "auto_archive_note": {
188
+ const folder = suggestFolder(args?.category);
189
+ const fileName = (args?.path).split("/").pop();
190
+ const newPath = `${folder}${fileName}`;
191
+ return notes.moveNote(args?.path, newPath);
192
+ }
193
+ case "generate_from_template": {
194
+ const template = await notes.getTemplate(args?.templateName);
195
+ const filledContent = fillTemplate(template, args?.data);
196
+ let targetFolder = args?.folder || "";
197
+ if (!targetFolder && args?.category) {
198
+ targetFolder = suggestFolder(args?.category);
199
+ }
200
+ const finalPath = `${targetFolder}${args?.noteName}.md`;
201
+ return notes.createNote(finalPath, filledContent);
202
+ }
203
+ default:
204
+ throw new Error(`未知工具: ${name}`);
205
+ }
206
+ }
207
+ return { tools, handleTool };
208
+ }
@@ -0,0 +1,3 @@
1
+ export declare function parseArgs(): {
2
+ vaultPath: string;
3
+ };
@@ -0,0 +1,16 @@
1
+ export function parseArgs() {
2
+ const args = process.argv.slice(2);
3
+ let vaultPath = "";
4
+ for (let i = 0; i < args.length; i++) {
5
+ if (args[i] === "--vault" && args[i + 1]) {
6
+ vaultPath = args[i + 1];
7
+ break;
8
+ }
9
+ }
10
+ if (!vaultPath) {
11
+ console.error("错误: 请使用 --vault 参数指定 Obsidian 笔记库路径");
12
+ console.error('用法: node dist/index.js --vault "/path/to/your/vault"');
13
+ process.exit(1);
14
+ }
15
+ return { vaultPath };
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fromsko/obsidian-mcp-server",
3
- "version": "1.1.9",
3
+ "version": "1.2.0",
4
4
  "description": "MCP server for Obsidian notes - search and read your Obsidian vault",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -41,4 +41,4 @@
41
41
  "tsx": "^4.7.0",
42
42
  "typescript": "^5.3.0"
43
43
  }
44
- }
44
+ }