@inkdropapp/mcp-server 1.5.0 → 1.7.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/README.md CHANGED
@@ -34,63 +34,67 @@ Read [the docs here](https://docs.inkdrop.app/reference/mcp-server).
34
34
  - `sort`: Sort field (`updatedAt`, `createdAt`, or `title`). Default: `updatedAt`.
35
35
  - `descending`: Reverse the order of output. Default: `true`.
36
36
  - Note: Results include truncated note bodies (200 characters). Use `read-note` to get full content.
37
- 5. **`create-note`**: Create a new note in the database.
37
+ 5. **`list-templates`**: List note templates — your custom templates, followed by the official ones bundled with Inkdrop.
38
+ - Optional inputs:
39
+ - `keyword`: Filter templates by fuzzy-matching their titles.
40
+ - Note: Results include truncated template bodies (200 characters). Use `read-note` to get full content.
41
+ 6. **`create-note`**: Create a new note in the database.
38
42
  - Required inputs:
39
- - `bookId`: The notebook ID. Must start with 'book:' or be 'trash'.
43
+ - `bookId`: The notebook ID. Must start with 'book:' or be 'trash' or 'template'. Specify 'template' to create a custom note template.
40
44
  - `title`: The note title.
41
45
  - `body`: The content of the note in Markdown.
42
46
  - Optional inputs:
43
47
  - `status`: The note status (`none`, `active`, `onHold`, `completed`, `dropped`).
44
48
  - `tags`: An array of tag IDs to assign to the note. Each must start with 'tag:'.
45
- 6. **`update-note`**: Update an existing note in the database. Only the fields you provide will be updated; omitted fields remain unchanged.
49
+ 7. **`update-note`**: Update an existing note in the database. Only the fields you provide will be updated; omitted fields remain unchanged.
46
50
  - Required inputs:
47
51
  - `_id`: The note ID. Must start with 'note:'.
48
52
  - `_rev`: The revision ID (CouchDB MVCC-token).
49
53
  - Optional inputs:
50
- - `bookId`: The notebook ID. Must start with 'book:' or be 'trash'.
54
+ - `bookId`: The notebook ID. Must start with 'book:' or be 'trash' or 'template'.
51
55
  - `title`: The note title.
52
56
  - `body`: The content of the note in Markdown.
53
57
  - `status`: The note status (`none`, `active`, `onHold`, `completed`, `dropped`).
54
58
  - `tags`: An array of tag IDs to assign to the note. Each must start with 'tag:'.
55
- 7. **`patch-note`**: Update the body of an existing note by performing an exact string replacement. More efficient than `update-note` for small edits to large notes as it saves tokens. You must first read the note with `read-note` to get the current body.
59
+ 8. **`patch-note`**: Update the body of an existing note by performing one or more exact string replacements in a single call. More efficient than `update-note` for small edits to large notes as it saves tokens. You must first read the note with `read-note` to get the current body.
56
60
  - Required inputs:
57
61
  - `_id`: The note ID. Must start with 'note:'.
58
62
  - `_rev`: The revision ID (CouchDB MVCC-token).
59
63
  - `old_string`: The exact text to find in the note body. Must match exactly one occurrence. Include enough surrounding context to ensure a unique match.
60
64
  - `new_string`: The text to replace `old_string` with. Use an empty string to delete the matched text.
61
- 8. **`list-notebooks`**: Retrieve a list of all notebooks.
62
- 9. **`read-book`**: Retrieve a single notebook by its ID.
63
- - Required inputs:
64
- - `bookId`: The notebook ID. Must start with 'book:'.
65
- 10. **`create-book`**: Create a new notebook in the database.
65
+ 9. **`list-notebooks`**: Retrieve a list of all notebooks.
66
+ 10. **`read-book`**: Retrieve a single notebook by its ID.
67
+ - Required inputs:
68
+ - `bookId`: The notebook ID. Must start with 'book:'.
69
+ 11. **`create-book`**: Create a new notebook in the database.
66
70
  - Required inputs:
67
71
  - `name`: The notebook name.
68
72
  - Optional inputs:
69
73
  - `parentBookId`: The ID of the parent notebook. Must start with 'book:'. Omit it to create the notebook at the root level.
70
- 11. **`update-book`**: Update an existing notebook in the database. Only the fields you provide will be updated; omitted fields remain unchanged, so you don't need to read the notebook first.
74
+ 12. **`update-book`**: Update an existing notebook in the database. Only the fields you provide will be updated; omitted fields remain unchanged, so you don't need to read the notebook first.
71
75
  - Required inputs:
72
76
  - `_id`: The notebook ID. Must start with 'book:'.
73
77
  - Optional inputs:
74
78
  - `_rev`: The revision ID (CouchDB MVCC-token). Only needed as an optimistic-concurrency guard — pass it to make the update fail on a conflicting concurrent edit.
75
79
  - `name`: The notebook name.
76
80
  - `parentBookId`: The ID of the parent notebook. Pass `null` to move the notebook to the root level.
77
- 12. **`list-tags`**: Retrieve a list of all tags.
78
- 13. **`read-tag`**: Retrieve a single tag by its ID.
81
+ 13. **`list-tags`**: Retrieve a list of all tags.
82
+ 14. **`read-tag`**: Retrieve a single tag by its ID.
79
83
  - Required inputs:
80
84
  - `tagId`: The tag ID. Must start with 'tag:'.
81
- 14. **`create-tag`**: Create a new tag in the database.
85
+ 15. **`create-tag`**: Create a new tag in the database.
82
86
  - Required inputs:
83
87
  - `name`: The name of the tag.
84
88
  - Optional inputs:
85
89
  - `color`: The color type of the tag (`default`, `red`, `orange`, `yellow`, `olive`, `green`, `teal`, `blue`, `violet`, `purple`, `pink`, `brown`, `grey`, `black`). Default: `default`.
86
- 15. **`update-tag`**: Update an existing tag in the database. Only the fields you provide will be updated; omitted fields remain unchanged, so you don't need to read the tag first.
90
+ 16. **`update-tag`**: Update an existing tag in the database. Only the fields you provide will be updated; omitted fields remain unchanged, so you don't need to read the tag first.
87
91
  - Required inputs:
88
92
  - `_id`: The tag ID. Must start with 'tag:'.
89
93
  - Optional inputs:
90
94
  - `_rev`: The revision ID (CouchDB MVCC-token). Only needed as an optimistic-concurrency guard — pass it to make the update fail on a conflicting concurrent edit.
91
95
  - `name`: The name of the tag.
92
96
  - `color`: The color type of the tag. Omit it to keep the tag's current color.
93
- 16. **`create-file`**: Create a new attachment file in the database from a local image file or from base64 image data. Returns the Markdown to embed the attachment in a note body.
97
+ 17. **`create-file`**: Create a new attachment file in the database from a local image file or from base64 image data. Returns the Markdown to embed the attachment in a note body.
94
98
  - Required inputs: exactly one of
95
99
  - `filePath`: Absolute path to a local image file to attach. Preferred — it keeps the image bytes out of the conversation.
96
100
  - `data`: Base64-encoded image data, without a `data:` URI prefix.
@@ -99,7 +103,7 @@ Read [the docs here](https://docs.inkdrop.app/reference/mcp-server).
99
103
  - `contentType`: The MIME type (`image/png`, `image/jpeg`, `image/jpg`, `image/svg+xml`, `image/gif`, `image/heic`, `image/heif`). Inferred from the `filePath` extension when omitted, so it is required with `data`.
100
104
  - `publicIn`: An array of note IDs where the attachment is included. Each must start with 'note:'.
101
105
  - Note: Attachments are limited to 10MB.
102
- 17. **`read-file`**: Retrieve an attachment file by its ID. Returns the file metadata, and the image itself when it is a PNG, JPEG or GIF.
106
+ 18. **`read-file`**: Retrieve an attachment file by its ID. Returns the file metadata, and the image itself when it is a PNG, JPEG or GIF.
103
107
  - Required inputs:
104
108
  - `fileId`: The attachment ID. Must start with 'file:'.
105
109
  - Optional inputs:
package/dist/index.js CHANGED
@@ -131,10 +131,10 @@ You can use special qualifiers to get more accurate results. See the qualifiers
131
131
  - **book**
132
132
  \`book:Blog\`: Searches for notes in the 'Blog' notebook.
133
133
  \`book:"Desktop App"\`: Searches for notes in the 'Desktop App' notebook.
134
- - **bookId**
135
- \`bookId:kGlLniaV\`: Searches for notes in the notebook ID 'book:kGlLniaV'.
134
+ \`book:kGlLniaV\`: Searches for notes in the notebook with the ID 'book:kGlLniaV'.
136
135
  - **tag**
137
136
  \`tag:JavaScript\`: Searches for all notes having the 'JavaScript' tag. Read more about [tags](https://docs.inkdrop.app/manual/write-notes#tag-notes).
137
+ \`tag:pQ7xYt2R\`: Searches for all notes having the tag with the ID 'tag:pQ7xYt2R'.
138
138
  - **status**
139
139
  \`status:onHold\`: Searches for all notes with the 'On hold' status. Read more about [statuses](/reference/note-statuses).
140
140
  - **title**
@@ -215,7 +215,7 @@ You have to retrieve the full note content by calling \`read-note\`.
215
215
  bookId: zod_1.z
216
216
  .string()
217
217
  .optional()
218
- .describe(`ID of the notebook. It always starts with 'book:'. You can retrieve a list of notebooks with \`list-notebooks\``),
218
+ .describe(`ID of the notebook. It always starts with 'book:'. You can retrieve a list of notebooks with \`list-notebooks\`. The pseudo-notebooks 'trash' and 'template' are not supported here; use \`list-templates\` for templates`),
219
219
  tagIds: zod_1.z
220
220
  .array(zod_1.z.string())
221
221
  .optional()
@@ -235,8 +235,8 @@ You have to retrieve the full note content by calling \`read-note\`.
235
235
  limit: zod_1.z.number().optional().default(100).describe(`Limit the number of results returned`)
236
236
  }
237
237
  }, async ({ bookId, tagIds, keyword, sort, descending, limit }) => {
238
- const bookFilter = bookId ? `bookId:${bookId.split(':')[1]}` : '';
239
- const tagFilter = tagIds ? tagIds.map(t => `tagId:${t}`).join(' ') : '';
238
+ const bookFilter = bookId ?? '';
239
+ const tagFilter = tagIds?.join(' ') ?? '';
240
240
  keyword = `${bookFilter} ${tagFilter} ${keyword || ''}`.trim();
241
241
  const notes = await (0, api_1.fetchJSON)('/notes', {
242
242
  keyword,
@@ -259,6 +259,35 @@ You have to retrieve the full note content by calling \`read-note\`.
259
259
  ]
260
260
  };
261
261
  });
262
+ server.registerTool('list-templates', {
263
+ description: `List note templates: your custom templates, followed by the official ones bundled with Inkdrop.
264
+ Templates are notes whose \`bookId\` is \`template\`. Official templates are read-only.
265
+ The result does not include entire template bodies as they are truncated in 200 characters.
266
+ You have to retrieve the full template content by calling \`read-note\`.
267
+ `,
268
+ inputSchema: {
269
+ keyword: zod_1.z
270
+ .string()
271
+ .optional()
272
+ .describe('Filter templates by fuzzy-matching their titles. Search qualifiers such as `book:` or `tag:` are not supported.')
273
+ }
274
+ }, async ({ keyword }) => {
275
+ const templates = await (0, api_1.fetchJSON)('/templates', { keyword });
276
+ const summaries = templates.map(template => {
277
+ return {
278
+ ...template,
279
+ body: template.body.substring(0, 200)
280
+ };
281
+ });
282
+ return {
283
+ content: [
284
+ {
285
+ type: 'text',
286
+ text: JSON.stringify(summaries, null, 2)
287
+ }
288
+ ]
289
+ };
290
+ });
262
291
  server.registerTool('create-note', {
263
292
  description: 'Create a new note in the database',
264
293
  inputSchema: {
@@ -266,8 +295,8 @@ server.registerTool('create-note', {
266
295
  .string()
267
296
  .min(5)
268
297
  .max(128)
269
- .regex(/^(book:|trash$)/)
270
- .describe('The notebook ID'),
298
+ .regex(/^(book:|trash$|template$)/)
299
+ .describe('The notebook ID. Specify `template` to create a custom note template'),
271
300
  title: zod_1.z.string().max(128).describe('The note title'),
272
301
  body: zod_1.z.string().max(1048576).describe('The content of the note represented with Markdown'),
273
302
  status: zod_1.z
@@ -306,9 +335,9 @@ server.registerTool('update-note', {
306
335
  .string()
307
336
  .min(5)
308
337
  .max(128)
309
- .regex(/^(book:|trash$)/)
338
+ .regex(/^(book:|trash$|template$)/)
310
339
  .optional()
311
- .describe('The notebook ID'),
340
+ .describe('The notebook ID. Specify `template` to turn the note into a custom note template'),
312
341
  title: zod_1.z.string().max(128).optional().describe('The note title'),
313
342
  body: zod_1.z
314
343
  .string()
@@ -342,7 +371,7 @@ server.registerTool('update-note', {
342
371
  };
343
372
  });
344
373
  server.registerTool('patch-note', {
345
- description: 'Update the body of the existing note by performing an exact string replacement. Use this tool to make partial updates to the note body without replacing the entire content. You must first read the note with `read-note` to get the current body, then specify the exact substring to replace.',
374
+ description: 'Update the body of the existing note by performing one or more exact string replacements. Use this tool to make partial updates to the note body without replacing the entire content. You must first read the note with `read-note` to get the current body, then specify the exact substrings to replace. Edits are applied in order, each against the result of the previous one, and the note is only saved if all of them succeed.',
346
375
  inputSchema: {
347
376
  _id: zod_1.z
348
377
  .string()
@@ -353,45 +382,36 @@ server.registerTool('patch-note', {
353
382
  _rev: zod_1.z
354
383
  .string()
355
384
  .describe('This is a CouchDB specific field. The current MVCC-token/revision of this document (mandatory and immutable).'),
356
- old_string: zod_1.z
357
- .string()
385
+ edits: zod_1.z
386
+ .array(zod_1.z.object({
387
+ old_string: zod_1.z
388
+ .string()
389
+ .min(1)
390
+ .describe('The exact text to find in the note body. Must match exactly one occurrence. Include enough surrounding context to ensure a unique match.'),
391
+ new_string: zod_1.z
392
+ .string()
393
+ .describe('The text to replace `old_string` with. Use an empty string to delete the matched text.')
394
+ }))
358
395
  .min(1)
359
- .describe('The exact text to find in the note body. Must match exactly one occurrence. Include enough surrounding context to ensure a unique match.'),
360
- new_string: zod_1.z
361
- .string()
362
- .describe('The text to replace `old_string` with. Use an empty string to delete the matched text.')
396
+ .describe('The replacements to perform, applied in order.')
363
397
  }
364
- }, async ({ _id, _rev, old_string, new_string }) => {
398
+ }, async ({ _id, _rev, edits }) => {
365
399
  const existingNote = await (0, api_1.fetchJSON)(`/${_id}`, { rev: _rev });
366
- const body = existingNote.body;
367
- const firstIndex = body.indexOf(old_string);
368
- if (firstIndex === -1) {
369
- return {
370
- content: [
371
- {
372
- type: 'text',
373
- text: 'Failed to patch: `old_string` was not found in the note body.'
374
- }
375
- ],
376
- isError: true
377
- };
378
- }
379
- const secondIndex = body.indexOf(old_string, firstIndex + 1);
380
- if (secondIndex !== -1) {
400
+ const patchResult = (0, utils_1.applyTextEdits)(existingNote.body, edits);
401
+ if (!patchResult.ok) {
381
402
  return {
382
403
  content: [
383
404
  {
384
405
  type: 'text',
385
- text: 'Failed to patch: `old_string` matches multiple locations in the note body. Provide more surrounding context to make it unique.'
406
+ text: `Failed to patch: ${patchResult.error} No edits were saved.`
386
407
  }
387
408
  ],
388
409
  isError: true
389
410
  };
390
411
  }
391
- const patched = body.slice(0, firstIndex) + new_string + body.slice(firstIndex + old_string.length);
392
412
  const res = await (0, api_1.postJSON)('/notes', {
393
413
  ...existingNote,
394
- body: patched,
414
+ body: patchResult.text,
395
415
  updatedAt: +new Date()
396
416
  });
397
417
  return {
package/dist/utils.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getNoteUri = getNoteUri;
4
4
  exports.getFileUri = getFileUri;
5
5
  exports.inferImageContentType = inferImageContentType;
6
+ exports.applyTextEdits = applyTextEdits;
6
7
  exports.isViewableImageType = isViewableImageType;
7
8
  const node_path_1 = require("node:path");
8
9
  const inkdrop_model_1 = require("inkdrop-model");
@@ -45,6 +46,42 @@ function inferImageContentType(filePath) {
45
46
  const ext = (0, node_path_1.extname)(filePath).toLowerCase().replace(/^\./, '');
46
47
  return inkdrop_model_1.SUPPORTED_IMAGE_MIME_TYPES[ext === 'svg' ? 'svg+xml' : ext];
47
48
  }
49
+ /**
50
+ * Applies exact string replacements in order, each against the result of the
51
+ * previous one, so a later edit can match text an earlier edit produced.
52
+ *
53
+ * Every `old_string` must match exactly one location at the time it is applied.
54
+ * Processing stops at the first edit that does not, so callers never see a
55
+ * partially patched text.
56
+ *
57
+ * @param text - The text to patch
58
+ * @param edits - The replacements to perform
59
+ * @returns The patched text, or an error naming the 1-based position of the failing edit
60
+ */
61
+ function applyTextEdits(text, edits) {
62
+ let patchedText = text;
63
+ for (const [editIndex, { old_string, new_string }] of edits.entries()) {
64
+ const editLabel = `edit ${editIndex + 1} of ${edits.length}`;
65
+ const firstMatchIndex = patchedText.indexOf(old_string);
66
+ if (firstMatchIndex === -1) {
67
+ return {
68
+ ok: false,
69
+ error: `\`old_string\` of ${editLabel} was not found in the note body.`
70
+ };
71
+ }
72
+ if (patchedText.indexOf(old_string, firstMatchIndex + 1) !== -1) {
73
+ return {
74
+ ok: false,
75
+ error: `\`old_string\` of ${editLabel} matches multiple locations in the note body. Provide more surrounding context to make it unique.`
76
+ };
77
+ }
78
+ patchedText =
79
+ patchedText.slice(0, firstMatchIndex) +
80
+ new_string +
81
+ patchedText.slice(firstMatchIndex + old_string.length);
82
+ }
83
+ return { ok: true, text: patchedText };
84
+ }
48
85
  /**
49
86
  * Content types the MCP `image` content block can carry. Inkdrop also accepts
50
87
  * SVG and HEIC/HEIF attachments, which have to be written to disk instead.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkdropapp/mcp-server",
3
- "version": "1.5.0",
3
+ "version": "1.7.0",
4
4
  "description": "Inkdrop Model Context Protocol Server",
5
5
  "bin": {
6
6
  "inkdrop-mcp-server": "dist/index.js"
@@ -26,14 +26,14 @@
26
26
  "author": "Takuya Matsuyama<contact@inkdrop.app>",
27
27
  "license": "Apache-2.0",
28
28
  "dependencies": {
29
- "@modelcontextprotocol/sdk": "^1.30.0",
29
+ "@modelcontextprotocol/sdk": "^1.32.2",
30
30
  "ajv": "^8.20.0",
31
- "inkdrop-model": "^2.13.1",
32
- "zod": "^4.5.4"
31
+ "inkdrop-model": "^3.0.1",
32
+ "zod": "^4.6.7"
33
33
  },
34
34
  "devDependencies": {
35
- "@types/node": "^26.4.1",
36
- "oxfmt": "^0.66.0",
35
+ "@types/node": "^26.6.6",
36
+ "oxfmt": "^0.76.0",
37
37
  "typescript": "^7.0.2"
38
38
  }
39
39
  }
package/src/index.ts CHANGED
@@ -18,7 +18,13 @@ import {
18
18
  import { z } from 'zod'
19
19
 
20
20
  import { fetchJSON, postJSON } from './api'
21
- import { getFileUri, getNoteUri, inferImageContentType, isViewableImageType } from './utils'
21
+ import {
22
+ applyTextEdits,
23
+ getFileUri,
24
+ getNoteUri,
25
+ inferImageContentType,
26
+ isViewableImageType
27
+ } from './utils'
22
28
 
23
29
  const server = new McpServer({
24
30
  name: 'Inkdrop',
@@ -167,10 +173,10 @@ You can use special qualifiers to get more accurate results. See the qualifiers
167
173
  - **book**
168
174
  \`book:Blog\`: Searches for notes in the 'Blog' notebook.
169
175
  \`book:"Desktop App"\`: Searches for notes in the 'Desktop App' notebook.
170
- - **bookId**
171
- \`bookId:kGlLniaV\`: Searches for notes in the notebook ID 'book:kGlLniaV'.
176
+ \`book:kGlLniaV\`: Searches for notes in the notebook with the ID 'book:kGlLniaV'.
172
177
  - **tag**
173
178
  \`tag:JavaScript\`: Searches for all notes having the 'JavaScript' tag. Read more about [tags](https://docs.inkdrop.app/manual/write-notes#tag-notes).
179
+ \`tag:pQ7xYt2R\`: Searches for all notes having the tag with the ID 'tag:pQ7xYt2R'.
174
180
  - **status**
175
181
  \`status:onHold\`: Searches for all notes with the 'On hold' status. Read more about [statuses](/reference/note-statuses).
176
182
  - **title**
@@ -257,7 +263,7 @@ You have to retrieve the full note content by calling \`read-note\`.
257
263
  .string()
258
264
  .optional()
259
265
  .describe(
260
- `ID of the notebook. It always starts with 'book:'. You can retrieve a list of notebooks with \`list-notebooks\``
266
+ `ID of the notebook. It always starts with 'book:'. You can retrieve a list of notebooks with \`list-notebooks\`. The pseudo-notebooks 'trash' and 'template' are not supported here; use \`list-templates\` for templates`
261
267
  ),
262
268
  tagIds: z
263
269
  .array(z.string())
@@ -281,8 +287,8 @@ You have to retrieve the full note content by calling \`read-note\`.
281
287
  }
282
288
  },
283
289
  async ({ bookId, tagIds, keyword, sort, descending, limit }) => {
284
- const bookFilter = bookId ? `bookId:${bookId.split(':')[1]}` : ''
285
- const tagFilter = tagIds ? tagIds.map(t => `tagId:${t}`).join(' ') : ''
290
+ const bookFilter = bookId ?? ''
291
+ const tagFilter = tagIds?.join(' ') ?? ''
286
292
  keyword = `${bookFilter} ${tagFilter} ${keyword || ''}`.trim()
287
293
  const notes: Note[] = await fetchJSON('/notes', {
288
294
  keyword,
@@ -307,6 +313,42 @@ You have to retrieve the full note content by calling \`read-note\`.
307
313
  }
308
314
  )
309
315
 
316
+ server.registerTool(
317
+ 'list-templates',
318
+ {
319
+ description: `List note templates: your custom templates, followed by the official ones bundled with Inkdrop.
320
+ Templates are notes whose \`bookId\` is \`template\`. Official templates are read-only.
321
+ The result does not include entire template bodies as they are truncated in 200 characters.
322
+ You have to retrieve the full template content by calling \`read-note\`.
323
+ `,
324
+ inputSchema: {
325
+ keyword: z
326
+ .string()
327
+ .optional()
328
+ .describe(
329
+ 'Filter templates by fuzzy-matching their titles. Search qualifiers such as `book:` or `tag:` are not supported.'
330
+ )
331
+ }
332
+ },
333
+ async ({ keyword }) => {
334
+ const templates: Note[] = await fetchJSON('/templates', { keyword })
335
+ const summaries = templates.map(template => {
336
+ return {
337
+ ...template,
338
+ body: template.body.substring(0, 200)
339
+ }
340
+ })
341
+ return {
342
+ content: [
343
+ {
344
+ type: 'text',
345
+ text: JSON.stringify(summaries, null, 2)
346
+ }
347
+ ]
348
+ }
349
+ }
350
+ )
351
+
310
352
  server.registerTool(
311
353
  'create-note',
312
354
  {
@@ -316,8 +358,8 @@ server.registerTool(
316
358
  .string()
317
359
  .min(5)
318
360
  .max(128)
319
- .regex(/^(book:|trash$)/)
320
- .describe('The notebook ID'),
361
+ .regex(/^(book:|trash$|template$)/)
362
+ .describe('The notebook ID. Specify `template` to create a custom note template'),
321
363
 
322
364
  title: z.string().max(128).describe('The note title'),
323
365
 
@@ -374,9 +416,11 @@ server.registerTool(
374
416
  .string()
375
417
  .min(5)
376
418
  .max(128)
377
- .regex(/^(book:|trash$)/)
419
+ .regex(/^(book:|trash$|template$)/)
378
420
  .optional()
379
- .describe('The notebook ID'),
421
+ .describe(
422
+ 'The notebook ID. Specify `template` to turn the note into a custom note template'
423
+ ),
380
424
 
381
425
  title: z.string().max(128).optional().describe('The note title'),
382
426
 
@@ -425,7 +469,7 @@ server.registerTool(
425
469
  'patch-note',
426
470
  {
427
471
  description:
428
- 'Update the body of the existing note by performing an exact string replacement. Use this tool to make partial updates to the note body without replacing the entire content. You must first read the note with `read-note` to get the current body, then specify the exact substring to replace.',
472
+ 'Update the body of the existing note by performing one or more exact string replacements. Use this tool to make partial updates to the note body without replacing the entire content. You must first read the note with `read-note` to get the current body, then specify the exact substrings to replace. Edits are applied in order, each against the result of the previous one, and the note is only saved if all of them succeed.',
429
473
  inputSchema: {
430
474
  _id: z
431
475
  .string()
@@ -442,56 +486,46 @@ server.registerTool(
442
486
  'This is a CouchDB specific field. The current MVCC-token/revision of this document (mandatory and immutable).'
443
487
  ),
444
488
 
445
- old_string: z
446
- .string()
447
- .min(1)
448
- .describe(
449
- 'The exact text to find in the note body. Must match exactly one occurrence. Include enough surrounding context to ensure a unique match.'
450
- ),
451
-
452
- new_string: z
453
- .string()
454
- .describe(
455
- 'The text to replace `old_string` with. Use an empty string to delete the matched text.'
489
+ edits: z
490
+ .array(
491
+ z.object({
492
+ old_string: z
493
+ .string()
494
+ .min(1)
495
+ .describe(
496
+ 'The exact text to find in the note body. Must match exactly one occurrence. Include enough surrounding context to ensure a unique match.'
497
+ ),
498
+
499
+ new_string: z
500
+ .string()
501
+ .describe(
502
+ 'The text to replace `old_string` with. Use an empty string to delete the matched text.'
503
+ )
504
+ })
456
505
  )
506
+ .min(1)
507
+ .describe('The replacements to perform, applied in order.')
457
508
  }
458
509
  },
459
- async ({ _id, _rev, old_string, new_string }) => {
510
+ async ({ _id, _rev, edits }) => {
460
511
  const existingNote = await fetchJSON<Note>(`/${_id}`, { rev: _rev })
461
- const body = existingNote.body
462
512
 
463
- const firstIndex = body.indexOf(old_string)
464
- if (firstIndex === -1) {
513
+ const patchResult = applyTextEdits(existingNote.body, edits)
514
+ if (!patchResult.ok) {
465
515
  return {
466
516
  content: [
467
517
  {
468
518
  type: 'text',
469
- text: 'Failed to patch: `old_string` was not found in the note body.'
519
+ text: `Failed to patch: ${patchResult.error} No edits were saved.`
470
520
  }
471
521
  ],
472
522
  isError: true
473
523
  }
474
524
  }
475
525
 
476
- const secondIndex = body.indexOf(old_string, firstIndex + 1)
477
- if (secondIndex !== -1) {
478
- return {
479
- content: [
480
- {
481
- type: 'text',
482
- text: 'Failed to patch: `old_string` matches multiple locations in the note body. Provide more surrounding context to make it unique.'
483
- }
484
- ],
485
- isError: true
486
- }
487
- }
488
-
489
- const patched =
490
- body.slice(0, firstIndex) + new_string + body.slice(firstIndex + old_string.length)
491
-
492
526
  const res = await postJSON('/notes', {
493
527
  ...existingNote,
494
- body: patched,
528
+ body: patchResult.text,
495
529
  updatedAt: +new Date()
496
530
  })
497
531
  return {
package/src/utils.ts CHANGED
@@ -44,6 +44,55 @@ export function inferImageContentType(filePath: string): ImageFileType | undefin
44
44
  return SUPPORTED_IMAGE_MIME_TYPES[ext === 'svg' ? 'svg+xml' : ext]
45
45
  }
46
46
 
47
+ export type TextEdit = {
48
+ old_string: string
49
+ new_string: string
50
+ }
51
+
52
+ export type ApplyTextEditsResult = { ok: true; text: string } | { ok: false; error: string }
53
+
54
+ /**
55
+ * Applies exact string replacements in order, each against the result of the
56
+ * previous one, so a later edit can match text an earlier edit produced.
57
+ *
58
+ * Every `old_string` must match exactly one location at the time it is applied.
59
+ * Processing stops at the first edit that does not, so callers never see a
60
+ * partially patched text.
61
+ *
62
+ * @param text - The text to patch
63
+ * @param edits - The replacements to perform
64
+ * @returns The patched text, or an error naming the 1-based position of the failing edit
65
+ */
66
+ export function applyTextEdits(text: string, edits: TextEdit[]): ApplyTextEditsResult {
67
+ let patchedText = text
68
+
69
+ for (const [editIndex, { old_string, new_string }] of edits.entries()) {
70
+ const editLabel = `edit ${editIndex + 1} of ${edits.length}`
71
+
72
+ const firstMatchIndex = patchedText.indexOf(old_string)
73
+ if (firstMatchIndex === -1) {
74
+ return {
75
+ ok: false,
76
+ error: `\`old_string\` of ${editLabel} was not found in the note body.`
77
+ }
78
+ }
79
+
80
+ if (patchedText.indexOf(old_string, firstMatchIndex + 1) !== -1) {
81
+ return {
82
+ ok: false,
83
+ error: `\`old_string\` of ${editLabel} matches multiple locations in the note body. Provide more surrounding context to make it unique.`
84
+ }
85
+ }
86
+
87
+ patchedText =
88
+ patchedText.slice(0, firstMatchIndex) +
89
+ new_string +
90
+ patchedText.slice(firstMatchIndex + old_string.length)
91
+ }
92
+
93
+ return { ok: true, text: patchedText }
94
+ }
95
+
47
96
  /**
48
97
  * Content types the MCP `image` content block can carry. Inkdrop also accepts
49
98
  * SVG and HEIC/HEIF attachments, which have to be written to disk instead.
@@ -1,77 +0,0 @@
1
- name: Claude Code Review
2
-
3
- on:
4
- pull_request:
5
- types: [opened, synchronize]
6
- # Optional: Only run on specific file changes
7
- # paths:
8
- # - "src/**/*.ts"
9
- # - "src/**/*.tsx"
10
- # - "src/**/*.js"
11
- # - "src/**/*.jsx"
12
-
13
- jobs:
14
- claude-review:
15
- # Optional: Filter by PR author
16
- # if: |
17
- # github.event.pull_request.user.login == 'external-contributor' ||
18
- # github.event.pull_request.user.login == 'new-developer' ||
19
- # github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR'
20
-
21
- runs-on: ubuntu-latest
22
- permissions:
23
- contents: read
24
- pull-requests: read
25
- issues: read
26
- id-token: write
27
-
28
- steps:
29
- - name: Checkout repository
30
- uses: actions/checkout@v4
31
- with:
32
- fetch-depth: 1
33
-
34
- - name: Run Claude Code Review
35
- id: claude-review
36
- uses: anthropics/claude-code-action@beta
37
- with:
38
- claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
39
-
40
- # Optional: Specify model (defaults to Claude Sonnet 4, uncomment for Claude Opus 4)
41
- # model: "claude-opus-4-20250514"
42
-
43
- # Direct prompt for automated review (no @claude mention needed)
44
- direct_prompt: |
45
- Please review this pull request and provide feedback on:
46
- - Code quality and best practices
47
- - Potential bugs or issues
48
- - Performance considerations
49
- - Security concerns
50
- - Test coverage
51
-
52
- Be constructive and helpful in your feedback.
53
-
54
- # Optional: Use sticky comments to make Claude reuse the same comment on subsequent pushes to the same PR
55
- # use_sticky_comment: true
56
-
57
- # Optional: Customize review based on file types
58
- # direct_prompt: |
59
- # Review this PR focusing on:
60
- # - For TypeScript files: Type safety and proper interface usage
61
- # - For API endpoints: Security, input validation, and error handling
62
- # - For React components: Performance, accessibility, and best practices
63
- # - For tests: Coverage, edge cases, and test quality
64
-
65
- # Optional: Different prompts for different authors
66
- # direct_prompt: |
67
- # ${{ github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' &&
68
- # 'Welcome! Please review this PR from a first-time contributor. Be encouraging and provide detailed explanations for any suggestions.' ||
69
- # 'Please provide a thorough code review focusing on our coding standards and best practices.' }}
70
-
71
- # Optional: Add specific tools for running tests or linting
72
- # allowed_tools: "Bash(npm run test),Bash(npm run lint),Bash(npm run typecheck)"
73
-
74
- # Optional: Skip review for certain conditions
75
- # if: |
76
- # !contains(github.event.pull_request.title, '[skip-review]') &&
77
- # !contains(github.event.pull_request.title, '[WIP]')
@@ -1,63 +0,0 @@
1
- name: Claude Code
2
-
3
- on:
4
- issue_comment:
5
- types: [created]
6
- pull_request_review_comment:
7
- types: [created]
8
- issues:
9
- types: [opened, assigned]
10
- pull_request_review:
11
- types: [submitted]
12
-
13
- jobs:
14
- claude:
15
- if: |
16
- (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
17
- (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
18
- (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
19
- (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
20
- runs-on: ubuntu-latest
21
- permissions:
22
- contents: read
23
- pull-requests: read
24
- issues: read
25
- id-token: write
26
- actions: read # Required for Claude to read CI results on PRs
27
- steps:
28
- - name: Checkout repository
29
- uses: actions/checkout@v4
30
- with:
31
- fetch-depth: 1
32
-
33
- - name: Run Claude Code
34
- id: claude
35
- uses: anthropics/claude-code-action@beta
36
- with:
37
- claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
38
-
39
- # This is an optional setting that allows Claude to read CI results on PRs
40
- additional_permissions: |
41
- actions: read
42
-
43
- # Optional: Specify model (defaults to Claude Sonnet 4, uncomment for Claude Opus 4)
44
- # model: "claude-opus-4-20250514"
45
-
46
- # Optional: Customize the trigger phrase (default: @claude)
47
- # trigger_phrase: "/claude"
48
-
49
- # Optional: Trigger when specific user is assigned to an issue
50
- # assignee_trigger: "claude-bot"
51
-
52
- # Optional: Allow Claude to run specific commands
53
- # allowed_tools: "Bash(npm install),Bash(npm run build),Bash(npm run test:*),Bash(npm run lint:*)"
54
-
55
- # Optional: Add custom instructions for Claude to customize its behavior for your project
56
- # custom_instructions: |
57
- # Follow our coding standards
58
- # Ensure all new code has tests
59
- # Use TypeScript for new files
60
-
61
- # Optional: Custom environment variables for Claude
62
- # claude_env: |
63
- # NODE_ENV: test