@inkdropapp/mcp-server 1.3.1 → 1.4.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 +18 -15
- package/Session.vim +122 -0
- package/dist/index.js +77 -5
- package/dist/utils.js +16 -0
- package/package.json +8 -8
- package/pnpm-workspace.yaml +3 -0
- package/src/index.ts +88 -6
- package/src/utils.ts +13 -0
- package/tsconfig.json +4 -10
package/README.md
CHANGED
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
A [Model Context Protocol](https://github.com/modelcontextprotocol) server for the [Inkdrop Local HTTP Server API](https://developers.inkdrop.app/data-access/local-http-server).
|
|
4
4
|
|
|
5
|
-
<a href="https://glama.ai/mcp/servers/c7fgtnckbv">
|
|
6
|
-
<img width="380" height="200" src="https://glama.ai/mcp/servers/c7fgtnckbv/badge" alt="Inkdrop Server MCP server" />
|
|
7
|
-
</a>
|
|
8
|
-
|
|
9
5
|
## Installation
|
|
10
6
|
|
|
11
7
|
1. [Set up a local HTTP server](https://developers.inkdrop.app/guides/integrate-with-external-programs)
|
|
@@ -37,12 +33,19 @@ A [Model Context Protocol](https://github.com/modelcontextprotocol) server for t
|
|
|
37
33
|
1. **`read-note`**: Retrieve the complete contents of the note by its ID from the database.
|
|
38
34
|
- Required inputs:
|
|
39
35
|
- `noteId`: The ID of the note to retrieve. It can be found as `_id` in the note docs. It always starts with `note:`.
|
|
40
|
-
|
|
36
|
+
- Optional inputs:
|
|
37
|
+
- `includeTemplate`: When `true` and the note has a `sourceTemplateId`, also fetch that template and embed its body (fill-out instructions and examples) as an extra text block. Default: `false`.
|
|
38
|
+
- Note: If the note was created from a template, the response includes a resource link to its source template, whose body holds the fill-out instructions and examples.
|
|
39
|
+
2. **`read-backlinks`**: Retrieve backlinks for a note — the notes that link to it.
|
|
40
|
+
- Required inputs:
|
|
41
|
+
- `noteId`: The ID of the note to find backlinks for. It always starts with `note:`.
|
|
42
|
+
- Note: Each result is returned as a resource link (`inkdrop://note/<id>`) pointing to the referring note. Backlinks are found by searching all note bodies for the note's link URI.
|
|
43
|
+
3. **`search-notes`**: List all notes that contain a given keyword.
|
|
41
44
|
- Required inputs:
|
|
42
45
|
- `keyword`: Keyword to search for.
|
|
43
46
|
- Note: Results include truncated note bodies (200 characters). Use `read-note` to get full content.
|
|
44
47
|
- Supports advanced search qualifiers like `book:`, `tag:`, `status:`, `title:`, etc.
|
|
45
|
-
|
|
48
|
+
4. **`list-notes`**: List all notes with specified conditions.
|
|
46
49
|
- Required inputs:
|
|
47
50
|
- `bookId`: The notebook ID. It always starts with 'book:'.
|
|
48
51
|
- Optional inputs:
|
|
@@ -51,7 +54,7 @@ A [Model Context Protocol](https://github.com/modelcontextprotocol) server for t
|
|
|
51
54
|
- `sort`: Sort field (`updatedAt`, `createdAt`, or `title`). Default: `updatedAt`.
|
|
52
55
|
- `descending`: Reverse the order of output. Default: `true`.
|
|
53
56
|
- Note: Results include truncated note bodies (200 characters). Use `read-note` to get full content.
|
|
54
|
-
|
|
57
|
+
5. **`create-note`**: Create a new note in the database.
|
|
55
58
|
- Required inputs:
|
|
56
59
|
- `bookId`: The notebook ID. Must start with 'book:' or be 'trash'.
|
|
57
60
|
- `title`: The note title.
|
|
@@ -59,7 +62,7 @@ A [Model Context Protocol](https://github.com/modelcontextprotocol) server for t
|
|
|
59
62
|
- Optional inputs:
|
|
60
63
|
- `status`: The note status (`none`, `active`, `onHold`, `completed`, `dropped`).
|
|
61
64
|
- `tags`: An array of tag IDs to assign to the note. Each must start with 'tag:'.
|
|
62
|
-
|
|
65
|
+
6. **`update-note`**: Update an existing note in the database. Only the fields you provide will be updated; omitted fields remain unchanged.
|
|
63
66
|
- Required inputs:
|
|
64
67
|
- `_id`: The note ID. Must start with 'note:'.
|
|
65
68
|
- `_rev`: The revision ID (CouchDB MVCC-token).
|
|
@@ -69,26 +72,26 @@ A [Model Context Protocol](https://github.com/modelcontextprotocol) server for t
|
|
|
69
72
|
- `body`: The content of the note in Markdown.
|
|
70
73
|
- `status`: The note status (`none`, `active`, `onHold`, `completed`, `dropped`).
|
|
71
74
|
- `tags`: An array of tag IDs to assign to the note. Each must start with 'tag:'.
|
|
72
|
-
|
|
75
|
+
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.
|
|
73
76
|
- Required inputs:
|
|
74
77
|
- `_id`: The note ID. Must start with 'note:'.
|
|
75
78
|
- `_rev`: The revision ID (CouchDB MVCC-token).
|
|
76
79
|
- `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
80
|
- `new_string`: The text to replace `old_string` with. Use an empty string to delete the matched text.
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
8. **`list-notebooks`**: Retrieve a list of all notebooks.
|
|
82
|
+
9. **`read-book`**: Retrieve a single notebook by its ID.
|
|
80
83
|
- Required inputs:
|
|
81
84
|
- `bookId`: The notebook ID. Must start with 'book:'.
|
|
82
|
-
|
|
83
|
-
|
|
85
|
+
10. **`list-tags`**: Retrieve a list of all tags.
|
|
86
|
+
11. **`read-tag`**: Retrieve a single tag by its ID.
|
|
84
87
|
- Required inputs:
|
|
85
88
|
- `tagId`: The tag ID. Must start with 'tag:'.
|
|
86
|
-
|
|
89
|
+
12. **`create-tag`**: Create a new tag in the database.
|
|
87
90
|
- Required inputs:
|
|
88
91
|
- `name`: The name of the tag.
|
|
89
92
|
- Optional inputs:
|
|
90
93
|
- `color`: The color type of the tag (`default`, `red`, `orange`, `yellow`, `olive`, `green`, `teal`, `blue`, `violet`, `purple`, `pink`, `brown`, `grey`, `black`). Default: `default`.
|
|
91
|
-
|
|
94
|
+
13. **`update-tag`**: Update an existing tag in the database.
|
|
92
95
|
- Required inputs:
|
|
93
96
|
- `_id`: The tag ID. Must start with 'tag:'.
|
|
94
97
|
- `_rev`: The revision ID (CouchDB MVCC-token).
|
package/Session.vim
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
let SessionLoad = 1
|
|
2
|
+
let s:so_save = &g:so | let s:siso_save = &g:siso | setg so=0 siso=0 | setl so=-1 siso=-1
|
|
3
|
+
let v:this_session=expand("<sfile>:p")
|
|
4
|
+
doautoall SessionLoadPre
|
|
5
|
+
silent only
|
|
6
|
+
silent tabonly
|
|
7
|
+
cd ~/Developments/inkdrop/mcp-server
|
|
8
|
+
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
|
|
9
|
+
let s:wipebuf = bufnr('%')
|
|
10
|
+
endif
|
|
11
|
+
let s:shortmess_save = &shortmess
|
|
12
|
+
set shortmess+=aoO
|
|
13
|
+
badd +34 package.json
|
|
14
|
+
badd +79 src/index.ts
|
|
15
|
+
badd +258 node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@4.4.3/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/mcp.d.ts
|
|
16
|
+
badd +6 src/utils.ts
|
|
17
|
+
argglobal
|
|
18
|
+
%argdel
|
|
19
|
+
$argadd package.json
|
|
20
|
+
edit src/index.ts
|
|
21
|
+
let s:save_splitbelow = &splitbelow
|
|
22
|
+
let s:save_splitright = &splitright
|
|
23
|
+
set splitbelow splitright
|
|
24
|
+
wincmd _ | wincmd |
|
|
25
|
+
vsplit
|
|
26
|
+
wincmd _ | wincmd |
|
|
27
|
+
vsplit
|
|
28
|
+
2wincmd h
|
|
29
|
+
wincmd w
|
|
30
|
+
wincmd w
|
|
31
|
+
let &splitbelow = s:save_splitbelow
|
|
32
|
+
let &splitright = s:save_splitright
|
|
33
|
+
wincmd t
|
|
34
|
+
let s:save_winminheight = &winminheight
|
|
35
|
+
let s:save_winminwidth = &winminwidth
|
|
36
|
+
set winminheight=0
|
|
37
|
+
set winheight=1
|
|
38
|
+
set winminwidth=0
|
|
39
|
+
set winwidth=1
|
|
40
|
+
exe 'vert 1resize ' . ((&columns * 153 + 230) / 460)
|
|
41
|
+
exe 'vert 2resize ' . ((&columns * 153 + 230) / 460)
|
|
42
|
+
exe 'vert 3resize ' . ((&columns * 152 + 230) / 460)
|
|
43
|
+
argglobal
|
|
44
|
+
balt package.json
|
|
45
|
+
setlocal foldmethod=expr
|
|
46
|
+
setlocal foldexpr=nvim_treesitter#foldexpr()
|
|
47
|
+
setlocal foldmarker={{{,}}}
|
|
48
|
+
setlocal foldignore=#
|
|
49
|
+
setlocal foldlevel=99
|
|
50
|
+
setlocal foldminlines=1
|
|
51
|
+
setlocal foldnestmax=20
|
|
52
|
+
setlocal foldenable
|
|
53
|
+
let s:l = 79 - ((41 * winheight(0) + 40) / 81)
|
|
54
|
+
if s:l < 1 | let s:l = 1 | endif
|
|
55
|
+
keepjumps exe s:l
|
|
56
|
+
normal! zt
|
|
57
|
+
keepjumps 79
|
|
58
|
+
normal! 031|
|
|
59
|
+
wincmd w
|
|
60
|
+
argglobal
|
|
61
|
+
if bufexists(fnamemodify("src/index.ts", ":p")) | buffer src/index.ts | else | edit src/index.ts | endif
|
|
62
|
+
if &buftype ==# 'terminal'
|
|
63
|
+
silent file src/index.ts
|
|
64
|
+
endif
|
|
65
|
+
balt package.json
|
|
66
|
+
setlocal foldmethod=expr
|
|
67
|
+
setlocal foldexpr=nvim_treesitter#foldexpr()
|
|
68
|
+
setlocal foldmarker={{{,}}}
|
|
69
|
+
setlocal foldignore=#
|
|
70
|
+
setlocal foldlevel=99
|
|
71
|
+
setlocal foldminlines=1
|
|
72
|
+
setlocal foldnestmax=20
|
|
73
|
+
setlocal foldenable
|
|
74
|
+
let s:l = 389 - ((37 * winheight(0) + 40) / 81)
|
|
75
|
+
if s:l < 1 | let s:l = 1 | endif
|
|
76
|
+
keepjumps exe s:l
|
|
77
|
+
normal! zt
|
|
78
|
+
keepjumps 389
|
|
79
|
+
normal! 010|
|
|
80
|
+
wincmd w
|
|
81
|
+
argglobal
|
|
82
|
+
if bufexists(fnamemodify("package.json", ":p")) | buffer package.json | else | edit package.json | endif
|
|
83
|
+
if &buftype ==# 'terminal'
|
|
84
|
+
silent file package.json
|
|
85
|
+
endif
|
|
86
|
+
balt src/index.ts
|
|
87
|
+
setlocal foldmethod=expr
|
|
88
|
+
setlocal foldexpr=nvim_treesitter#foldexpr()
|
|
89
|
+
setlocal foldmarker={{{,}}}
|
|
90
|
+
setlocal foldignore=#
|
|
91
|
+
setlocal foldlevel=99
|
|
92
|
+
setlocal foldminlines=1
|
|
93
|
+
setlocal foldnestmax=20
|
|
94
|
+
setlocal foldenable
|
|
95
|
+
let s:l = 34 - ((33 * winheight(0) + 40) / 81)
|
|
96
|
+
if s:l < 1 | let s:l = 1 | endif
|
|
97
|
+
keepjumps exe s:l
|
|
98
|
+
normal! zt
|
|
99
|
+
keepjumps 34
|
|
100
|
+
normal! 025|
|
|
101
|
+
wincmd w
|
|
102
|
+
exe 'vert 1resize ' . ((&columns * 153 + 230) / 460)
|
|
103
|
+
exe 'vert 2resize ' . ((&columns * 153 + 230) / 460)
|
|
104
|
+
exe 'vert 3resize ' . ((&columns * 152 + 230) / 460)
|
|
105
|
+
tabnext 1
|
|
106
|
+
if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0 && getbufvar(s:wipebuf, '&buftype') isnot# 'terminal'
|
|
107
|
+
silent exe 'bwipe ' . s:wipebuf
|
|
108
|
+
endif
|
|
109
|
+
unlet! s:wipebuf
|
|
110
|
+
set winheight=1 winwidth=20
|
|
111
|
+
let &shortmess = s:shortmess_save
|
|
112
|
+
let &winminheight = s:save_winminheight
|
|
113
|
+
let &winminwidth = s:save_winminwidth
|
|
114
|
+
let s:sx = expand("<sfile>:p:r")."x.vim"
|
|
115
|
+
if filereadable(s:sx)
|
|
116
|
+
exe "source " . fnameescape(s:sx)
|
|
117
|
+
endif
|
|
118
|
+
let &g:so = s:so_save | let &g:siso = s:siso_save
|
|
119
|
+
set hlsearch
|
|
120
|
+
doautoall SessionLoadPost
|
|
121
|
+
unlet SessionLoad
|
|
122
|
+
" vim: set ft=vim :
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ 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
8
|
const api_1 = require("./api");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
9
10
|
const server = new mcp_js_1.McpServer({
|
|
10
11
|
name: 'Inkdrop',
|
|
11
12
|
version: '1.3.0'
|
|
@@ -14,7 +15,9 @@ server.registerResource('note', new mcp_js_1.ResourceTemplate('inkdrop://note/{n
|
|
|
14
15
|
description: 'A note data',
|
|
15
16
|
mimeType: 'application/json'
|
|
16
17
|
}, async (uri, { noteId }) => {
|
|
17
|
-
const
|
|
18
|
+
const id = Array.isArray(noteId) ? noteId[0] : noteId;
|
|
19
|
+
const normalizedId = id.startsWith('note:') ? id : `note:${id}`;
|
|
20
|
+
const note = await (0, api_1.fetchJSON)(`/${normalizedId}`, {});
|
|
18
21
|
return {
|
|
19
22
|
contents: [
|
|
20
23
|
{
|
|
@@ -26,25 +29,94 @@ server.registerResource('note', new mcp_js_1.ResourceTemplate('inkdrop://note/{n
|
|
|
26
29
|
};
|
|
27
30
|
});
|
|
28
31
|
server.registerTool('read-note', {
|
|
29
|
-
description: 'Retrieve the complete contents of the note by its ID from the database.'
|
|
32
|
+
description: 'Retrieve the complete contents of the note by its ID from the database. ' +
|
|
33
|
+
'A note created from a template has a `sourceTemplateId`; when present, the response ' +
|
|
34
|
+
'includes a resource link to that source template, whose body holds the fill-out ' +
|
|
35
|
+
'instructions and examples. Read the template (or pass `includeTemplate: true`) before ' +
|
|
36
|
+
'completing the note.',
|
|
30
37
|
inputSchema: {
|
|
31
38
|
noteId: zod_1.z
|
|
32
39
|
.string()
|
|
33
|
-
.describe('ID of the note to retrieve. It can be found as `_id` in the note docs. It always starts with \`note:\`.')
|
|
40
|
+
.describe('ID of the note to retrieve. It can be found as `_id` in the note docs. It always starts with \`note:\`.'),
|
|
41
|
+
includeTemplate: zod_1.z
|
|
42
|
+
.boolean()
|
|
43
|
+
.optional()
|
|
44
|
+
.default(false)
|
|
45
|
+
.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
46
|
}
|
|
35
|
-
}, async ({ noteId }) => {
|
|
47
|
+
}, async ({ noteId, includeTemplate }) => {
|
|
36
48
|
if (!noteId.startsWith('note:'))
|
|
37
49
|
noteId = `note:${noteId}`;
|
|
38
50
|
const note = await (0, api_1.fetchJSON)(`/${noteId}`, {});
|
|
51
|
+
let templateBlockText = null;
|
|
52
|
+
if (includeTemplate && note.sourceTemplateId) {
|
|
53
|
+
try {
|
|
54
|
+
const template = await (0, api_1.fetchJSON)(`/${note.sourceTemplateId}`, {});
|
|
55
|
+
templateBlockText = `# Source template: ${template.title}\n\n${template.body}`;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// Template unavailable (e.g. deleted → 404). Skip the embed; the note read still succeeds.
|
|
59
|
+
}
|
|
60
|
+
}
|
|
39
61
|
return {
|
|
40
62
|
content: [
|
|
41
63
|
{
|
|
42
64
|
type: 'text',
|
|
43
65
|
text: JSON.stringify(note, null, 2)
|
|
44
|
-
}
|
|
66
|
+
},
|
|
67
|
+
...(note.sourceTemplateId
|
|
68
|
+
? [
|
|
69
|
+
{
|
|
70
|
+
type: 'resource_link',
|
|
71
|
+
uri: (0, utils_1.getNoteUri)(note.sourceTemplateId),
|
|
72
|
+
name: 'Source template',
|
|
73
|
+
mimeType: 'application/json',
|
|
74
|
+
description: 'The template this note was created from. Read it to get the fill-out instructions and examples before completing this note.'
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
: []),
|
|
78
|
+
...(templateBlockText
|
|
79
|
+
? [{ type: 'text', text: templateBlockText }]
|
|
80
|
+
: [])
|
|
45
81
|
]
|
|
46
82
|
};
|
|
47
83
|
});
|
|
84
|
+
server.registerTool('read-backlinks', {
|
|
85
|
+
description: `Retrieve backlinks for a note — the notes that link to it.
|
|
86
|
+
Each result is returned as a resource link (\`inkdrop://note/<id>\`) pointing to the referring note.
|
|
87
|
+
Backlinks are found by searching all note bodies for the note's link URI.`,
|
|
88
|
+
inputSchema: {
|
|
89
|
+
noteId: zod_1.z
|
|
90
|
+
.string()
|
|
91
|
+
.describe('ID of the note to find backlinks for. It can be found as `_id` in the note docs. It always starts with \`note:\`.')
|
|
92
|
+
}
|
|
93
|
+
}, async ({ noteId }) => {
|
|
94
|
+
if (!noteId.startsWith('note:'))
|
|
95
|
+
noteId = `note:${noteId}`;
|
|
96
|
+
const noteLink = (0, utils_1.getNoteUri)(noteId);
|
|
97
|
+
const backlinks = await (0, api_1.fetchJSON)('/notes', {
|
|
98
|
+
keyword: noteLink,
|
|
99
|
+
limit: 100
|
|
100
|
+
});
|
|
101
|
+
if (backlinks.length === 0) {
|
|
102
|
+
return {
|
|
103
|
+
content: [
|
|
104
|
+
{
|
|
105
|
+
type: 'text',
|
|
106
|
+
text: `No backlinks found for ${noteLink}.`
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
content: backlinks.map(note => ({
|
|
113
|
+
type: 'resource_link',
|
|
114
|
+
uri: (0, utils_1.getNoteUri)(note._id),
|
|
115
|
+
name: note.title || 'Untitled note',
|
|
116
|
+
mimeType: 'application/json'
|
|
117
|
+
}))
|
|
118
|
+
};
|
|
119
|
+
});
|
|
48
120
|
server.registerTool('search-notes', {
|
|
49
121
|
description: `List all notes that contain a given keyword.
|
|
50
122
|
The result does not include entire note bodies as they are truncated in 200 characters.
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNoteUri = getNoteUri;
|
|
4
|
+
/**
|
|
5
|
+
* Builds the canonical Inkdrop note URI for a note ID.
|
|
6
|
+
*
|
|
7
|
+
* The `note:` prefix is stripped so the result matches how note links are stored
|
|
8
|
+
* in note bodies (`note:foobar` → `inkdrop://note/foobar`). Backlink searches rely
|
|
9
|
+
* on this exact form to find notes that link to a given note.
|
|
10
|
+
*
|
|
11
|
+
* @param noteId - The note document ID, with or without the `note:` prefix
|
|
12
|
+
* @returns The `inkdrop://note/<id>` URI
|
|
13
|
+
*/
|
|
14
|
+
function getNoteUri(noteId) {
|
|
15
|
+
return `inkdrop://note/${noteId.replace(/^note:/, '')}`;
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkdropapp/mcp-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Inkdrop Model Context Protocol Server",
|
|
5
5
|
"bin": {
|
|
6
6
|
"inkdrop-mcp-server": "dist/index.js"
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
"author": "Takuya Matsuyama<contact@inkdrop.app>",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
28
|
-
"ajv": "^8.
|
|
29
|
-
"inkdrop-model": "^2.
|
|
30
|
-
"zod": "^4.3
|
|
27
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
28
|
+
"ajv": "^8.20.0",
|
|
29
|
+
"inkdrop-model": "^2.13.0",
|
|
30
|
+
"zod": "^4.4.3"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@types/node": "^
|
|
34
|
-
"prettier": "^3.
|
|
35
|
-
"typescript": "^
|
|
33
|
+
"@types/node": "^26.1.1",
|
|
34
|
+
"prettier": "^3.9.5",
|
|
35
|
+
"typescript": "^7.0.2"
|
|
36
36
|
}
|
|
37
37
|
}
|
package/src/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
import { z } from 'zod'
|
|
18
18
|
|
|
19
19
|
import { fetchJSON, postJSON } from './api'
|
|
20
|
+
import { getNoteUri } from './utils'
|
|
20
21
|
|
|
21
22
|
const server = new McpServer({
|
|
22
23
|
name: 'Inkdrop',
|
|
@@ -31,7 +32,9 @@ server.registerResource(
|
|
|
31
32
|
mimeType: 'application/json'
|
|
32
33
|
},
|
|
33
34
|
async (uri, { noteId }) => {
|
|
34
|
-
const
|
|
35
|
+
const id = Array.isArray(noteId) ? noteId[0] : noteId
|
|
36
|
+
const normalizedId = id.startsWith('note:') ? id : `note:${id}`
|
|
37
|
+
const note: Note[] = await fetchJSON(`/${normalizedId}`, {})
|
|
35
38
|
return {
|
|
36
39
|
contents: [
|
|
37
40
|
{
|
|
@@ -48,29 +51,108 @@ server.registerTool(
|
|
|
48
51
|
'read-note',
|
|
49
52
|
{
|
|
50
53
|
description:
|
|
51
|
-
'Retrieve the complete contents of the note by its ID from the database.'
|
|
54
|
+
'Retrieve the complete contents of the note by its ID from the database. ' +
|
|
55
|
+
'A note created from a template has a `sourceTemplateId`; when present, the response ' +
|
|
56
|
+
'includes a resource link to that source template, whose body holds the fill-out ' +
|
|
57
|
+
'instructions and examples. Read the template (or pass `includeTemplate: true`) before ' +
|
|
58
|
+
'completing the note.',
|
|
52
59
|
inputSchema: {
|
|
53
60
|
noteId: z
|
|
54
61
|
.string()
|
|
55
62
|
.describe(
|
|
56
63
|
'ID of the note to retrieve. It can be found as `_id` in the note docs. It always starts with \`note:\`.'
|
|
64
|
+
),
|
|
65
|
+
includeTemplate: z
|
|
66
|
+
.boolean()
|
|
67
|
+
.optional()
|
|
68
|
+
.default(false)
|
|
69
|
+
.describe(
|
|
70
|
+
'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.'
|
|
57
71
|
)
|
|
58
72
|
}
|
|
59
73
|
},
|
|
60
|
-
async ({ noteId }) => {
|
|
74
|
+
async ({ noteId, includeTemplate }) => {
|
|
61
75
|
if (!noteId.startsWith('note:')) noteId = `note:${noteId}`
|
|
62
|
-
const note
|
|
76
|
+
const note = await fetchJSON<Note>(`/${noteId}`, {})
|
|
77
|
+
|
|
78
|
+
let templateBlockText: string | null = null
|
|
79
|
+
if (includeTemplate && note.sourceTemplateId) {
|
|
80
|
+
try {
|
|
81
|
+
const template = await fetchJSON<Note>(`/${note.sourceTemplateId}`, {})
|
|
82
|
+
templateBlockText = `# Source template: ${template.title}\n\n${template.body}`
|
|
83
|
+
} catch {
|
|
84
|
+
// Template unavailable (e.g. deleted → 404). Skip the embed; the note read still succeeds.
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
63
88
|
return {
|
|
64
89
|
content: [
|
|
65
90
|
{
|
|
66
|
-
type: 'text',
|
|
91
|
+
type: 'text' as const,
|
|
67
92
|
text: JSON.stringify(note, null, 2)
|
|
68
|
-
}
|
|
93
|
+
},
|
|
94
|
+
...(note.sourceTemplateId
|
|
95
|
+
? [
|
|
96
|
+
{
|
|
97
|
+
type: 'resource_link' as const,
|
|
98
|
+
uri: getNoteUri(note.sourceTemplateId),
|
|
99
|
+
name: 'Source template',
|
|
100
|
+
mimeType: 'application/json',
|
|
101
|
+
description:
|
|
102
|
+
'The template this note was created from. Read it to get the fill-out instructions and examples before completing this note.'
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
: []),
|
|
106
|
+
...(templateBlockText
|
|
107
|
+
? [{ type: 'text' as const, text: templateBlockText }]
|
|
108
|
+
: [])
|
|
69
109
|
]
|
|
70
110
|
}
|
|
71
111
|
}
|
|
72
112
|
)
|
|
73
113
|
|
|
114
|
+
server.registerTool(
|
|
115
|
+
'read-backlinks',
|
|
116
|
+
{
|
|
117
|
+
description: `Retrieve backlinks for a note — the notes that link to it.
|
|
118
|
+
Each result is returned as a resource link (\`inkdrop://note/<id>\`) pointing to the referring note.
|
|
119
|
+
Backlinks are found by searching all note bodies for the note's link URI.`,
|
|
120
|
+
inputSchema: {
|
|
121
|
+
noteId: z
|
|
122
|
+
.string()
|
|
123
|
+
.describe(
|
|
124
|
+
'ID of the note to find backlinks for. It can be found as `_id` in the note docs. It always starts with \`note:\`.'
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
async ({ noteId }) => {
|
|
129
|
+
if (!noteId.startsWith('note:')) noteId = `note:${noteId}`
|
|
130
|
+
const noteLink = getNoteUri(noteId)
|
|
131
|
+
const backlinks: Note[] = await fetchJSON('/notes', {
|
|
132
|
+
keyword: noteLink,
|
|
133
|
+
limit: 100
|
|
134
|
+
})
|
|
135
|
+
if (backlinks.length === 0) {
|
|
136
|
+
return {
|
|
137
|
+
content: [
|
|
138
|
+
{
|
|
139
|
+
type: 'text',
|
|
140
|
+
text: `No backlinks found for ${noteLink}.`
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
content: backlinks.map(note => ({
|
|
147
|
+
type: 'resource_link' as const,
|
|
148
|
+
uri: getNoteUri(note._id),
|
|
149
|
+
name: note.title || 'Untitled note',
|
|
150
|
+
mimeType: 'application/json'
|
|
151
|
+
}))
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
)
|
|
155
|
+
|
|
74
156
|
server.registerTool(
|
|
75
157
|
'search-notes',
|
|
76
158
|
{
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the canonical Inkdrop note URI for a note ID.
|
|
3
|
+
*
|
|
4
|
+
* The `note:` prefix is stripped so the result matches how note links are stored
|
|
5
|
+
* in note bodies (`note:foobar` → `inkdrop://note/foobar`). Backlink searches rely
|
|
6
|
+
* on this exact form to find notes that link to a given note.
|
|
7
|
+
*
|
|
8
|
+
* @param noteId - The note document ID, with or without the `note:` prefix
|
|
9
|
+
* @returns The `inkdrop://note/<id>` URI
|
|
10
|
+
*/
|
|
11
|
+
export function getNoteUri(noteId: string): string {
|
|
12
|
+
return `inkdrop://note/${noteId.replace(/^note:/, '')}`
|
|
13
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"outDir": "./dist",
|
|
4
4
|
"rootDir": "./src",
|
|
5
|
-
"lib": [
|
|
6
|
-
|
|
7
|
-
],
|
|
5
|
+
"lib": ["es2024"],
|
|
6
|
+
"types": ["node"],
|
|
8
7
|
"stripInternal": true,
|
|
9
8
|
"noUnusedLocals": false,
|
|
10
9
|
"strict": true,
|
|
@@ -17,11 +16,6 @@
|
|
|
17
16
|
"declaration": false,
|
|
18
17
|
"skipLibCheck": true
|
|
19
18
|
},
|
|
20
|
-
"include": [
|
|
21
|
-
|
|
22
|
-
],
|
|
23
|
-
"exclude": [
|
|
24
|
-
"node_modules",
|
|
25
|
-
"build"
|
|
26
|
-
]
|
|
19
|
+
"include": ["src/*.ts"],
|
|
20
|
+
"exclude": ["node_modules", "build"]
|
|
27
21
|
}
|