@inkdropapp/mcp-server 1.3.0 → 1.3.1

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
@@ -69,11 +69,12 @@ A [Model Context Protocol](https://github.com/modelcontextprotocol) server for t
69
69
  - `body`: The content of the note in Markdown.
70
70
  - `status`: The note status (`none`, `active`, `onHold`, `completed`, `dropped`).
71
71
  - `tags`: An array of tag IDs to assign to the note. Each must start with 'tag:'.
72
- 6. **`patch-note`**: Update the body of an existing note by applying a unified diff patch. More efficient than `update-note` for small edits to large notes as it saves tokens.
72
+ 6. **`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.
73
73
  - Required inputs:
74
74
  - `_id`: The note ID. Must start with 'note:'.
75
75
  - `_rev`: The revision ID (CouchDB MVCC-token).
76
- - `patch`: A unified diff string to apply to the note body. Use standard unified diff format with `---`/`+++` headers and `@@ -start,count +start,count @@` hunk markers.
76
+ - `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.
77
+ - `new_string`: The text to replace `old_string` with. Use an empty string to delete the matched text.
77
78
  7. **`list-notebooks`**: Retrieve a list of all notebooks.
78
79
  8. **`read-book`**: Retrieve a single notebook by its ID.
79
80
  - Required inputs:
package/dist/index.js CHANGED
@@ -5,7 +5,6 @@ const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
5
5
  const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
6
6
  const inkdrop_model_1 = require("inkdrop-model");
7
7
  const zod_1 = require("zod");
8
- const diff_1 = require("diff");
9
8
  const api_1 = require("./api");
10
9
  const server = new mcp_js_1.McpServer({
11
10
  name: 'Inkdrop',
@@ -159,9 +158,14 @@ You have to retrieve the full note content by calling \`read-note\`.
159
158
  .boolean()
160
159
  .optional()
161
160
  .default(true)
162
- .describe(`Reverse the order of the output documents`)
161
+ .describe(`Reverse the order of the output documents`),
162
+ limit: zod_1.z
163
+ .number()
164
+ .optional()
165
+ .default(100)
166
+ .describe(`Limit the number of results returned`)
163
167
  }
164
- }, async ({ bookId, tagIds, keyword, sort, descending }) => {
168
+ }, async ({ bookId, tagIds, keyword, sort, descending, limit }) => {
165
169
  const bookFilter = bookId ? `bookId:${bookId.split(':')[1]}` : '';
166
170
  const tagFilter = tagIds ? tagIds.map(t => `tagId:${t}`).join(' ') : '';
167
171
  keyword = `${bookFilter} ${tagFilter} ${keyword || ''}`.trim();
@@ -169,7 +173,7 @@ You have to retrieve the full note content by calling \`read-note\`.
169
173
  keyword,
170
174
  sort,
171
175
  descending,
172
- limit: 100
176
+ limit
173
177
  });
174
178
  const summaries = notes.map(note => {
175
179
  return {
@@ -259,7 +263,8 @@ server.registerTool('update-note', {
259
263
  const existingNote = await (0, api_1.fetchJSON)(`/${noteData._id}`, { rev });
260
264
  const res = await (0, api_1.postJSON)(`/notes`, {
261
265
  ...existingNote,
262
- ...noteData
266
+ ...noteData,
267
+ updatedAt: +new Date()
263
268
  });
264
269
  return {
265
270
  content: [
@@ -271,7 +276,7 @@ server.registerTool('update-note', {
271
276
  };
272
277
  });
273
278
  server.registerTool('patch-note', {
274
- description: 'Update the body of the existing note by applying a diff patch in the database. You should use this tool when you want to make partial updates to the note body without replacing the entire content because it is much more efficient for saving token window.',
279
+ 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.',
275
280
  inputSchema: {
276
281
  _id: zod_1.z
277
282
  .string()
@@ -282,25 +287,49 @@ server.registerTool('patch-note', {
282
287
  _rev: zod_1.z
283
288
  .string()
284
289
  .describe('This is a CouchDB specific field. The current MVCC-token/revision of this document (mandatory and immutable).'),
285
- patch: zod_1.z
290
+ old_string: zod_1.z
291
+ .string()
292
+ .min(1)
293
+ .describe('The exact text to find in the note body. Must match exactly one occurrence. Include enough surrounding context to ensure a unique match.'),
294
+ new_string: zod_1.z
286
295
  .string()
287
- .describe('A unified diff string to apply to the note body. Use standard unified diff format with `---`/`+++` headers and `@@ -start,count +start,count @@` hunk markers.')
296
+ .describe('The text to replace `old_string` with. Use an empty string to delete the matched text.')
288
297
  }
289
- }, async ({ _id, _rev, patch }) => {
298
+ }, async ({ _id, _rev, old_string, new_string }) => {
290
299
  const existingNote = await (0, api_1.fetchJSON)(`/${_id}`, { rev: _rev });
291
- const patched = (0, diff_1.applyPatch)(existingNote.body, patch);
292
- if (patched === false) {
300
+ const body = existingNote.body;
301
+ const firstIndex = body.indexOf(old_string);
302
+ if (firstIndex === -1) {
293
303
  return {
294
304
  content: [
295
305
  {
296
306
  type: 'text',
297
- text: 'Failed to apply the patch. The diff may be malformed or does not match the current note body.'
307
+ text: 'Failed to patch: `old_string` was not found in the note body.'
298
308
  }
299
309
  ],
300
310
  isError: true
301
311
  };
302
312
  }
303
- const res = await (0, api_1.postJSON)('/notes', { ...existingNote, body: patched });
313
+ const secondIndex = body.indexOf(old_string, firstIndex + 1);
314
+ if (secondIndex !== -1) {
315
+ return {
316
+ content: [
317
+ {
318
+ type: 'text',
319
+ text: 'Failed to patch: `old_string` matches multiple locations in the note body. Provide more surrounding context to make it unique.'
320
+ }
321
+ ],
322
+ isError: true
323
+ };
324
+ }
325
+ const patched = body.slice(0, firstIndex) +
326
+ new_string +
327
+ body.slice(firstIndex + old_string.length);
328
+ const res = await (0, api_1.postJSON)('/notes', {
329
+ ...existingNote,
330
+ body: patched,
331
+ updatedAt: +new Date()
332
+ });
304
333
  return {
305
334
  content: [
306
335
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkdropapp/mcp-server",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Inkdrop Model Context Protocol Server",
5
5
  "bin": {
6
6
  "inkdrop-mcp-server": "dist/index.js"
@@ -26,7 +26,6 @@
26
26
  "dependencies": {
27
27
  "@modelcontextprotocol/sdk": "^1.26.0",
28
28
  "ajv": "^8.17.1",
29
- "diff": "^8.0.3",
30
29
  "inkdrop-model": "^2.11.1",
31
30
  "zod": "^4.3.6"
32
31
  },
package/src/index.ts CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  Tag
16
16
  } from 'inkdrop-model'
17
17
  import { z } from 'zod'
18
- import { applyPatch } from 'diff'
18
+
19
19
  import { fetchJSON, postJSON } from './api'
20
20
 
21
21
  const server = new McpServer({
@@ -195,10 +195,15 @@ You have to retrieve the full note content by calling \`read-note\`.
195
195
  .boolean()
196
196
  .optional()
197
197
  .default(true)
198
- .describe(`Reverse the order of the output documents`)
198
+ .describe(`Reverse the order of the output documents`),
199
+ limit: z
200
+ .number()
201
+ .optional()
202
+ .default(100)
203
+ .describe(`Limit the number of results returned`)
199
204
  }
200
205
  },
201
- async ({ bookId, tagIds, keyword, sort, descending }) => {
206
+ async ({ bookId, tagIds, keyword, sort, descending, limit }) => {
202
207
  const bookFilter = bookId ? `bookId:${bookId.split(':')[1]}` : ''
203
208
  const tagFilter = tagIds ? tagIds.map(t => `tagId:${t}`).join(' ') : ''
204
209
  keyword = `${bookFilter} ${tagFilter} ${keyword || ''}`.trim()
@@ -206,7 +211,7 @@ You have to retrieve the full note content by calling \`read-note\`.
206
211
  keyword,
207
212
  sort,
208
213
  descending,
209
- limit: 100
214
+ limit
210
215
  })
211
216
  const summaries = notes.map(note => {
212
217
  return {
@@ -328,7 +333,8 @@ server.registerTool(
328
333
 
329
334
  const res = await postJSON(`/notes`, {
330
335
  ...existingNote,
331
- ...noteData
336
+ ...noteData,
337
+ updatedAt: +new Date()
332
338
  })
333
339
  return {
334
340
  content: [
@@ -345,7 +351,7 @@ server.registerTool(
345
351
  'patch-note',
346
352
  {
347
353
  description:
348
- 'Update the body of the existing note by applying a diff patch in the database. You should use this tool when you want to make partial updates to the note body without replacing the entire content because it is much more efficient for saving token window.',
354
+ '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.',
349
355
  inputSchema: {
350
356
  _id: z
351
357
  .string()
@@ -362,28 +368,60 @@ server.registerTool(
362
368
  'This is a CouchDB specific field. The current MVCC-token/revision of this document (mandatory and immutable).'
363
369
  ),
364
370
 
365
- patch: z
371
+ old_string: z
372
+ .string()
373
+ .min(1)
374
+ .describe(
375
+ 'The exact text to find in the note body. Must match exactly one occurrence. Include enough surrounding context to ensure a unique match.'
376
+ ),
377
+
378
+ new_string: z
366
379
  .string()
367
380
  .describe(
368
- 'A unified diff string to apply to the note body. Use standard unified diff format with `---`/`+++` headers and `@@ -start,count +start,count @@` hunk markers.'
381
+ 'The text to replace `old_string` with. Use an empty string to delete the matched text.'
369
382
  )
370
383
  }
371
384
  },
372
- async ({ _id, _rev, patch }) => {
385
+ async ({ _id, _rev, old_string, new_string }) => {
373
386
  const existingNote = await fetchJSON<Note>(`/${_id}`, { rev: _rev })
374
- const patched = applyPatch(existingNote.body, patch)
375
- if (patched === false) {
387
+ const body = existingNote.body
388
+
389
+ const firstIndex = body.indexOf(old_string)
390
+ if (firstIndex === -1) {
376
391
  return {
377
392
  content: [
378
393
  {
379
394
  type: 'text',
380
- text: 'Failed to apply the patch. The diff may be malformed or does not match the current note body.'
395
+ text: 'Failed to patch: `old_string` was not found in the note body.'
381
396
  }
382
397
  ],
383
398
  isError: true
384
399
  }
385
400
  }
386
- const res = await postJSON('/notes', { ...existingNote, body: patched })
401
+
402
+ const secondIndex = body.indexOf(old_string, firstIndex + 1)
403
+ if (secondIndex !== -1) {
404
+ return {
405
+ content: [
406
+ {
407
+ type: 'text',
408
+ text: 'Failed to patch: `old_string` matches multiple locations in the note body. Provide more surrounding context to make it unique.'
409
+ }
410
+ ],
411
+ isError: true
412
+ }
413
+ }
414
+
415
+ const patched =
416
+ body.slice(0, firstIndex) +
417
+ new_string +
418
+ body.slice(firstIndex + old_string.length)
419
+
420
+ const res = await postJSON('/notes', {
421
+ ...existingNote,
422
+ body: patched,
423
+ updatedAt: +new Date()
424
+ })
387
425
  return {
388
426
  content: [
389
427
  {