@aniketbiswas/obsidian-mcp-server 1.0.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.
- package/LICENSE +21 -0
- package/README.md +232 -0
- package/build/index.d.ts +26 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +148 -0
- package/build/index.js.map +1 -0
- package/build/prompts/index.d.ts +33 -0
- package/build/prompts/index.d.ts.map +1 -0
- package/build/prompts/index.js +152 -0
- package/build/prompts/index.js.map +1 -0
- package/build/prompts/obsidian.d.ts +17 -0
- package/build/prompts/obsidian.d.ts.map +1 -0
- package/build/prompts/obsidian.js +305 -0
- package/build/prompts/obsidian.js.map +1 -0
- package/build/resources/index.d.ts +31 -0
- package/build/resources/index.d.ts.map +1 -0
- package/build/resources/index.js +111 -0
- package/build/resources/index.js.map +1 -0
- package/build/resources/obsidian.d.ts +19 -0
- package/build/resources/obsidian.d.ts.map +1 -0
- package/build/resources/obsidian.js +246 -0
- package/build/resources/obsidian.js.map +1 -0
- package/build/tools/_template.d.ts +23 -0
- package/build/tools/_template.d.ts.map +1 -0
- package/build/tools/_template.js +124 -0
- package/build/tools/_template.js.map +1 -0
- package/build/tools/calculator.d.ts +32 -0
- package/build/tools/calculator.d.ts.map +1 -0
- package/build/tools/calculator.js +130 -0
- package/build/tools/calculator.js.map +1 -0
- package/build/tools/daily-notes.d.ts +19 -0
- package/build/tools/daily-notes.d.ts.map +1 -0
- package/build/tools/daily-notes.js +469 -0
- package/build/tools/daily-notes.js.map +1 -0
- package/build/tools/greeting.d.ts +23 -0
- package/build/tools/greeting.d.ts.map +1 -0
- package/build/tools/greeting.js +111 -0
- package/build/tools/greeting.js.map +1 -0
- package/build/tools/index.d.ts +28 -0
- package/build/tools/index.d.ts.map +1 -0
- package/build/tools/index.js +46 -0
- package/build/tools/index.js.map +1 -0
- package/build/tools/links.d.ts +19 -0
- package/build/tools/links.d.ts.map +1 -0
- package/build/tools/links.js +467 -0
- package/build/tools/links.js.map +1 -0
- package/build/tools/metadata.d.ts +18 -0
- package/build/tools/metadata.d.ts.map +1 -0
- package/build/tools/metadata.js +447 -0
- package/build/tools/metadata.js.map +1 -0
- package/build/tools/navigation.d.ts +19 -0
- package/build/tools/navigation.d.ts.map +1 -0
- package/build/tools/navigation.js +378 -0
- package/build/tools/navigation.js.map +1 -0
- package/build/tools/notes.d.ts +19 -0
- package/build/tools/notes.d.ts.map +1 -0
- package/build/tools/notes.js +622 -0
- package/build/tools/notes.js.map +1 -0
- package/build/tools/search.d.ts +19 -0
- package/build/tools/search.d.ts.map +1 -0
- package/build/tools/search.js +418 -0
- package/build/tools/search.js.map +1 -0
- package/build/tools/templates.d.ts +18 -0
- package/build/tools/templates.d.ts.map +1 -0
- package/build/tools/templates.js +581 -0
- package/build/tools/templates.js.map +1 -0
- package/build/tools/vault.d.ts +19 -0
- package/build/tools/vault.d.ts.map +1 -0
- package/build/tools/vault.js +403 -0
- package/build/tools/vault.js.map +1 -0
- package/build/types/index.d.ts +11 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/index.js +11 -0
- package/build/types/index.js.map +1 -0
- package/build/types/obsidian.d.ts +329 -0
- package/build/types/obsidian.d.ts.map +1 -0
- package/build/types/obsidian.js +38 -0
- package/build/types/obsidian.js.map +1 -0
- package/build/utils/client.d.ts +201 -0
- package/build/utils/client.d.ts.map +1 -0
- package/build/utils/client.js +656 -0
- package/build/utils/client.js.map +1 -0
- package/build/utils/config.d.ts +43 -0
- package/build/utils/config.d.ts.map +1 -0
- package/build/utils/config.js +117 -0
- package/build/utils/config.js.map +1 -0
- package/build/utils/frontmatter.d.ts +90 -0
- package/build/utils/frontmatter.d.ts.map +1 -0
- package/build/utils/frontmatter.js +306 -0
- package/build/utils/frontmatter.js.map +1 -0
- package/build/utils/index.d.ts +13 -0
- package/build/utils/index.d.ts.map +1 -0
- package/build/utils/index.js +13 -0
- package/build/utils/index.js.map +1 -0
- package/build/utils/markdown.d.ts +134 -0
- package/build/utils/markdown.d.ts.map +1 -0
- package/build/utils/markdown.js +330 -0
- package/build/utils/markdown.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,622 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================================
|
|
3
|
+
* OBSIDIAN MCP - Note Tools
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* Core tools for creating, reading, updating, and deleting notes.
|
|
7
|
+
* These are the fundamental operations for note management.
|
|
8
|
+
* ============================================================================
|
|
9
|
+
*/
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { ObsidianApiError } from "../types/obsidian.js";
|
|
12
|
+
import { stringifyFrontmatter, } from "../utils/frontmatter.js";
|
|
13
|
+
import { getSummary, countWords } from "../utils/markdown.js";
|
|
14
|
+
/**
|
|
15
|
+
* Register note CRUD tools with the MCP server.
|
|
16
|
+
*
|
|
17
|
+
* @param server - The MCP server instance
|
|
18
|
+
* @param client - The Obsidian API client
|
|
19
|
+
*/
|
|
20
|
+
export function registerNoteTools(server, client) {
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
// TOOL: read_note
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Read the content of a note.
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
server.tool("read_note", "Read the content of a note from the Obsidian vault. " +
|
|
27
|
+
"Returns the full content including frontmatter, or can return parsed sections.", {
|
|
28
|
+
path: z.string().describe("Path to the note file (e.g., 'folder/note.md')."),
|
|
29
|
+
includeFrontmatter: z
|
|
30
|
+
.boolean()
|
|
31
|
+
.optional()
|
|
32
|
+
.default(true)
|
|
33
|
+
.describe("Whether to include frontmatter in the response."),
|
|
34
|
+
includeStats: z
|
|
35
|
+
.boolean()
|
|
36
|
+
.optional()
|
|
37
|
+
.default(false)
|
|
38
|
+
.describe("Whether to include word count and summary."),
|
|
39
|
+
}, async ({ path, includeFrontmatter, includeStats }) => {
|
|
40
|
+
try {
|
|
41
|
+
// Ensure .md extension
|
|
42
|
+
const filePath = path.endsWith(".md") ? path : `${path}.md`;
|
|
43
|
+
const note = await client.getNote(filePath);
|
|
44
|
+
const response = {
|
|
45
|
+
success: true,
|
|
46
|
+
path: filePath,
|
|
47
|
+
};
|
|
48
|
+
if (includeFrontmatter && note.frontmatter) {
|
|
49
|
+
response.frontmatter = note.frontmatter;
|
|
50
|
+
}
|
|
51
|
+
response.content = includeFrontmatter ? note.content : note.body;
|
|
52
|
+
if (includeStats) {
|
|
53
|
+
response.stats = {
|
|
54
|
+
wordCount: countWords(note.content),
|
|
55
|
+
summary: getSummary(note.content, 150),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
content: [
|
|
60
|
+
{
|
|
61
|
+
type: "text",
|
|
62
|
+
text: JSON.stringify(response, null, 2),
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
const message = error instanceof ObsidianApiError ? error.message : String(error);
|
|
69
|
+
return {
|
|
70
|
+
content: [
|
|
71
|
+
{
|
|
72
|
+
type: "text",
|
|
73
|
+
text: `Error reading note: ${message}`,
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
isError: true,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
// ---------------------------------------------------------------------------
|
|
81
|
+
// TOOL: create_note
|
|
82
|
+
// ---------------------------------------------------------------------------
|
|
83
|
+
// Create a new note in the vault.
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
server.tool("create_note", "Create a new note in the Obsidian vault. " +
|
|
86
|
+
"Can include frontmatter properties like tags, aliases, and custom fields.", {
|
|
87
|
+
path: z
|
|
88
|
+
.string()
|
|
89
|
+
.describe("Path for the new note (e.g., 'folder/note.md'). Will create parent folders if needed."),
|
|
90
|
+
content: z.string().describe("The markdown content for the note."),
|
|
91
|
+
frontmatter: z
|
|
92
|
+
.object({
|
|
93
|
+
title: z.string().optional().describe("Note title"),
|
|
94
|
+
tags: z.array(z.string()).optional().describe("Tags for the note"),
|
|
95
|
+
aliases: z.array(z.string()).optional().describe("Alternative names for the note"),
|
|
96
|
+
created: z.string().optional().describe("Creation date (ISO format)"),
|
|
97
|
+
})
|
|
98
|
+
.passthrough()
|
|
99
|
+
.optional()
|
|
100
|
+
.describe("Frontmatter properties to include in the note."),
|
|
101
|
+
overwrite: z
|
|
102
|
+
.boolean()
|
|
103
|
+
.optional()
|
|
104
|
+
.default(false)
|
|
105
|
+
.describe("Whether to overwrite if the note already exists."),
|
|
106
|
+
}, async ({ path, content, frontmatter, overwrite }) => {
|
|
107
|
+
try {
|
|
108
|
+
// Ensure .md extension
|
|
109
|
+
const filePath = path.endsWith(".md") ? path : `${path}.md`;
|
|
110
|
+
// Check if file exists (unless overwrite is true)
|
|
111
|
+
if (!overwrite) {
|
|
112
|
+
try {
|
|
113
|
+
await client.getFile(filePath);
|
|
114
|
+
return {
|
|
115
|
+
content: [
|
|
116
|
+
{
|
|
117
|
+
type: "text",
|
|
118
|
+
text: `Note already exists: ${filePath}. Set overwrite=true to replace it.`,
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
isError: true,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
// File doesn't exist, which is what we want
|
|
126
|
+
if (!(error instanceof ObsidianApiError && error.status === 404)) {
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// Add creation timestamp if not provided
|
|
132
|
+
const fm = {
|
|
133
|
+
...frontmatter,
|
|
134
|
+
created: frontmatter?.created || new Date().toISOString(),
|
|
135
|
+
};
|
|
136
|
+
await client.createNote(filePath, content, fm);
|
|
137
|
+
return {
|
|
138
|
+
content: [
|
|
139
|
+
{
|
|
140
|
+
type: "text",
|
|
141
|
+
text: JSON.stringify({
|
|
142
|
+
success: true,
|
|
143
|
+
message: `Note created: ${filePath}`,
|
|
144
|
+
path: filePath,
|
|
145
|
+
frontmatter: fm,
|
|
146
|
+
}, null, 2),
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
const message = error instanceof ObsidianApiError ? error.message : String(error);
|
|
153
|
+
return {
|
|
154
|
+
content: [
|
|
155
|
+
{
|
|
156
|
+
type: "text",
|
|
157
|
+
text: `Error creating note: ${message}`,
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
isError: true,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
// ---------------------------------------------------------------------------
|
|
165
|
+
// TOOL: update_note
|
|
166
|
+
// ---------------------------------------------------------------------------
|
|
167
|
+
// Update an existing note's content.
|
|
168
|
+
// ---------------------------------------------------------------------------
|
|
169
|
+
server.tool("update_note", "Update the content of an existing note in the Obsidian vault. " +
|
|
170
|
+
"Replaces the entire content of the note.", {
|
|
171
|
+
path: z.string().describe("Path to the note to update."),
|
|
172
|
+
content: z.string().describe("New content for the note."),
|
|
173
|
+
preserveFrontmatter: z
|
|
174
|
+
.boolean()
|
|
175
|
+
.optional()
|
|
176
|
+
.default(true)
|
|
177
|
+
.describe("Whether to preserve existing frontmatter."),
|
|
178
|
+
updateModified: z
|
|
179
|
+
.boolean()
|
|
180
|
+
.optional()
|
|
181
|
+
.default(true)
|
|
182
|
+
.describe("Whether to update the 'modified' frontmatter field."),
|
|
183
|
+
}, async ({ path, content, preserveFrontmatter, updateModified }) => {
|
|
184
|
+
try {
|
|
185
|
+
const filePath = path.endsWith(".md") ? path : `${path}.md`;
|
|
186
|
+
let finalContent = content;
|
|
187
|
+
if (preserveFrontmatter) {
|
|
188
|
+
// Get existing frontmatter
|
|
189
|
+
const existingNote = await client.getNote(filePath);
|
|
190
|
+
if (existingNote.frontmatter && Object.keys(existingNote.frontmatter).length > 0) {
|
|
191
|
+
const fm = existingNote.frontmatter;
|
|
192
|
+
if (updateModified) {
|
|
193
|
+
fm.modified = new Date().toISOString();
|
|
194
|
+
}
|
|
195
|
+
finalContent = stringifyFrontmatter(fm) + content;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
await client.putFile(filePath, finalContent);
|
|
199
|
+
return {
|
|
200
|
+
content: [
|
|
201
|
+
{
|
|
202
|
+
type: "text",
|
|
203
|
+
text: JSON.stringify({
|
|
204
|
+
success: true,
|
|
205
|
+
message: `Note updated: ${filePath}`,
|
|
206
|
+
path: filePath,
|
|
207
|
+
}, null, 2),
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
const message = error instanceof ObsidianApiError ? error.message : String(error);
|
|
214
|
+
return {
|
|
215
|
+
content: [
|
|
216
|
+
{
|
|
217
|
+
type: "text",
|
|
218
|
+
text: `Error updating note: ${message}`,
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
isError: true,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
// ---------------------------------------------------------------------------
|
|
226
|
+
// TOOL: append_to_note
|
|
227
|
+
// ---------------------------------------------------------------------------
|
|
228
|
+
// Append content to an existing note.
|
|
229
|
+
// ---------------------------------------------------------------------------
|
|
230
|
+
server.tool("append_to_note", "Append content to the end of an existing note. " +
|
|
231
|
+
"Useful for adding new sections, logging entries, or updating lists.", {
|
|
232
|
+
path: z.string().describe("Path to the note."),
|
|
233
|
+
content: z.string().describe("Content to append."),
|
|
234
|
+
ensureNewline: z
|
|
235
|
+
.boolean()
|
|
236
|
+
.optional()
|
|
237
|
+
.default(true)
|
|
238
|
+
.describe("Whether to ensure content starts on a new line."),
|
|
239
|
+
createIfMissing: z
|
|
240
|
+
.boolean()
|
|
241
|
+
.optional()
|
|
242
|
+
.default(false)
|
|
243
|
+
.describe("Whether to create the note if it doesn't exist."),
|
|
244
|
+
}, async ({ path, content, ensureNewline, createIfMissing }) => {
|
|
245
|
+
try {
|
|
246
|
+
const filePath = path.endsWith(".md") ? path : `${path}.md`;
|
|
247
|
+
// Check if file exists
|
|
248
|
+
try {
|
|
249
|
+
await client.getFile(filePath);
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
if (error instanceof ObsidianApiError && error.status === 404) {
|
|
253
|
+
if (createIfMissing) {
|
|
254
|
+
await client.putFile(filePath, content);
|
|
255
|
+
return {
|
|
256
|
+
content: [
|
|
257
|
+
{
|
|
258
|
+
type: "text",
|
|
259
|
+
text: JSON.stringify({
|
|
260
|
+
success: true,
|
|
261
|
+
message: `Note created and content added: ${filePath}`,
|
|
262
|
+
path: filePath,
|
|
263
|
+
}, null, 2),
|
|
264
|
+
},
|
|
265
|
+
],
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
throw error;
|
|
269
|
+
}
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
const contentToAppend = ensureNewline ? `\n${content}` : content;
|
|
273
|
+
await client.appendToFile(filePath, contentToAppend);
|
|
274
|
+
return {
|
|
275
|
+
content: [
|
|
276
|
+
{
|
|
277
|
+
type: "text",
|
|
278
|
+
text: JSON.stringify({
|
|
279
|
+
success: true,
|
|
280
|
+
message: `Content appended to: ${filePath}`,
|
|
281
|
+
path: filePath,
|
|
282
|
+
}, null, 2),
|
|
283
|
+
},
|
|
284
|
+
],
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
const message = error instanceof ObsidianApiError ? error.message : String(error);
|
|
289
|
+
return {
|
|
290
|
+
content: [
|
|
291
|
+
{
|
|
292
|
+
type: "text",
|
|
293
|
+
text: `Error appending to note: ${message}`,
|
|
294
|
+
},
|
|
295
|
+
],
|
|
296
|
+
isError: true,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
// ---------------------------------------------------------------------------
|
|
301
|
+
// TOOL: prepend_to_note
|
|
302
|
+
// ---------------------------------------------------------------------------
|
|
303
|
+
// Prepend content to a note (after frontmatter).
|
|
304
|
+
// ---------------------------------------------------------------------------
|
|
305
|
+
server.tool("prepend_to_note", "Prepend content to the beginning of a note (after frontmatter). " +
|
|
306
|
+
"Useful for adding headers, timestamps, or important notices.", {
|
|
307
|
+
path: z.string().describe("Path to the note."),
|
|
308
|
+
content: z.string().describe("Content to prepend."),
|
|
309
|
+
ensureNewline: z
|
|
310
|
+
.boolean()
|
|
311
|
+
.optional()
|
|
312
|
+
.default(true)
|
|
313
|
+
.describe("Whether to ensure content ends with a newline."),
|
|
314
|
+
}, async ({ path, content, ensureNewline }) => {
|
|
315
|
+
try {
|
|
316
|
+
const filePath = path.endsWith(".md") ? path : `${path}.md`;
|
|
317
|
+
const contentToAdd = ensureNewline ? `${content}\n` : content;
|
|
318
|
+
await client.patchFile(filePath, contentToAdd, {
|
|
319
|
+
operation: "prepend",
|
|
320
|
+
});
|
|
321
|
+
return {
|
|
322
|
+
content: [
|
|
323
|
+
{
|
|
324
|
+
type: "text",
|
|
325
|
+
text: JSON.stringify({
|
|
326
|
+
success: true,
|
|
327
|
+
message: `Content prepended to: ${filePath}`,
|
|
328
|
+
path: filePath,
|
|
329
|
+
}, null, 2),
|
|
330
|
+
},
|
|
331
|
+
],
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
catch (error) {
|
|
335
|
+
const message = error instanceof ObsidianApiError ? error.message : String(error);
|
|
336
|
+
return {
|
|
337
|
+
content: [
|
|
338
|
+
{
|
|
339
|
+
type: "text",
|
|
340
|
+
text: `Error prepending to note: ${message}`,
|
|
341
|
+
},
|
|
342
|
+
],
|
|
343
|
+
isError: true,
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
// ---------------------------------------------------------------------------
|
|
348
|
+
// TOOL: insert_under_heading
|
|
349
|
+
// ---------------------------------------------------------------------------
|
|
350
|
+
// Insert content under a specific heading.
|
|
351
|
+
// ---------------------------------------------------------------------------
|
|
352
|
+
server.tool("insert_under_heading", "Insert content under a specific heading in a note. " +
|
|
353
|
+
"Useful for adding content to specific sections without modifying the rest.", {
|
|
354
|
+
path: z.string().describe("Path to the note."),
|
|
355
|
+
heading: z.string().describe("The heading text to insert under (without # symbols)."),
|
|
356
|
+
content: z.string().describe("Content to insert."),
|
|
357
|
+
createHeadingIfMissing: z
|
|
358
|
+
.boolean()
|
|
359
|
+
.optional()
|
|
360
|
+
.default(false)
|
|
361
|
+
.describe("Whether to create the heading if it doesn't exist."),
|
|
362
|
+
headingLevel: z
|
|
363
|
+
.number()
|
|
364
|
+
.int()
|
|
365
|
+
.min(1)
|
|
366
|
+
.max(6)
|
|
367
|
+
.optional()
|
|
368
|
+
.default(2)
|
|
369
|
+
.describe("Heading level to use if creating (default: 2 for ##)."),
|
|
370
|
+
}, async ({ path, heading, content, createHeadingIfMissing, headingLevel }) => {
|
|
371
|
+
try {
|
|
372
|
+
const filePath = path.endsWith(".md") ? path : `${path}.md`;
|
|
373
|
+
// Try to insert under the heading
|
|
374
|
+
try {
|
|
375
|
+
await client.patchFile(filePath, content, {
|
|
376
|
+
operation: "insert-under-heading",
|
|
377
|
+
heading,
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
// If heading not found and we should create it
|
|
382
|
+
if (createHeadingIfMissing) {
|
|
383
|
+
const hashes = "#".repeat(headingLevel || 2);
|
|
384
|
+
const newContent = `\n\n${hashes} ${heading}\n\n${content}`;
|
|
385
|
+
await client.appendToFile(filePath, newContent);
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
throw error;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return {
|
|
392
|
+
content: [
|
|
393
|
+
{
|
|
394
|
+
type: "text",
|
|
395
|
+
text: JSON.stringify({
|
|
396
|
+
success: true,
|
|
397
|
+
message: `Content inserted under heading "${heading}" in: ${filePath}`,
|
|
398
|
+
path: filePath,
|
|
399
|
+
}, null, 2),
|
|
400
|
+
},
|
|
401
|
+
],
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
catch (error) {
|
|
405
|
+
const message = error instanceof ObsidianApiError ? error.message : String(error);
|
|
406
|
+
return {
|
|
407
|
+
content: [
|
|
408
|
+
{
|
|
409
|
+
type: "text",
|
|
410
|
+
text: `Error inserting under heading: ${message}`,
|
|
411
|
+
},
|
|
412
|
+
],
|
|
413
|
+
isError: true,
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
// ---------------------------------------------------------------------------
|
|
418
|
+
// TOOL: replace_in_note
|
|
419
|
+
// ---------------------------------------------------------------------------
|
|
420
|
+
// Find and replace text in a note.
|
|
421
|
+
// ---------------------------------------------------------------------------
|
|
422
|
+
server.tool("replace_in_note", "Find and replace text in a note. " +
|
|
423
|
+
"Useful for making specific edits without replacing the entire content.", {
|
|
424
|
+
path: z.string().describe("Path to the note."),
|
|
425
|
+
find: z.string().describe("Text to find."),
|
|
426
|
+
replace: z.string().describe("Text to replace with."),
|
|
427
|
+
replaceAll: z
|
|
428
|
+
.boolean()
|
|
429
|
+
.optional()
|
|
430
|
+
.default(false)
|
|
431
|
+
.describe("Whether to replace all occurrences."),
|
|
432
|
+
}, async ({ path, find, replace, replaceAll }) => {
|
|
433
|
+
try {
|
|
434
|
+
const filePath = path.endsWith(".md") ? path : `${path}.md`;
|
|
435
|
+
// Get current content
|
|
436
|
+
const currentContent = await client.getFile(filePath);
|
|
437
|
+
// Perform replacement
|
|
438
|
+
let newContent;
|
|
439
|
+
let count = 0;
|
|
440
|
+
if (replaceAll) {
|
|
441
|
+
// Count occurrences
|
|
442
|
+
const regex = new RegExp(escapeRegExp(find), "g");
|
|
443
|
+
const matches = currentContent.match(regex);
|
|
444
|
+
count = matches ? matches.length : 0;
|
|
445
|
+
newContent = currentContent.replace(regex, replace);
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
count = currentContent.includes(find) ? 1 : 0;
|
|
449
|
+
newContent = currentContent.replace(find, replace);
|
|
450
|
+
}
|
|
451
|
+
if (count === 0) {
|
|
452
|
+
return {
|
|
453
|
+
content: [
|
|
454
|
+
{
|
|
455
|
+
type: "text",
|
|
456
|
+
text: JSON.stringify({
|
|
457
|
+
success: false,
|
|
458
|
+
message: "Text not found in note.",
|
|
459
|
+
path: filePath,
|
|
460
|
+
}, null, 2),
|
|
461
|
+
},
|
|
462
|
+
],
|
|
463
|
+
isError: true,
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
await client.putFile(filePath, newContent);
|
|
467
|
+
return {
|
|
468
|
+
content: [
|
|
469
|
+
{
|
|
470
|
+
type: "text",
|
|
471
|
+
text: JSON.stringify({
|
|
472
|
+
success: true,
|
|
473
|
+
message: `Replaced ${count} occurrence(s) in: ${filePath}`,
|
|
474
|
+
path: filePath,
|
|
475
|
+
replacements: count,
|
|
476
|
+
}, null, 2),
|
|
477
|
+
},
|
|
478
|
+
],
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
catch (error) {
|
|
482
|
+
const message = error instanceof ObsidianApiError ? error.message : String(error);
|
|
483
|
+
return {
|
|
484
|
+
content: [
|
|
485
|
+
{
|
|
486
|
+
type: "text",
|
|
487
|
+
text: `Error replacing in note: ${message}`,
|
|
488
|
+
},
|
|
489
|
+
],
|
|
490
|
+
isError: true,
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
// ---------------------------------------------------------------------------
|
|
495
|
+
// TOOL: delete_note
|
|
496
|
+
// ---------------------------------------------------------------------------
|
|
497
|
+
// Delete a note from the vault.
|
|
498
|
+
// ---------------------------------------------------------------------------
|
|
499
|
+
server.tool("delete_note", "Delete a note from the Obsidian vault. " +
|
|
500
|
+
"WARNING: This permanently removes the note. Use with caution.", {
|
|
501
|
+
path: z.string().describe("Path to the note to delete."),
|
|
502
|
+
confirm: z
|
|
503
|
+
.boolean()
|
|
504
|
+
.describe("Set to true to confirm deletion. Required safety check."),
|
|
505
|
+
}, async ({ path, confirm }) => {
|
|
506
|
+
if (!confirm) {
|
|
507
|
+
return {
|
|
508
|
+
content: [
|
|
509
|
+
{
|
|
510
|
+
type: "text",
|
|
511
|
+
text: "Deletion not confirmed. Set confirm=true to delete the note.",
|
|
512
|
+
},
|
|
513
|
+
],
|
|
514
|
+
isError: true,
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
try {
|
|
518
|
+
const filePath = path.endsWith(".md") ? path : `${path}.md`;
|
|
519
|
+
await client.deleteFile(filePath);
|
|
520
|
+
return {
|
|
521
|
+
content: [
|
|
522
|
+
{
|
|
523
|
+
type: "text",
|
|
524
|
+
text: JSON.stringify({
|
|
525
|
+
success: true,
|
|
526
|
+
message: `Note deleted: ${filePath}`,
|
|
527
|
+
}, null, 2),
|
|
528
|
+
},
|
|
529
|
+
],
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
catch (error) {
|
|
533
|
+
const message = error instanceof ObsidianApiError ? error.message : String(error);
|
|
534
|
+
return {
|
|
535
|
+
content: [
|
|
536
|
+
{
|
|
537
|
+
type: "text",
|
|
538
|
+
text: `Error deleting note: ${message}`,
|
|
539
|
+
},
|
|
540
|
+
],
|
|
541
|
+
isError: true,
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
// ---------------------------------------------------------------------------
|
|
546
|
+
// TOOL: copy_note
|
|
547
|
+
// ---------------------------------------------------------------------------
|
|
548
|
+
// Copy a note to a new location.
|
|
549
|
+
// ---------------------------------------------------------------------------
|
|
550
|
+
server.tool("copy_note", "Copy a note to a new location in the vault. " +
|
|
551
|
+
"The original note is preserved.", {
|
|
552
|
+
sourcePath: z.string().describe("Path of the note to copy."),
|
|
553
|
+
destinationPath: z.string().describe("Path for the new copy."),
|
|
554
|
+
overwrite: z
|
|
555
|
+
.boolean()
|
|
556
|
+
.optional()
|
|
557
|
+
.default(false)
|
|
558
|
+
.describe("Whether to overwrite if destination exists."),
|
|
559
|
+
}, async ({ sourcePath, destinationPath, overwrite }) => {
|
|
560
|
+
try {
|
|
561
|
+
const srcPath = sourcePath.endsWith(".md") ? sourcePath : `${sourcePath}.md`;
|
|
562
|
+
const dstPath = destinationPath.endsWith(".md")
|
|
563
|
+
? destinationPath
|
|
564
|
+
: `${destinationPath}.md`;
|
|
565
|
+
// Check if destination exists
|
|
566
|
+
if (!overwrite) {
|
|
567
|
+
try {
|
|
568
|
+
await client.getFile(dstPath);
|
|
569
|
+
return {
|
|
570
|
+
content: [
|
|
571
|
+
{
|
|
572
|
+
type: "text",
|
|
573
|
+
text: `Destination already exists: ${dstPath}. Set overwrite=true to replace it.`,
|
|
574
|
+
},
|
|
575
|
+
],
|
|
576
|
+
isError: true,
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
catch (error) {
|
|
580
|
+
if (!(error instanceof ObsidianApiError && error.status === 404)) {
|
|
581
|
+
throw error;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
// Read source and write to destination
|
|
586
|
+
const content = await client.getFile(srcPath);
|
|
587
|
+
await client.putFile(dstPath, content);
|
|
588
|
+
return {
|
|
589
|
+
content: [
|
|
590
|
+
{
|
|
591
|
+
type: "text",
|
|
592
|
+
text: JSON.stringify({
|
|
593
|
+
success: true,
|
|
594
|
+
message: `Note copied from ${srcPath} to ${dstPath}`,
|
|
595
|
+
source: srcPath,
|
|
596
|
+
destination: dstPath,
|
|
597
|
+
}, null, 2),
|
|
598
|
+
},
|
|
599
|
+
],
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
catch (error) {
|
|
603
|
+
const message = error instanceof ObsidianApiError ? error.message : String(error);
|
|
604
|
+
return {
|
|
605
|
+
content: [
|
|
606
|
+
{
|
|
607
|
+
type: "text",
|
|
608
|
+
text: `Error copying note: ${message}`,
|
|
609
|
+
},
|
|
610
|
+
],
|
|
611
|
+
isError: true,
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Escape special characters for use in RegExp.
|
|
618
|
+
*/
|
|
619
|
+
function escapeRegExp(string) {
|
|
620
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
621
|
+
}
|
|
622
|
+
//# sourceMappingURL=notes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notes.js","sourceRoot":"","sources":["../../src/tools/notes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAuB,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAEL,oBAAoB,GAErB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAiB,EAAE,MAAsB;IACzE,8EAA8E;IAC9E,kBAAkB;IAClB,8EAA8E;IAC9E,8BAA8B;IAC9B,8EAA8E;IAE9E,MAAM,CAAC,IAAI,CACT,WAAW,EACX,sDAAsD;QACpD,gFAAgF,EAClF;QACE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iDAAiD,CAAC;QAC5E,kBAAkB,EAAE,CAAC;aAClB,OAAO,EAAE;aACT,QAAQ,EAAE;aACV,OAAO,CAAC,IAAI,CAAC;aACb,QAAQ,CAAC,iDAAiD,CAAC;QAC9D,YAAY,EAAE,CAAC;aACZ,OAAO,EAAE;aACT,QAAQ,EAAE;aACV,OAAO,CAAC,KAAK,CAAC;aACd,QAAQ,CAAC,4CAA4C,CAAC;KAC1D,EACD,KAAK,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE,YAAY,EAAE,EAAE,EAAE;QACnD,IAAI,CAAC;YACH,uBAAuB;YACvB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,C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BACP;wBACE,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,uBAAuB,OAAO,EAAE;qBACvC;iBACF;gBACD,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,YAAY,CAAC,MAAc;IAClC,OAAO,MAAM,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================================
|
|
3
|
+
* OBSIDIAN MCP - Search Tools
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* Tools for searching notes in the Obsidian vault.
|
|
7
|
+
* Supports full-text search, tag search, and pattern matching.
|
|
8
|
+
* ============================================================================
|
|
9
|
+
*/
|
|
10
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
11
|
+
import { ObsidianClient } from "../utils/client.js";
|
|
12
|
+
/**
|
|
13
|
+
* Register search tools with the MCP server.
|
|
14
|
+
*
|
|
15
|
+
* @param server - The MCP server instance
|
|
16
|
+
* @param client - The Obsidian API client
|
|
17
|
+
*/
|
|
18
|
+
export declare function registerSearchTools(server: McpServer, client: ObsidianClient): void;
|
|
19
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/tools/search.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAKpD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,GAAG,IAAI,CAufnF"}
|