@inkdropapp/mcp-server 1.3.0 → 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 +20 -16
- package/Session.vim +122 -0
- package/dist/index.js +119 -18
- package/dist/utils.js +16 -0
- package/package.json +8 -9
- package/pnpm-workspace.yaml +3 -0
- package/src/index.ts +139 -19
- 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,25 +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
|
-
- `
|
|
77
|
-
|
|
78
|
-
8. **`
|
|
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.
|
|
80
|
+
- `new_string`: The text to replace `old_string` with. Use an empty string to delete the matched text.
|
|
81
|
+
8. **`list-notebooks`**: Retrieve a list of all notebooks.
|
|
82
|
+
9. **`read-book`**: Retrieve a single notebook by its ID.
|
|
79
83
|
- Required inputs:
|
|
80
84
|
- `bookId`: The notebook ID. Must start with 'book:'.
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
10. **`list-tags`**: Retrieve a list of all tags.
|
|
86
|
+
11. **`read-tag`**: Retrieve a single tag by its ID.
|
|
83
87
|
- Required inputs:
|
|
84
88
|
- `tagId`: The tag ID. Must start with 'tag:'.
|
|
85
|
-
|
|
89
|
+
12. **`create-tag`**: Create a new tag in the database.
|
|
86
90
|
- Required inputs:
|
|
87
91
|
- `name`: The name of the tag.
|
|
88
92
|
- Optional inputs:
|
|
89
93
|
- `color`: The color type of the tag (`default`, `red`, `orange`, `yellow`, `olive`, `green`, `teal`, `blue`, `violet`, `purple`, `pink`, `brown`, `grey`, `black`). Default: `default`.
|
|
90
|
-
|
|
94
|
+
13. **`update-tag`**: Update an existing tag in the database.
|
|
91
95
|
- Required inputs:
|
|
92
96
|
- `_id`: The tag ID. Must start with 'tag:'.
|
|
93
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
|
@@ -5,8 +5,8 @@ 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");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
10
|
const server = new mcp_js_1.McpServer({
|
|
11
11
|
name: 'Inkdrop',
|
|
12
12
|
version: '1.3.0'
|
|
@@ -15,7 +15,9 @@ server.registerResource('note', new mcp_js_1.ResourceTemplate('inkdrop://note/{n
|
|
|
15
15
|
description: 'A note data',
|
|
16
16
|
mimeType: 'application/json'
|
|
17
17
|
}, async (uri, { noteId }) => {
|
|
18
|
-
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}`, {});
|
|
19
21
|
return {
|
|
20
22
|
contents: [
|
|
21
23
|
{
|
|
@@ -27,25 +29,94 @@ server.registerResource('note', new mcp_js_1.ResourceTemplate('inkdrop://note/{n
|
|
|
27
29
|
};
|
|
28
30
|
});
|
|
29
31
|
server.registerTool('read-note', {
|
|
30
|
-
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.',
|
|
31
37
|
inputSchema: {
|
|
32
38
|
noteId: zod_1.z
|
|
33
39
|
.string()
|
|
34
|
-
.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.')
|
|
35
46
|
}
|
|
36
|
-
}, async ({ noteId }) => {
|
|
47
|
+
}, async ({ noteId, includeTemplate }) => {
|
|
37
48
|
if (!noteId.startsWith('note:'))
|
|
38
49
|
noteId = `note:${noteId}`;
|
|
39
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
|
+
}
|
|
40
61
|
return {
|
|
41
62
|
content: [
|
|
42
63
|
{
|
|
43
64
|
type: 'text',
|
|
44
65
|
text: JSON.stringify(note, null, 2)
|
|
45
|
-
}
|
|
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
|
+
: [])
|
|
46
81
|
]
|
|
47
82
|
};
|
|
48
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
|
+
});
|
|
49
120
|
server.registerTool('search-notes', {
|
|
50
121
|
description: `List all notes that contain a given keyword.
|
|
51
122
|
The result does not include entire note bodies as they are truncated in 200 characters.
|
|
@@ -159,9 +230,14 @@ You have to retrieve the full note content by calling \`read-note\`.
|
|
|
159
230
|
.boolean()
|
|
160
231
|
.optional()
|
|
161
232
|
.default(true)
|
|
162
|
-
.describe(`Reverse the order of the output documents`)
|
|
233
|
+
.describe(`Reverse the order of the output documents`),
|
|
234
|
+
limit: zod_1.z
|
|
235
|
+
.number()
|
|
236
|
+
.optional()
|
|
237
|
+
.default(100)
|
|
238
|
+
.describe(`Limit the number of results returned`)
|
|
163
239
|
}
|
|
164
|
-
}, async ({ bookId, tagIds, keyword, sort, descending }) => {
|
|
240
|
+
}, async ({ bookId, tagIds, keyword, sort, descending, limit }) => {
|
|
165
241
|
const bookFilter = bookId ? `bookId:${bookId.split(':')[1]}` : '';
|
|
166
242
|
const tagFilter = tagIds ? tagIds.map(t => `tagId:${t}`).join(' ') : '';
|
|
167
243
|
keyword = `${bookFilter} ${tagFilter} ${keyword || ''}`.trim();
|
|
@@ -169,7 +245,7 @@ You have to retrieve the full note content by calling \`read-note\`.
|
|
|
169
245
|
keyword,
|
|
170
246
|
sort,
|
|
171
247
|
descending,
|
|
172
|
-
limit
|
|
248
|
+
limit
|
|
173
249
|
});
|
|
174
250
|
const summaries = notes.map(note => {
|
|
175
251
|
return {
|
|
@@ -259,7 +335,8 @@ server.registerTool('update-note', {
|
|
|
259
335
|
const existingNote = await (0, api_1.fetchJSON)(`/${noteData._id}`, { rev });
|
|
260
336
|
const res = await (0, api_1.postJSON)(`/notes`, {
|
|
261
337
|
...existingNote,
|
|
262
|
-
...noteData
|
|
338
|
+
...noteData,
|
|
339
|
+
updatedAt: +new Date()
|
|
263
340
|
});
|
|
264
341
|
return {
|
|
265
342
|
content: [
|
|
@@ -271,7 +348,7 @@ server.registerTool('update-note', {
|
|
|
271
348
|
};
|
|
272
349
|
});
|
|
273
350
|
server.registerTool('patch-note', {
|
|
274
|
-
description: 'Update the body of the existing note by
|
|
351
|
+
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
352
|
inputSchema: {
|
|
276
353
|
_id: zod_1.z
|
|
277
354
|
.string()
|
|
@@ -282,25 +359,49 @@ server.registerTool('patch-note', {
|
|
|
282
359
|
_rev: zod_1.z
|
|
283
360
|
.string()
|
|
284
361
|
.describe('This is a CouchDB specific field. The current MVCC-token/revision of this document (mandatory and immutable).'),
|
|
285
|
-
|
|
362
|
+
old_string: zod_1.z
|
|
286
363
|
.string()
|
|
287
|
-
.
|
|
364
|
+
.min(1)
|
|
365
|
+
.describe('The exact text to find in the note body. Must match exactly one occurrence. Include enough surrounding context to ensure a unique match.'),
|
|
366
|
+
new_string: zod_1.z
|
|
367
|
+
.string()
|
|
368
|
+
.describe('The text to replace `old_string` with. Use an empty string to delete the matched text.')
|
|
288
369
|
}
|
|
289
|
-
}, async ({ _id, _rev,
|
|
370
|
+
}, async ({ _id, _rev, old_string, new_string }) => {
|
|
290
371
|
const existingNote = await (0, api_1.fetchJSON)(`/${_id}`, { rev: _rev });
|
|
291
|
-
const
|
|
292
|
-
|
|
372
|
+
const body = existingNote.body;
|
|
373
|
+
const firstIndex = body.indexOf(old_string);
|
|
374
|
+
if (firstIndex === -1) {
|
|
375
|
+
return {
|
|
376
|
+
content: [
|
|
377
|
+
{
|
|
378
|
+
type: 'text',
|
|
379
|
+
text: 'Failed to patch: `old_string` was not found in the note body.'
|
|
380
|
+
}
|
|
381
|
+
],
|
|
382
|
+
isError: true
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
const secondIndex = body.indexOf(old_string, firstIndex + 1);
|
|
386
|
+
if (secondIndex !== -1) {
|
|
293
387
|
return {
|
|
294
388
|
content: [
|
|
295
389
|
{
|
|
296
390
|
type: 'text',
|
|
297
|
-
text: 'Failed to
|
|
391
|
+
text: 'Failed to patch: `old_string` matches multiple locations in the note body. Provide more surrounding context to make it unique.'
|
|
298
392
|
}
|
|
299
393
|
],
|
|
300
394
|
isError: true
|
|
301
395
|
};
|
|
302
396
|
}
|
|
303
|
-
const
|
|
397
|
+
const patched = body.slice(0, firstIndex) +
|
|
398
|
+
new_string +
|
|
399
|
+
body.slice(firstIndex + old_string.length);
|
|
400
|
+
const res = await (0, api_1.postJSON)('/notes', {
|
|
401
|
+
...existingNote,
|
|
402
|
+
body: patched,
|
|
403
|
+
updatedAt: +new Date()
|
|
404
|
+
});
|
|
304
405
|
return {
|
|
305
406
|
content: [
|
|
306
407
|
{
|
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,15 +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
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"zod": "^4.3.6"
|
|
27
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
28
|
+
"ajv": "^8.20.0",
|
|
29
|
+
"inkdrop-model": "^2.13.0",
|
|
30
|
+
"zod": "^4.4.3"
|
|
32
31
|
},
|
|
33
32
|
"devDependencies": {
|
|
34
|
-
"@types/node": "^
|
|
35
|
-
"prettier": "^3.
|
|
36
|
-
"typescript": "^
|
|
33
|
+
"@types/node": "^26.1.1",
|
|
34
|
+
"prettier": "^3.9.5",
|
|
35
|
+
"typescript": "^7.0.2"
|
|
37
36
|
}
|
|
38
37
|
}
|
package/src/index.ts
CHANGED
|
@@ -15,8 +15,9 @@ import {
|
|
|
15
15
|
Tag
|
|
16
16
|
} from 'inkdrop-model'
|
|
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
|
{
|
|
@@ -195,10 +277,15 @@ You have to retrieve the full note content by calling \`read-note\`.
|
|
|
195
277
|
.boolean()
|
|
196
278
|
.optional()
|
|
197
279
|
.default(true)
|
|
198
|
-
.describe(`Reverse the order of the output documents`)
|
|
280
|
+
.describe(`Reverse the order of the output documents`),
|
|
281
|
+
limit: z
|
|
282
|
+
.number()
|
|
283
|
+
.optional()
|
|
284
|
+
.default(100)
|
|
285
|
+
.describe(`Limit the number of results returned`)
|
|
199
286
|
}
|
|
200
287
|
},
|
|
201
|
-
async ({ bookId, tagIds, keyword, sort, descending }) => {
|
|
288
|
+
async ({ bookId, tagIds, keyword, sort, descending, limit }) => {
|
|
202
289
|
const bookFilter = bookId ? `bookId:${bookId.split(':')[1]}` : ''
|
|
203
290
|
const tagFilter = tagIds ? tagIds.map(t => `tagId:${t}`).join(' ') : ''
|
|
204
291
|
keyword = `${bookFilter} ${tagFilter} ${keyword || ''}`.trim()
|
|
@@ -206,7 +293,7 @@ You have to retrieve the full note content by calling \`read-note\`.
|
|
|
206
293
|
keyword,
|
|
207
294
|
sort,
|
|
208
295
|
descending,
|
|
209
|
-
limit
|
|
296
|
+
limit
|
|
210
297
|
})
|
|
211
298
|
const summaries = notes.map(note => {
|
|
212
299
|
return {
|
|
@@ -328,7 +415,8 @@ server.registerTool(
|
|
|
328
415
|
|
|
329
416
|
const res = await postJSON(`/notes`, {
|
|
330
417
|
...existingNote,
|
|
331
|
-
...noteData
|
|
418
|
+
...noteData,
|
|
419
|
+
updatedAt: +new Date()
|
|
332
420
|
})
|
|
333
421
|
return {
|
|
334
422
|
content: [
|
|
@@ -345,7 +433,7 @@ server.registerTool(
|
|
|
345
433
|
'patch-note',
|
|
346
434
|
{
|
|
347
435
|
description:
|
|
348
|
-
'Update the body of the existing note by
|
|
436
|
+
'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
437
|
inputSchema: {
|
|
350
438
|
_id: z
|
|
351
439
|
.string()
|
|
@@ -362,28 +450,60 @@ server.registerTool(
|
|
|
362
450
|
'This is a CouchDB specific field. The current MVCC-token/revision of this document (mandatory and immutable).'
|
|
363
451
|
),
|
|
364
452
|
|
|
365
|
-
|
|
453
|
+
old_string: z
|
|
366
454
|
.string()
|
|
455
|
+
.min(1)
|
|
367
456
|
.describe(
|
|
368
|
-
'
|
|
457
|
+
'The exact text to find in the note body. Must match exactly one occurrence. Include enough surrounding context to ensure a unique match.'
|
|
458
|
+
),
|
|
459
|
+
|
|
460
|
+
new_string: z
|
|
461
|
+
.string()
|
|
462
|
+
.describe(
|
|
463
|
+
'The text to replace `old_string` with. Use an empty string to delete the matched text.'
|
|
369
464
|
)
|
|
370
465
|
}
|
|
371
466
|
},
|
|
372
|
-
async ({ _id, _rev,
|
|
467
|
+
async ({ _id, _rev, old_string, new_string }) => {
|
|
373
468
|
const existingNote = await fetchJSON<Note>(`/${_id}`, { rev: _rev })
|
|
374
|
-
const
|
|
375
|
-
|
|
469
|
+
const body = existingNote.body
|
|
470
|
+
|
|
471
|
+
const firstIndex = body.indexOf(old_string)
|
|
472
|
+
if (firstIndex === -1) {
|
|
376
473
|
return {
|
|
377
474
|
content: [
|
|
378
475
|
{
|
|
379
476
|
type: 'text',
|
|
380
|
-
text: 'Failed to
|
|
477
|
+
text: 'Failed to patch: `old_string` was not found in the note body.'
|
|
381
478
|
}
|
|
382
479
|
],
|
|
383
480
|
isError: true
|
|
384
481
|
}
|
|
385
482
|
}
|
|
386
|
-
|
|
483
|
+
|
|
484
|
+
const secondIndex = body.indexOf(old_string, firstIndex + 1)
|
|
485
|
+
if (secondIndex !== -1) {
|
|
486
|
+
return {
|
|
487
|
+
content: [
|
|
488
|
+
{
|
|
489
|
+
type: 'text',
|
|
490
|
+
text: 'Failed to patch: `old_string` matches multiple locations in the note body. Provide more surrounding context to make it unique.'
|
|
491
|
+
}
|
|
492
|
+
],
|
|
493
|
+
isError: true
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
const patched =
|
|
498
|
+
body.slice(0, firstIndex) +
|
|
499
|
+
new_string +
|
|
500
|
+
body.slice(firstIndex + old_string.length)
|
|
501
|
+
|
|
502
|
+
const res = await postJSON('/notes', {
|
|
503
|
+
...existingNote,
|
|
504
|
+
body: patched,
|
|
505
|
+
updatedAt: +new Date()
|
|
506
|
+
})
|
|
387
507
|
return {
|
|
388
508
|
content: [
|
|
389
509
|
{
|
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
|
}
|