@inkdropapp/mcp-server 1.3.1 → 1.5.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/.claude/settings.local.json +1 -3
- package/.github/workflows/claude-code-review.yml +9 -10
- package/.github/workflows/claude.yml +6 -7
- package/.oxfmtrc.json +12 -0
- package/README.md +48 -38
- package/Session.vim +122 -0
- package/dist/api.js +6 -6
- package/dist/index.js +320 -67
- package/dist/utils.js +63 -0
- package/package.json +10 -8
- package/pnpm-workspace.yaml +3 -0
- package/src/api.ts +18 -21
- package/src/index.ts +397 -94
- package/src/utils.ts +63 -0
- package/tsconfig.json +5 -11
- package/prettier.config.js +0 -12
package/dist/index.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const promises_1 = require("node:fs/promises");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
4
7
|
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
5
8
|
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
6
9
|
const inkdrop_model_1 = require("inkdrop-model");
|
|
7
10
|
const zod_1 = require("zod");
|
|
8
11
|
const api_1 = require("./api");
|
|
12
|
+
const utils_1 = require("./utils");
|
|
9
13
|
const server = new mcp_js_1.McpServer({
|
|
10
14
|
name: 'Inkdrop',
|
|
11
15
|
version: '1.3.0'
|
|
@@ -14,7 +18,9 @@ server.registerResource('note', new mcp_js_1.ResourceTemplate('inkdrop://note/{n
|
|
|
14
18
|
description: 'A note data',
|
|
15
19
|
mimeType: 'application/json'
|
|
16
20
|
}, async (uri, { noteId }) => {
|
|
17
|
-
const
|
|
21
|
+
const id = Array.isArray(noteId) ? noteId[0] : noteId;
|
|
22
|
+
const normalizedId = id.startsWith('note:') ? id : `note:${id}`;
|
|
23
|
+
const note = await (0, api_1.fetchJSON)(`/${normalizedId}`, {});
|
|
18
24
|
return {
|
|
19
25
|
contents: [
|
|
20
26
|
{
|
|
@@ -26,25 +32,92 @@ server.registerResource('note', new mcp_js_1.ResourceTemplate('inkdrop://note/{n
|
|
|
26
32
|
};
|
|
27
33
|
});
|
|
28
34
|
server.registerTool('read-note', {
|
|
29
|
-
description: 'Retrieve the complete contents of the note by its ID from the database.'
|
|
35
|
+
description: 'Retrieve the complete contents of the note by its ID from the database. ' +
|
|
36
|
+
'A note created from a template has a `sourceTemplateId`; when present, the response ' +
|
|
37
|
+
'includes a resource link to that source template, whose body holds the fill-out ' +
|
|
38
|
+
'instructions and examples. Read the template (or pass `includeTemplate: true`) before ' +
|
|
39
|
+
'completing the note.',
|
|
30
40
|
inputSchema: {
|
|
31
41
|
noteId: zod_1.z
|
|
32
42
|
.string()
|
|
33
|
-
.describe('ID of the note to retrieve. It can be found as `_id` in the note docs. It always starts with \`note:\`.')
|
|
43
|
+
.describe('ID of the note to retrieve. It can be found as `_id` in the note docs. It always starts with \`note:\`.'),
|
|
44
|
+
includeTemplate: zod_1.z
|
|
45
|
+
.boolean()
|
|
46
|
+
.optional()
|
|
47
|
+
.default(false)
|
|
48
|
+
.describe('When true and the note has a `sourceTemplateId`, also fetch that template and embed its body (the fill-out instructions and examples) as an extra text block, so you get the note and its template in one call.')
|
|
34
49
|
}
|
|
35
|
-
}, async ({ noteId }) => {
|
|
50
|
+
}, async ({ noteId, includeTemplate }) => {
|
|
36
51
|
if (!noteId.startsWith('note:'))
|
|
37
52
|
noteId = `note:${noteId}`;
|
|
38
53
|
const note = await (0, api_1.fetchJSON)(`/${noteId}`, {});
|
|
54
|
+
let templateBlockText = null;
|
|
55
|
+
if (includeTemplate && note.sourceTemplateId) {
|
|
56
|
+
try {
|
|
57
|
+
const template = await (0, api_1.fetchJSON)(`/${note.sourceTemplateId}`, {});
|
|
58
|
+
templateBlockText = `# Source template: ${template.title}\n\n${template.body}`;
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// Template unavailable (e.g. deleted → 404). Skip the embed; the note read still succeeds.
|
|
62
|
+
}
|
|
63
|
+
}
|
|
39
64
|
return {
|
|
40
65
|
content: [
|
|
41
66
|
{
|
|
42
67
|
type: 'text',
|
|
43
68
|
text: JSON.stringify(note, null, 2)
|
|
44
|
-
}
|
|
69
|
+
},
|
|
70
|
+
...(note.sourceTemplateId
|
|
71
|
+
? [
|
|
72
|
+
{
|
|
73
|
+
type: 'resource_link',
|
|
74
|
+
uri: (0, utils_1.getNoteUri)(note.sourceTemplateId),
|
|
75
|
+
name: 'Source template',
|
|
76
|
+
mimeType: 'application/json',
|
|
77
|
+
description: 'The template this note was created from. Read it to get the fill-out instructions and examples before completing this note.'
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
: []),
|
|
81
|
+
...(templateBlockText ? [{ type: 'text', text: templateBlockText }] : [])
|
|
45
82
|
]
|
|
46
83
|
};
|
|
47
84
|
});
|
|
85
|
+
server.registerTool('read-backlinks', {
|
|
86
|
+
description: `Retrieve backlinks for a note — the notes that link to it.
|
|
87
|
+
Each result is returned as a resource link (\`inkdrop://note/<id>\`) pointing to the referring note.
|
|
88
|
+
Backlinks are found by searching all note bodies for the note's link URI.`,
|
|
89
|
+
inputSchema: {
|
|
90
|
+
noteId: zod_1.z
|
|
91
|
+
.string()
|
|
92
|
+
.describe('ID of the note to find backlinks for. It can be found as `_id` in the note docs. It always starts with \`note:\`.')
|
|
93
|
+
}
|
|
94
|
+
}, async ({ noteId }) => {
|
|
95
|
+
if (!noteId.startsWith('note:'))
|
|
96
|
+
noteId = `note:${noteId}`;
|
|
97
|
+
const noteLink = (0, utils_1.getNoteUri)(noteId);
|
|
98
|
+
const backlinks = await (0, api_1.fetchJSON)('/notes', {
|
|
99
|
+
keyword: noteLink,
|
|
100
|
+
limit: 100
|
|
101
|
+
});
|
|
102
|
+
if (backlinks.length === 0) {
|
|
103
|
+
return {
|
|
104
|
+
content: [
|
|
105
|
+
{
|
|
106
|
+
type: 'text',
|
|
107
|
+
text: `No backlinks found for ${noteLink}.`
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
content: backlinks.map(note => ({
|
|
114
|
+
type: 'resource_link',
|
|
115
|
+
uri: (0, utils_1.getNoteUri)(note._id),
|
|
116
|
+
name: note.title || 'Untitled note',
|
|
117
|
+
mimeType: 'application/json'
|
|
118
|
+
}))
|
|
119
|
+
};
|
|
120
|
+
});
|
|
48
121
|
server.registerTool('search-notes', {
|
|
49
122
|
description: `List all notes that contain a given keyword.
|
|
50
123
|
The result does not include entire note bodies as they are truncated in 200 characters.
|
|
@@ -159,11 +232,7 @@ You have to retrieve the full note content by calling \`read-note\`.
|
|
|
159
232
|
.optional()
|
|
160
233
|
.default(true)
|
|
161
234
|
.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`)
|
|
235
|
+
limit: zod_1.z.number().optional().default(100).describe(`Limit the number of results returned`)
|
|
167
236
|
}
|
|
168
237
|
}, async ({ bookId, tagIds, keyword, sort, descending, limit }) => {
|
|
169
238
|
const bookFilter = bookId ? `bookId:${bookId.split(':')[1]}` : '';
|
|
@@ -200,10 +269,7 @@ server.registerTool('create-note', {
|
|
|
200
269
|
.regex(/^(book:|trash$)/)
|
|
201
270
|
.describe('The notebook ID'),
|
|
202
271
|
title: zod_1.z.string().max(128).describe('The note title'),
|
|
203
|
-
body: zod_1.z
|
|
204
|
-
.string()
|
|
205
|
-
.max(1048576)
|
|
206
|
-
.describe('The content of the note represented with Markdown'),
|
|
272
|
+
body: zod_1.z.string().max(1048576).describe('The content of the note represented with Markdown'),
|
|
207
273
|
status: zod_1.z
|
|
208
274
|
.enum(['none', 'active', 'onHold', 'completed', 'dropped'])
|
|
209
275
|
.optional()
|
|
@@ -322,9 +388,7 @@ server.registerTool('patch-note', {
|
|
|
322
388
|
isError: true
|
|
323
389
|
};
|
|
324
390
|
}
|
|
325
|
-
const patched = body.slice(0, firstIndex) +
|
|
326
|
-
new_string +
|
|
327
|
-
body.slice(firstIndex + old_string.length);
|
|
391
|
+
const patched = body.slice(0, firstIndex) + new_string + body.slice(firstIndex + old_string.length);
|
|
328
392
|
const res = await (0, api_1.postJSON)('/notes', {
|
|
329
393
|
...existingNote,
|
|
330
394
|
body: patched,
|
|
@@ -374,10 +438,7 @@ const TagColors = Object.values(inkdrop_model_1.TAG_COLOR);
|
|
|
374
438
|
server.registerTool('create-tag', {
|
|
375
439
|
description: 'Create a new tag in the database',
|
|
376
440
|
inputSchema: {
|
|
377
|
-
color: zod_1.z
|
|
378
|
-
.enum(TagColors)
|
|
379
|
-
.default('default')
|
|
380
|
-
.describe('The color type of the tag'),
|
|
441
|
+
color: zod_1.z.enum(TagColors).default('default').describe('The color type of the tag'),
|
|
381
442
|
name: zod_1.z.string().max(64).describe('The name of the tag')
|
|
382
443
|
}
|
|
383
444
|
}, async (tagData) => {
|
|
@@ -392,7 +453,7 @@ server.registerTool('create-tag', {
|
|
|
392
453
|
};
|
|
393
454
|
});
|
|
394
455
|
server.registerTool('update-tag', {
|
|
395
|
-
description: 'Update the existing tag in the database.
|
|
456
|
+
description: 'Update the existing tag in the database. Only the fields you provide will be updated; omitted fields remain unchanged, so you do not need to read the tag first. Call `list-tags` or `read-tag` to find the tag ID.',
|
|
396
457
|
inputSchema: {
|
|
397
458
|
_id: zod_1.z
|
|
398
459
|
.string()
|
|
@@ -402,15 +463,13 @@ server.registerTool('update-tag', {
|
|
|
402
463
|
.describe('The unique document ID which should start with `tag:` and the remains are randomly generated string'),
|
|
403
464
|
_rev: zod_1.z
|
|
404
465
|
.string()
|
|
405
|
-
.
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
.describe('The color type of the tag'),
|
|
410
|
-
name: zod_1.z.string().max(64).describe('The name of the tag')
|
|
466
|
+
.optional()
|
|
467
|
+
.describe('This is a CouchDB specific field. The current MVCC-token/revision of this document. Optional: the server merges your fields into the stored tag, so it is only needed as an optimistic-concurrency guard. Pass it when you have read the tag first and want the update to fail on a conflicting concurrent edit.'),
|
|
468
|
+
color: zod_1.z.enum(TagColors).optional().describe('The color type of the tag'),
|
|
469
|
+
name: zod_1.z.string().max(64).optional().describe('The name of the tag')
|
|
411
470
|
}
|
|
412
|
-
}, async (
|
|
413
|
-
const res = await (0, api_1.postJSON)(
|
|
471
|
+
}, async ({ _id, ...updateFields }) => {
|
|
472
|
+
const res = await (0, api_1.postJSON)(`/${_id}`, updateFields);
|
|
414
473
|
return {
|
|
415
474
|
content: [
|
|
416
475
|
{
|
|
@@ -451,46 +510,240 @@ server.registerTool('read-book', {
|
|
|
451
510
|
]
|
|
452
511
|
};
|
|
453
512
|
});
|
|
454
|
-
server.
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
513
|
+
server.registerTool('create-book', {
|
|
514
|
+
description: 'Create a new notebook in the database. To create a nested notebook, pass the parent notebook ID as `parentBookId`. Call `list-notebooks` first to find it.',
|
|
515
|
+
inputSchema: {
|
|
516
|
+
name: zod_1.z.string().min(1).max(64).describe('The notebook name'),
|
|
517
|
+
parentBookId: zod_1.z
|
|
518
|
+
.string()
|
|
519
|
+
.min(6)
|
|
520
|
+
.max(128)
|
|
521
|
+
.regex(/^book:/)
|
|
522
|
+
.optional()
|
|
523
|
+
.describe('The ID of the parent notebook. Omit it to create the notebook at the root level.')
|
|
524
|
+
}
|
|
525
|
+
}, async (bookData) => {
|
|
526
|
+
const res = await (0, api_1.postJSON)(`/books`, bookData);
|
|
527
|
+
return {
|
|
528
|
+
content: [
|
|
529
|
+
{
|
|
459
530
|
type: 'text',
|
|
460
|
-
text:
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
531
|
+
text: JSON.stringify(res, null, 2)
|
|
532
|
+
}
|
|
533
|
+
]
|
|
534
|
+
};
|
|
535
|
+
});
|
|
536
|
+
server.registerTool('update-book', {
|
|
537
|
+
description: 'Update the existing notebook in the database. Only the fields you provide will be updated; omitted fields remain unchanged, so you do not need to read the notebook first. Call `list-notebooks` or `read-book` to find the notebook ID.',
|
|
538
|
+
inputSchema: {
|
|
539
|
+
_id: zod_1.z
|
|
540
|
+
.string()
|
|
541
|
+
.min(6)
|
|
542
|
+
.max(128)
|
|
543
|
+
.regex(/^book:/)
|
|
544
|
+
.describe('The unique document ID which should start with `book:` and the remains are randomly generated string'),
|
|
545
|
+
_rev: zod_1.z
|
|
546
|
+
.string()
|
|
547
|
+
.optional()
|
|
548
|
+
.describe('This is a CouchDB specific field. The current MVCC-token/revision of this document. Optional: the server merges your fields into the stored notebook, so it is only needed as an optimistic-concurrency guard. Pass it when you have read the notebook first and want the update to fail on a conflicting concurrent edit.'),
|
|
549
|
+
name: zod_1.z.string().min(1).max(64).optional().describe('The notebook name'),
|
|
550
|
+
parentBookId: zod_1.z
|
|
551
|
+
.string()
|
|
552
|
+
.min(6)
|
|
553
|
+
.max(128)
|
|
554
|
+
.regex(/^book:/)
|
|
555
|
+
.nullable()
|
|
556
|
+
.optional()
|
|
557
|
+
.describe('The ID of the parent notebook. Pass `null` to move the notebook to the root level.')
|
|
558
|
+
}
|
|
559
|
+
}, async ({ _id, ...updateFields }) => {
|
|
560
|
+
const res = await (0, api_1.postJSON)(`/${_id}`, {
|
|
561
|
+
...updateFields,
|
|
562
|
+
updatedAt: +new Date()
|
|
563
|
+
});
|
|
564
|
+
return {
|
|
565
|
+
content: [
|
|
566
|
+
{
|
|
567
|
+
type: 'text',
|
|
568
|
+
text: JSON.stringify(res, null, 2)
|
|
569
|
+
}
|
|
570
|
+
]
|
|
571
|
+
};
|
|
572
|
+
});
|
|
573
|
+
const ImageFileTypes = [...inkdrop_model_1.supportedImageFileTypes];
|
|
574
|
+
server.registerTool('create-file', {
|
|
575
|
+
description: 'Create a new attachment file in the database from a local image file or from base64 image data. ' +
|
|
576
|
+
'Returns the Markdown to embed the attachment in a note body. ' +
|
|
577
|
+
'Prefer `filePath` over `data`: it keeps the image bytes out of the conversation.',
|
|
578
|
+
inputSchema: {
|
|
579
|
+
filePath: zod_1.z
|
|
580
|
+
.string()
|
|
581
|
+
.optional()
|
|
582
|
+
.describe('Absolute path to a local image file to attach. Either this or `data` must be given.'),
|
|
583
|
+
data: zod_1.z
|
|
584
|
+
.string()
|
|
585
|
+
.optional()
|
|
586
|
+
.describe('Base64-encoded image data, without a `data:` URI prefix. Use `filePath` instead whenever the image is already on disk.'),
|
|
587
|
+
name: zod_1.z
|
|
588
|
+
.string()
|
|
589
|
+
.min(1)
|
|
590
|
+
.max(128)
|
|
591
|
+
.optional()
|
|
592
|
+
.describe('The file name. Defaults to the file name of `filePath`, or `image.<ext>` when `data` is given.'),
|
|
593
|
+
contentType: zod_1.z
|
|
594
|
+
.enum(ImageFileTypes)
|
|
595
|
+
.optional()
|
|
596
|
+
.describe('The MIME type of the image. Inferred from the `filePath` extension when omitted, so it is required with `data`.')
|
|
597
|
+
}
|
|
598
|
+
}, async ({ filePath, data, name, contentType }) => {
|
|
599
|
+
if ((filePath === undefined) === (data === undefined)) {
|
|
600
|
+
return {
|
|
601
|
+
content: [
|
|
602
|
+
{
|
|
603
|
+
type: 'text',
|
|
604
|
+
text: 'Failed to create the attachment: provide exactly one of `filePath` or `data`.'
|
|
605
|
+
}
|
|
606
|
+
],
|
|
607
|
+
isError: true
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
let buffer;
|
|
611
|
+
if (filePath !== undefined) {
|
|
612
|
+
try {
|
|
613
|
+
buffer = await (0, promises_1.readFile)(filePath);
|
|
614
|
+
}
|
|
615
|
+
catch (e) {
|
|
616
|
+
return {
|
|
617
|
+
content: [
|
|
618
|
+
{
|
|
619
|
+
type: 'text',
|
|
620
|
+
text: `Failed to read the file at ${filePath}: ${e.message}`
|
|
621
|
+
}
|
|
622
|
+
],
|
|
623
|
+
isError: true
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
contentType ??= (0, utils_1.inferImageContentType)(filePath);
|
|
627
|
+
name ??= (0, node_path_1.basename)(filePath);
|
|
628
|
+
}
|
|
629
|
+
else {
|
|
630
|
+
buffer = Buffer.from(data, 'base64');
|
|
631
|
+
}
|
|
632
|
+
if (!contentType) {
|
|
633
|
+
return {
|
|
634
|
+
content: [
|
|
635
|
+
{
|
|
636
|
+
type: 'text',
|
|
637
|
+
text: `Failed to create the attachment: could not infer the content type${filePath ? ` from ${filePath}` : ''}. Pass \`contentType\` explicitly. Supported types: ${inkdrop_model_1.supportedImageFileTypes.join(', ')}.`
|
|
638
|
+
}
|
|
639
|
+
],
|
|
640
|
+
isError: true
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
const base64 = buffer.toString('base64');
|
|
644
|
+
const contentLength = Math.floor((base64.length * 3) / 4);
|
|
645
|
+
if (contentLength > inkdrop_model_1.maxAttachmentFileSize) {
|
|
646
|
+
return {
|
|
647
|
+
content: [
|
|
648
|
+
{
|
|
649
|
+
type: 'text',
|
|
650
|
+
text: `Failed to create the attachment: the file is ${contentLength} bytes, over the ${inkdrop_model_1.maxAttachmentFileSize} byte limit.`
|
|
651
|
+
}
|
|
652
|
+
],
|
|
653
|
+
isError: true
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
const res = await (0, api_1.postJSON)('/files', {
|
|
657
|
+
name: name ?? `image.${contentType.replace(/^image\//, '')}`,
|
|
658
|
+
contentType,
|
|
659
|
+
contentLength,
|
|
660
|
+
publicIn: [],
|
|
661
|
+
md5digest: (0, node_crypto_1.createHash)('md5').update(buffer).digest('hex'),
|
|
662
|
+
_attachments: {
|
|
663
|
+
index: {
|
|
664
|
+
content_type: contentType,
|
|
665
|
+
data: base64
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
});
|
|
669
|
+
return {
|
|
670
|
+
content: [
|
|
671
|
+
{
|
|
672
|
+
type: 'text',
|
|
673
|
+
text: JSON.stringify(res, null, 2)
|
|
674
|
+
},
|
|
675
|
+
{
|
|
676
|
+
type: 'text',
|
|
677
|
+
text: `Markdown to embed this attachment in a note body:\n\n(res.id)})`
|
|
490
678
|
}
|
|
679
|
+
]
|
|
680
|
+
};
|
|
681
|
+
});
|
|
682
|
+
server.registerTool('read-file', {
|
|
683
|
+
description: 'Retrieve an attachment file by its ID. Returns the file metadata, and the image itself when it is a PNG, JPEG or GIF. ' +
|
|
684
|
+
'Pass `outputPath` to write the attachment to disk instead — required to get at SVG, HEIC and HEIF attachments, which cannot be displayed inline.',
|
|
685
|
+
inputSchema: {
|
|
686
|
+
fileId: zod_1.z
|
|
687
|
+
.string()
|
|
688
|
+
.describe('ID of the attachment to retrieve. It can be found as `_id` in the file docs. It always starts with \`file:\`.'),
|
|
689
|
+
outputPath: zod_1.z
|
|
690
|
+
.string()
|
|
691
|
+
.optional()
|
|
692
|
+
.describe('Absolute path to write the attachment to. When given, the file is saved there and its bytes are not returned inline.'),
|
|
693
|
+
includeImage: zod_1.z
|
|
694
|
+
.boolean()
|
|
695
|
+
.optional()
|
|
696
|
+
.default(true)
|
|
697
|
+
.describe('Whether to return the image itself alongside the metadata. Set to false to fetch only the metadata of a large attachment.')
|
|
698
|
+
}
|
|
699
|
+
}, async ({ fileId, outputPath, includeImage }) => {
|
|
700
|
+
if (!fileId.startsWith('file:'))
|
|
701
|
+
fileId = `file:${fileId}`;
|
|
702
|
+
const needsData = includeImage || outputPath !== undefined;
|
|
703
|
+
const file = await (0, api_1.fetchJSON)(`/${fileId}`, {
|
|
704
|
+
attachments: needsData ? true : undefined
|
|
705
|
+
});
|
|
706
|
+
const { _attachments, ...metadata } = file;
|
|
707
|
+
const base64 = typeof _attachments?.index?.data === 'string' ? _attachments.index.data : undefined;
|
|
708
|
+
const attachmentBlock = async () => {
|
|
709
|
+
if (!needsData)
|
|
710
|
+
return [];
|
|
711
|
+
if (!base64) {
|
|
712
|
+
return [
|
|
713
|
+
{
|
|
714
|
+
type: 'text',
|
|
715
|
+
text: 'The attachment data could not be read from the document.'
|
|
716
|
+
}
|
|
717
|
+
];
|
|
718
|
+
}
|
|
719
|
+
if (outputPath !== undefined) {
|
|
720
|
+
await (0, promises_1.writeFile)(outputPath, Buffer.from(base64, 'base64'));
|
|
721
|
+
return [{ type: 'text', text: `Attachment written to ${outputPath}` }];
|
|
722
|
+
}
|
|
723
|
+
if (!(0, utils_1.isViewableImageType)(file.contentType)) {
|
|
724
|
+
return [
|
|
725
|
+
{
|
|
726
|
+
type: 'text',
|
|
727
|
+
text: `The attachment is a ${file.contentType} file, which cannot be displayed inline. Pass \`outputPath\` to write it to disk.`
|
|
728
|
+
}
|
|
729
|
+
];
|
|
491
730
|
}
|
|
492
|
-
|
|
493
|
-
|
|
731
|
+
return [
|
|
732
|
+
{
|
|
733
|
+
type: 'image',
|
|
734
|
+
data: base64,
|
|
735
|
+
// `image/jpg` is not a real MIME type; the image block expects `image/jpeg`.
|
|
736
|
+
mimeType: file.contentType === 'image/jpg' ? 'image/jpeg' : file.contentType
|
|
737
|
+
}
|
|
738
|
+
];
|
|
739
|
+
};
|
|
740
|
+
return {
|
|
741
|
+
content: [
|
|
742
|
+
{ type: 'text', text: JSON.stringify(metadata, null, 2) },
|
|
743
|
+
...(await attachmentBlock())
|
|
744
|
+
]
|
|
745
|
+
};
|
|
746
|
+
});
|
|
494
747
|
async function runServer() {
|
|
495
748
|
const transport = new stdio_js_1.StdioServerTransport();
|
|
496
749
|
await server.connect(transport);
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNoteUri = getNoteUri;
|
|
4
|
+
exports.getFileUri = getFileUri;
|
|
5
|
+
exports.inferImageContentType = inferImageContentType;
|
|
6
|
+
exports.isViewableImageType = isViewableImageType;
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
|
+
const inkdrop_model_1 = require("inkdrop-model");
|
|
9
|
+
/**
|
|
10
|
+
* Builds the canonical Inkdrop note URI for a note ID.
|
|
11
|
+
*
|
|
12
|
+
* The `note:` prefix is stripped so the result matches how note links are stored
|
|
13
|
+
* in note bodies (`note:foobar` → `inkdrop://note/foobar`). Backlink searches rely
|
|
14
|
+
* on this exact form to find notes that link to a given note.
|
|
15
|
+
*
|
|
16
|
+
* @param noteId - The note document ID, with or without the `note:` prefix
|
|
17
|
+
* @returns The `inkdrop://note/<id>` URI
|
|
18
|
+
*/
|
|
19
|
+
function getNoteUri(noteId) {
|
|
20
|
+
return `inkdrop://note/${noteId.replace(/^note:/, '')}`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Builds the Inkdrop attachment URI for a file ID.
|
|
24
|
+
*
|
|
25
|
+
* Unlike note links, attachment URIs keep the `file:` prefix and use no slash
|
|
26
|
+
* (`file:foobar` → `inkdrop://file:foobar`). This matches how the desktop app
|
|
27
|
+
* renders an attachment into a note body, so the result can be embedded as-is.
|
|
28
|
+
*
|
|
29
|
+
* @param fileId - The file document ID, with or without the `file:` prefix
|
|
30
|
+
* @returns The `inkdrop://file:<id>` URI
|
|
31
|
+
*/
|
|
32
|
+
function getFileUri(fileId) {
|
|
33
|
+
return `inkdrop://${fileId.startsWith('file:') ? fileId : `file:${fileId}`}`;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Infers the attachment content type from a file name or path extension.
|
|
37
|
+
*
|
|
38
|
+
* `SUPPORTED_IMAGE_MIME_TYPES` is keyed by MIME subtype, which doubles as the file
|
|
39
|
+
* extension for every supported type except SVG, whose subtype is `svg+xml`.
|
|
40
|
+
*
|
|
41
|
+
* @returns The matching image MIME type, or `undefined` when the extension is
|
|
42
|
+
* missing or not a supported attachment type
|
|
43
|
+
*/
|
|
44
|
+
function inferImageContentType(filePath) {
|
|
45
|
+
const ext = (0, node_path_1.extname)(filePath).toLowerCase().replace(/^\./, '');
|
|
46
|
+
return inkdrop_model_1.SUPPORTED_IMAGE_MIME_TYPES[ext === 'svg' ? 'svg+xml' : ext];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Content types the MCP `image` content block can carry. Inkdrop also accepts
|
|
50
|
+
* SVG and HEIC/HEIF attachments, which have to be written to disk instead.
|
|
51
|
+
*/
|
|
52
|
+
const VIEWABLE_IMAGE_TYPES = new Set([
|
|
53
|
+
'image/png',
|
|
54
|
+
'image/jpeg',
|
|
55
|
+
'image/jpg',
|
|
56
|
+
'image/gif'
|
|
57
|
+
]);
|
|
58
|
+
/**
|
|
59
|
+
* Whether an attachment can be returned as an MCP `image` content block.
|
|
60
|
+
*/
|
|
61
|
+
function isViewableImageType(contentType) {
|
|
62
|
+
return contentType !== undefined && VIEWABLE_IMAGE_TYPES.has(contentType);
|
|
63
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkdropapp/mcp-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Inkdrop Model Context Protocol Server",
|
|
5
5
|
"bin": {
|
|
6
6
|
"inkdrop-mcp-server": "dist/index.js"
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
"build": "tsc && chmod +x dist/*.js",
|
|
11
11
|
"prepublishOnly": "npm run build",
|
|
12
12
|
"watch": "tsc --watch",
|
|
13
|
+
"format": "oxfmt",
|
|
14
|
+
"format:check": "oxfmt --check",
|
|
13
15
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
16
|
},
|
|
15
17
|
"repository": {
|
|
@@ -24,14 +26,14 @@
|
|
|
24
26
|
"author": "Takuya Matsuyama<contact@inkdrop.app>",
|
|
25
27
|
"license": "Apache-2.0",
|
|
26
28
|
"dependencies": {
|
|
27
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
28
|
-
"ajv": "^8.
|
|
29
|
-
"inkdrop-model": "^2.
|
|
30
|
-
"zod": "^4.
|
|
29
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
30
|
+
"ajv": "^8.20.0",
|
|
31
|
+
"inkdrop-model": "^2.13.1",
|
|
32
|
+
"zod": "^4.5.4"
|
|
31
33
|
},
|
|
32
34
|
"devDependencies": {
|
|
33
|
-
"@types/node": "^
|
|
34
|
-
"
|
|
35
|
-
"typescript": "^
|
|
35
|
+
"@types/node": "^26.4.1",
|
|
36
|
+
"oxfmt": "^0.66.0",
|
|
37
|
+
"typescript": "^7.0.2"
|
|
36
38
|
}
|
|
37
39
|
}
|
package/src/api.ts
CHANGED
|
@@ -1,48 +1,45 @@
|
|
|
1
1
|
const config = {
|
|
2
2
|
baseUrl: process.env.INKDROP_LOCAL_SERVER_URL,
|
|
3
3
|
username: process.env.INKDROP_LOCAL_USERNAME,
|
|
4
|
-
password: process.env.INKDROP_LOCAL_PASSWORD
|
|
5
|
-
}
|
|
4
|
+
password: process.env.INKDROP_LOCAL_PASSWORD
|
|
5
|
+
}
|
|
6
6
|
|
|
7
7
|
function getAuthHeaders() {
|
|
8
|
-
const token = Buffer.from(`${config.username}:${config.password}`).toString(
|
|
9
|
-
"base64"
|
|
10
|
-
);
|
|
8
|
+
const token = Buffer.from(`${config.username}:${config.password}`).toString('base64')
|
|
11
9
|
return {
|
|
12
10
|
Authorization: `Basic ${token}`
|
|
13
|
-
}
|
|
11
|
+
}
|
|
14
12
|
}
|
|
15
13
|
|
|
16
14
|
export function buildUrl(path: string, qs: Record<string, any> = {}): string {
|
|
17
|
-
const url = new URL(path, config.baseUrl)
|
|
15
|
+
const url = new URL(path, config.baseUrl)
|
|
18
16
|
for (const [k, v] of Object.entries(qs)) {
|
|
19
|
-
if (v !== undefined && v !== null) url.searchParams.set(k, String(v))
|
|
17
|
+
if (v !== undefined && v !== null) url.searchParams.set(k, String(v))
|
|
20
18
|
}
|
|
21
|
-
return url.toString()
|
|
19
|
+
return url.toString()
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
export async function fetchJSON<T = any>(path: string, qs: Record<string, any> = {}): Promise<T> {
|
|
25
|
-
const url = buildUrl(path, qs)
|
|
26
|
-
const resp = await fetch(url, { headers: getAuthHeaders() })
|
|
23
|
+
const url = buildUrl(path, qs)
|
|
24
|
+
const resp = await fetch(url, { headers: getAuthHeaders() })
|
|
27
25
|
if (!resp.ok) {
|
|
28
|
-
throw new Error(`Fetch error [${resp.status}] ${resp.statusText}`)
|
|
26
|
+
throw new Error(`Fetch error [${resp.status}] ${resp.statusText}`)
|
|
29
27
|
}
|
|
30
|
-
return await resp.json() as T
|
|
28
|
+
return (await resp.json()) as T
|
|
31
29
|
}
|
|
32
30
|
|
|
33
|
-
export async function postJSON(path: string, body: unknown) {
|
|
34
|
-
const url = buildUrl(path)
|
|
31
|
+
export async function postJSON<T = any>(path: string, body: unknown): Promise<T> {
|
|
32
|
+
const url = buildUrl(path)
|
|
35
33
|
const resp = await fetch(url, {
|
|
36
|
-
method:
|
|
34
|
+
method: 'POST',
|
|
37
35
|
headers: {
|
|
38
36
|
...getAuthHeaders(),
|
|
39
|
-
|
|
37
|
+
'Content-Type': 'application/json'
|
|
40
38
|
},
|
|
41
39
|
body: JSON.stringify(body)
|
|
42
|
-
})
|
|
40
|
+
})
|
|
43
41
|
if (!resp.ok) {
|
|
44
|
-
throw new Error(`Fetch error [${resp.status}] ${resp.statusText}`)
|
|
42
|
+
throw new Error(`Fetch error [${resp.status}] ${resp.statusText}`)
|
|
45
43
|
}
|
|
46
|
-
return await resp.json()
|
|
44
|
+
return (await resp.json()) as T
|
|
47
45
|
}
|
|
48
|
-
|