@inkdropapp/mcp-server 1.6.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 +1 -1
- package/dist/index.js +21 -30
- package/dist/utils.js +37 -0
- package/package.json +4 -4
- package/src/index.ts +35 -39
- package/src/utils.ts +49 -0
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ Read [the docs here](https://docs.inkdrop.app/reference/mcp-server).
|
|
|
56
56
|
- `body`: The content of the note in Markdown.
|
|
57
57
|
- `status`: The note status (`none`, `active`, `onHold`, `completed`, `dropped`).
|
|
58
58
|
- `tags`: An array of tag IDs to assign to the note. Each must start with 'tag:'.
|
|
59
|
-
8. **`patch-note`**: Update the body of an existing note by performing
|
|
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.
|
|
60
60
|
- Required inputs:
|
|
61
61
|
- `_id`: The note ID. Must start with 'note:'.
|
|
62
62
|
- `_rev`: The revision ID (CouchDB MVCC-token).
|
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
|
-
|
|
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**
|
|
@@ -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
|
|
239
|
-
const tagFilter = tagIds
|
|
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,
|
|
@@ -371,7 +371,7 @@ server.registerTool('update-note', {
|
|
|
371
371
|
};
|
|
372
372
|
});
|
|
373
373
|
server.registerTool('patch-note', {
|
|
374
|
-
description: 'Update the body of the existing note by performing
|
|
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.',
|
|
375
375
|
inputSchema: {
|
|
376
376
|
_id: zod_1.z
|
|
377
377
|
.string()
|
|
@@ -382,45 +382,36 @@ server.registerTool('patch-note', {
|
|
|
382
382
|
_rev: zod_1.z
|
|
383
383
|
.string()
|
|
384
384
|
.describe('This is a CouchDB specific field. The current MVCC-token/revision of this document (mandatory and immutable).'),
|
|
385
|
-
|
|
386
|
-
.
|
|
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
|
+
}))
|
|
387
395
|
.min(1)
|
|
388
|
-
.describe('The
|
|
389
|
-
new_string: zod_1.z
|
|
390
|
-
.string()
|
|
391
|
-
.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.')
|
|
392
397
|
}
|
|
393
|
-
}, async ({ _id, _rev,
|
|
398
|
+
}, async ({ _id, _rev, edits }) => {
|
|
394
399
|
const existingNote = await (0, api_1.fetchJSON)(`/${_id}`, { rev: _rev });
|
|
395
|
-
const
|
|
396
|
-
|
|
397
|
-
if (firstIndex === -1) {
|
|
398
|
-
return {
|
|
399
|
-
content: [
|
|
400
|
-
{
|
|
401
|
-
type: 'text',
|
|
402
|
-
text: 'Failed to patch: `old_string` was not found in the note body.'
|
|
403
|
-
}
|
|
404
|
-
],
|
|
405
|
-
isError: true
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
const secondIndex = body.indexOf(old_string, firstIndex + 1);
|
|
409
|
-
if (secondIndex !== -1) {
|
|
400
|
+
const patchResult = (0, utils_1.applyTextEdits)(existingNote.body, edits);
|
|
401
|
+
if (!patchResult.ok) {
|
|
410
402
|
return {
|
|
411
403
|
content: [
|
|
412
404
|
{
|
|
413
405
|
type: 'text',
|
|
414
|
-
text:
|
|
406
|
+
text: `Failed to patch: ${patchResult.error} No edits were saved.`
|
|
415
407
|
}
|
|
416
408
|
],
|
|
417
409
|
isError: true
|
|
418
410
|
};
|
|
419
411
|
}
|
|
420
|
-
const patched = body.slice(0, firstIndex) + new_string + body.slice(firstIndex + old_string.length);
|
|
421
412
|
const res = await (0, api_1.postJSON)('/notes', {
|
|
422
413
|
...existingNote,
|
|
423
|
-
body:
|
|
414
|
+
body: patchResult.text,
|
|
424
415
|
updatedAt: +new Date()
|
|
425
416
|
});
|
|
426
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.
|
|
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.32.
|
|
29
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
30
30
|
"ajv": "^8.20.0",
|
|
31
31
|
"inkdrop-model": "^3.0.1",
|
|
32
32
|
"zod": "^4.6.7"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@types/node": "^26.6.
|
|
36
|
-
"oxfmt": "^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 {
|
|
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
|
-
|
|
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**
|
|
@@ -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
|
|
285
|
-
const tagFilter = tagIds
|
|
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,
|
|
@@ -463,7 +469,7 @@ server.registerTool(
|
|
|
463
469
|
'patch-note',
|
|
464
470
|
{
|
|
465
471
|
description:
|
|
466
|
-
'Update the body of the existing note by performing
|
|
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.',
|
|
467
473
|
inputSchema: {
|
|
468
474
|
_id: z
|
|
469
475
|
.string()
|
|
@@ -480,56 +486,46 @@ server.registerTool(
|
|
|
480
486
|
'This is a CouchDB specific field. The current MVCC-token/revision of this document (mandatory and immutable).'
|
|
481
487
|
),
|
|
482
488
|
|
|
483
|
-
|
|
484
|
-
.
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
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
|
+
})
|
|
494
505
|
)
|
|
506
|
+
.min(1)
|
|
507
|
+
.describe('The replacements to perform, applied in order.')
|
|
495
508
|
}
|
|
496
509
|
},
|
|
497
|
-
async ({ _id, _rev,
|
|
510
|
+
async ({ _id, _rev, edits }) => {
|
|
498
511
|
const existingNote = await fetchJSON<Note>(`/${_id}`, { rev: _rev })
|
|
499
|
-
const body = existingNote.body
|
|
500
|
-
|
|
501
|
-
const firstIndex = body.indexOf(old_string)
|
|
502
|
-
if (firstIndex === -1) {
|
|
503
|
-
return {
|
|
504
|
-
content: [
|
|
505
|
-
{
|
|
506
|
-
type: 'text',
|
|
507
|
-
text: 'Failed to patch: `old_string` was not found in the note body.'
|
|
508
|
-
}
|
|
509
|
-
],
|
|
510
|
-
isError: true
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
512
|
|
|
514
|
-
const
|
|
515
|
-
if (
|
|
513
|
+
const patchResult = applyTextEdits(existingNote.body, edits)
|
|
514
|
+
if (!patchResult.ok) {
|
|
516
515
|
return {
|
|
517
516
|
content: [
|
|
518
517
|
{
|
|
519
518
|
type: 'text',
|
|
520
|
-
text:
|
|
519
|
+
text: `Failed to patch: ${patchResult.error} No edits were saved.`
|
|
521
520
|
}
|
|
522
521
|
],
|
|
523
522
|
isError: true
|
|
524
523
|
}
|
|
525
524
|
}
|
|
526
525
|
|
|
527
|
-
const patched =
|
|
528
|
-
body.slice(0, firstIndex) + new_string + body.slice(firstIndex + old_string.length)
|
|
529
|
-
|
|
530
526
|
const res = await postJSON('/notes', {
|
|
531
527
|
...existingNote,
|
|
532
|
-
body:
|
|
528
|
+
body: patchResult.text,
|
|
533
529
|
updatedAt: +new Date()
|
|
534
530
|
})
|
|
535
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.
|