@inkdropapp/mcp-server 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +32 -19
- package/dist/index.js +73 -3
- package/package.json +6 -2
- package/src/index.ts +86 -4
- package/src/bak.ts +0 -433
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2025 Takuya Matsuyama
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
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
|
-
|
|
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>
|
|
6
8
|
|
|
7
9
|
## Installation
|
|
8
10
|
|
|
@@ -17,13 +19,10 @@ A [Model Context Protocol](https://github.com/modelcontextprotocol) server for t
|
|
|
17
19
|
"mcpServers": {
|
|
18
20
|
"inkdrop": {
|
|
19
21
|
"command": "npx",
|
|
20
|
-
"args": [
|
|
21
|
-
"-y",
|
|
22
|
-
"@inkdropapp/mcp-server"
|
|
23
|
-
],
|
|
22
|
+
"args": ["-y", "@inkdropapp/mcp-server"],
|
|
24
23
|
"env": {
|
|
25
24
|
"INKDROP_LOCAL_SERVER_URL": "http://localhost:19840",
|
|
26
|
-
"INKDROP_LOCAL_USERNAME": "your-local-server-username"
|
|
25
|
+
"INKDROP_LOCAL_USERNAME": "your-local-server-username",
|
|
27
26
|
"INKDROP_LOCAL_PASSWORD": "your-local-server-password"
|
|
28
27
|
}
|
|
29
28
|
}
|
|
@@ -37,25 +36,39 @@ A [Model Context Protocol](https://github.com/modelcontextprotocol) server for t
|
|
|
37
36
|
|
|
38
37
|
1. **`read-note`**: Retrieve the complete contents of the note by its ID from the database.
|
|
39
38
|
- Required inputs:
|
|
40
|
-
- `noteId`: The ID of the note to retrieve.
|
|
39
|
+
- `noteId`: The ID of the note to retrieve. It can be found as `_id` in the note docs. It always starts with `note:`.
|
|
41
40
|
2. **`search-notes`**: List all notes that contain a given keyword.
|
|
42
41
|
- Required inputs:
|
|
43
42
|
- `keyword`: Keyword to search for.
|
|
44
|
-
|
|
43
|
+
- Note: Results include truncated note bodies (200 characters). Use `read-note` to get full content.
|
|
44
|
+
- Supports advanced search qualifiers like `book:`, `tag:`, `status:`, `title:`, etc.
|
|
45
|
+
3. **`list-notes`**: List all notes with specified conditions.
|
|
45
46
|
- Required inputs:
|
|
46
|
-
- `bookId`: The notebook ID
|
|
47
|
-
- `title`: The note title
|
|
48
|
-
- `body`: The content of the note in Markdown
|
|
47
|
+
- `bookId`: The notebook ID. It always starts with 'book:'.
|
|
49
48
|
- Optional inputs:
|
|
50
|
-
- `
|
|
51
|
-
|
|
49
|
+
- `tagIds`: An array of tag IDs to filter. Each starts with 'tag:'.
|
|
50
|
+
- `keyword`: Keyword to filter notes.
|
|
51
|
+
- `sort`: Sort field (`updatedAt`, `createdAt`, or `title`). Default: `updatedAt`.
|
|
52
|
+
- `descending`: Reverse the order of output. Default: `true`.
|
|
53
|
+
- Note: Results include truncated note bodies (200 characters). Use `read-note` to get full content.
|
|
54
|
+
4. **`create-note`**: Create a new note in the database.
|
|
52
55
|
- Required inputs:
|
|
53
|
-
- `
|
|
54
|
-
- `
|
|
55
|
-
- `
|
|
56
|
-
|
|
57
|
-
- `
|
|
58
|
-
5. **`
|
|
56
|
+
- `bookId`: The notebook ID. Must start with 'book:' or be 'trash'.
|
|
57
|
+
- `title`: The note title.
|
|
58
|
+
- `body`: The content of the note in Markdown.
|
|
59
|
+
- Optional inputs:
|
|
60
|
+
- `status`: The note status (`none`, `active`, `onHold`, `completed`, `dropped`).
|
|
61
|
+
5. **`update-note`**: Update an existing note in the database.
|
|
62
|
+
- Required inputs:
|
|
63
|
+
- `_id`: The note ID. Must start with 'note:'.
|
|
64
|
+
- `_rev`: The revision ID (CouchDB MVCC-token).
|
|
65
|
+
- `bookId`: The notebook ID. Must start with 'book:' or be 'trash'.
|
|
66
|
+
- `title`: The note title.
|
|
67
|
+
- `body`: The content of the note in Markdown.
|
|
68
|
+
- Optional inputs:
|
|
69
|
+
- `status`: The note status (`none`, `active`, `onHold`, `completed`, `dropped`).
|
|
70
|
+
6. **`list-notebooks`**: Retrieve a list of all notebooks.
|
|
71
|
+
7. **`list-tags`**: Retrieve a list of all tags.
|
|
59
72
|
|
|
60
73
|
## Debugging
|
|
61
74
|
|
package/dist/index.js
CHANGED
|
@@ -28,8 +28,10 @@ server.resource('note', new mcp_js_1.ResourceTemplate('inkdrop://note/{noteId}',
|
|
|
28
28
|
server.tool('read-note', 'Retrieve the complete contents of the note by its ID from the database.', {
|
|
29
29
|
noteId: zod_1.z
|
|
30
30
|
.string()
|
|
31
|
-
.describe('ID of the note to retrieve. It can be found as `_id` in the note docs')
|
|
31
|
+
.describe('ID of the note to retrieve. It can be found as `_id` in the note docs. It always starts with \`note:\`.')
|
|
32
32
|
}, async ({ noteId }) => {
|
|
33
|
+
if (!noteId.startsWith('note:'))
|
|
34
|
+
noteId = `note:${noteId}`;
|
|
33
35
|
const note = await (0, api_1.fetchJSON)(`/${noteId}`, {});
|
|
34
36
|
return {
|
|
35
37
|
content: [
|
|
@@ -51,6 +53,9 @@ You can use special qualifiers to get more accurate results. See the qualifiers
|
|
|
51
53
|
|
|
52
54
|
- **book**
|
|
53
55
|
\`book:Blog\`: Searches for notes in the 'Blog' notebook.
|
|
56
|
+
\`book:"Desktop App"\`: Searches for notes in the 'Desktop App' notebook.
|
|
57
|
+
- **bookId**
|
|
58
|
+
\`bookId:kGlLniaV\`: Searches for notes in the notebook ID 'book:kGlLniaV'.
|
|
54
59
|
- **tag**
|
|
55
60
|
\`tag:JavaScript\`: Searches for all notes having the 'JavaScript' tag. Read more about [tags](https://docs.inkdrop.app/manual/write-notes#tag-notes).
|
|
56
61
|
- **status**
|
|
@@ -122,6 +127,55 @@ Note that you can't specify excluding modifiers only without including condition
|
|
|
122
127
|
]
|
|
123
128
|
};
|
|
124
129
|
});
|
|
130
|
+
server.tool('list-notes', `List all notes with specified conditions.
|
|
131
|
+
The result does not include entire note bodies as they are truncated in 200 characters.
|
|
132
|
+
You have to retrieve the full note content by calling \`read-note\`.
|
|
133
|
+
`, {
|
|
134
|
+
bookId: zod_1.z
|
|
135
|
+
.string()
|
|
136
|
+
.optional()
|
|
137
|
+
.describe(`ID of the notebook. It always starts with 'book:'. You can retrieve a list of notebooks with \`list-notebooks\``),
|
|
138
|
+
tagIds: zod_1.z
|
|
139
|
+
.array(zod_1.z.string())
|
|
140
|
+
.optional()
|
|
141
|
+
.default([])
|
|
142
|
+
.describe(`An array of tag IDs to filter. It always starts with 'tag:'. You can retrieve a list of available tags from \`list-tags\`.`),
|
|
143
|
+
keyword: zod_1.z.string().optional().describe(`Keyword to filter notes`),
|
|
144
|
+
sort: zod_1.z
|
|
145
|
+
.enum(['updatedAt', 'createdAt', 'title'])
|
|
146
|
+
.optional()
|
|
147
|
+
.default('updatedAt')
|
|
148
|
+
.describe(`Sort the documents by the specified field`),
|
|
149
|
+
descending: zod_1.z
|
|
150
|
+
.boolean()
|
|
151
|
+
.optional()
|
|
152
|
+
.default(true)
|
|
153
|
+
.describe(`Reverse the order of the output documents`)
|
|
154
|
+
}, async ({ bookId, tagIds, keyword, sort, descending }) => {
|
|
155
|
+
const bookFilter = bookId ? `bookId:${bookId.split(':')[1]}` : '';
|
|
156
|
+
const tagFilter = tagIds ? tagIds.map(t => `tagId:${t}`).join(' ') : '';
|
|
157
|
+
keyword = `${bookFilter} ${tagFilter} ${keyword || ''}`.trim();
|
|
158
|
+
const notes = await (0, api_1.fetchJSON)('/notes', {
|
|
159
|
+
keyword,
|
|
160
|
+
sort,
|
|
161
|
+
descending,
|
|
162
|
+
limit: 100
|
|
163
|
+
});
|
|
164
|
+
const summaries = notes.map(note => {
|
|
165
|
+
return {
|
|
166
|
+
...note,
|
|
167
|
+
body: note.body.substring(0, 200)
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
return {
|
|
171
|
+
content: [
|
|
172
|
+
{
|
|
173
|
+
type: 'text',
|
|
174
|
+
text: JSON.stringify(summaries, null, 2)
|
|
175
|
+
}
|
|
176
|
+
]
|
|
177
|
+
};
|
|
178
|
+
});
|
|
125
179
|
server.tool('create-note', 'Create a new note in the database', {
|
|
126
180
|
bookId: zod_1.z
|
|
127
181
|
.string()
|
|
@@ -149,7 +203,7 @@ server.tool('create-note', 'Create a new note in the database', {
|
|
|
149
203
|
]
|
|
150
204
|
};
|
|
151
205
|
});
|
|
152
|
-
server.tool('update-note', 'Update the existing note in the database', {
|
|
206
|
+
server.tool('update-note', 'Update the existing note in the database. You should retrieve the existing note with \`read-note\` first. When updating the note, you must specify not only the changed fields but also all the un-changed fields.', {
|
|
153
207
|
_id: zod_1.z
|
|
154
208
|
.string()
|
|
155
209
|
.min(6)
|
|
@@ -169,7 +223,7 @@ server.tool('update-note', 'Update the existing note in the database', {
|
|
|
169
223
|
body: zod_1.z
|
|
170
224
|
.string()
|
|
171
225
|
.max(1048576)
|
|
172
|
-
.describe('The content of the note
|
|
226
|
+
.describe('The content of the note in Markdown. NOTE: Do not escape special characters like `\\n`.'),
|
|
173
227
|
status: zod_1.z
|
|
174
228
|
.enum(['none', 'active', 'onHold', 'completed', 'dropped'])
|
|
175
229
|
.optional()
|
|
@@ -196,6 +250,17 @@ server.tool('list-notebooks', `Retrieve a list of all notebooks`, {}, async () =
|
|
|
196
250
|
]
|
|
197
251
|
};
|
|
198
252
|
});
|
|
253
|
+
server.tool('list-tags', `Retrieve a list of all tags`, {}, async () => {
|
|
254
|
+
const books = await (0, api_1.fetchJSON)('/tags');
|
|
255
|
+
return {
|
|
256
|
+
content: [
|
|
257
|
+
{
|
|
258
|
+
type: 'text',
|
|
259
|
+
text: JSON.stringify(books, null, 2)
|
|
260
|
+
}
|
|
261
|
+
]
|
|
262
|
+
};
|
|
263
|
+
});
|
|
199
264
|
server.prompt('inkdrop-prompt', 'Instructions for using the Inkdrop MCP server effectively', () => ({
|
|
200
265
|
messages: [
|
|
201
266
|
{
|
|
@@ -209,6 +274,8 @@ Key capabilities:
|
|
|
209
274
|
- Search notes by keyword
|
|
210
275
|
- Get a note by its ID
|
|
211
276
|
- Get a list of all notebooks
|
|
277
|
+
- Create a new note
|
|
278
|
+
- Update an existing note
|
|
212
279
|
|
|
213
280
|
Best practices:
|
|
214
281
|
- When searching:
|
|
@@ -226,6 +293,9 @@ ${JSON.stringify(inkdrop_model_1.NoteSchema, null, 2)}
|
|
|
226
293
|
${JSON.stringify(inkdrop_model_1.BookSchema, null, 2)}
|
|
227
294
|
\`\`\`
|
|
228
295
|
|
|
296
|
+
\`\`\`json
|
|
297
|
+
${JSON.stringify(inkdrop_model_1.TagSchema, null, 2)}
|
|
298
|
+
\`\`\`
|
|
229
299
|
`
|
|
230
300
|
}
|
|
231
301
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkdropapp/mcp-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Inkdrop Model Context Protocol Server",
|
|
5
5
|
"bin": {
|
|
6
6
|
"inkdrop-mcp-server": "dist/index.js"
|
|
@@ -12,13 +12,17 @@
|
|
|
12
12
|
"watch": "tsc --watch",
|
|
13
13
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
14
|
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/inkdropapp/mcp-server.git"
|
|
18
|
+
},
|
|
15
19
|
"keywords": [
|
|
16
20
|
"Inkdrop",
|
|
17
21
|
"MCP",
|
|
18
22
|
"Claude"
|
|
19
23
|
],
|
|
20
24
|
"author": "Takuya Matsuyama<contact@inkdrop.app>",
|
|
21
|
-
"license": "
|
|
25
|
+
"license": "Apache-2.0",
|
|
22
26
|
"dependencies": {
|
|
23
27
|
"@modelcontextprotocol/sdk": "^1.6.1",
|
|
24
28
|
"ajv": "^8.17.1",
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
ResourceTemplate
|
|
6
6
|
} from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
7
7
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
8
|
-
import { Note, NoteSchema, Book, BookSchema } from 'inkdrop-model'
|
|
8
|
+
import { Note, NoteSchema, Book, BookSchema, TagSchema } from 'inkdrop-model'
|
|
9
9
|
import { z } from 'zod'
|
|
10
10
|
import { fetchJSON, postJSON } from './api'
|
|
11
11
|
|
|
@@ -42,10 +42,11 @@ server.tool(
|
|
|
42
42
|
noteId: z
|
|
43
43
|
.string()
|
|
44
44
|
.describe(
|
|
45
|
-
'ID of the note to retrieve. It can be found as `_id` in the note docs'
|
|
45
|
+
'ID of the note to retrieve. It can be found as `_id` in the note docs. It always starts with \`note:\`.'
|
|
46
46
|
)
|
|
47
47
|
},
|
|
48
48
|
async ({ noteId }) => {
|
|
49
|
+
if (!noteId.startsWith('note:')) noteId = `note:${noteId}`
|
|
49
50
|
const note: Note[] = await fetchJSON(`/${noteId}`, {})
|
|
50
51
|
return {
|
|
51
52
|
content: [
|
|
@@ -71,6 +72,9 @@ You can use special qualifiers to get more accurate results. See the qualifiers
|
|
|
71
72
|
|
|
72
73
|
- **book**
|
|
73
74
|
\`book:Blog\`: Searches for notes in the 'Blog' notebook.
|
|
75
|
+
\`book:"Desktop App"\`: Searches for notes in the 'Desktop App' notebook.
|
|
76
|
+
- **bookId**
|
|
77
|
+
\`bookId:kGlLniaV\`: Searches for notes in the notebook ID 'book:kGlLniaV'.
|
|
74
78
|
- **tag**
|
|
75
79
|
\`tag:JavaScript\`: Searches for all notes having the 'JavaScript' tag. Read more about [tags](https://docs.inkdrop.app/manual/write-notes#tag-notes).
|
|
76
80
|
- **status**
|
|
@@ -146,6 +150,65 @@ Note that you can't specify excluding modifiers only without including condition
|
|
|
146
150
|
}
|
|
147
151
|
)
|
|
148
152
|
|
|
153
|
+
server.tool(
|
|
154
|
+
'list-notes',
|
|
155
|
+
`List all notes with specified conditions.
|
|
156
|
+
The result does not include entire note bodies as they are truncated in 200 characters.
|
|
157
|
+
You have to retrieve the full note content by calling \`read-note\`.
|
|
158
|
+
`,
|
|
159
|
+
{
|
|
160
|
+
bookId: z
|
|
161
|
+
.string()
|
|
162
|
+
.optional()
|
|
163
|
+
.describe(
|
|
164
|
+
`ID of the notebook. It always starts with 'book:'. You can retrieve a list of notebooks with \`list-notebooks\``
|
|
165
|
+
),
|
|
166
|
+
tagIds: z
|
|
167
|
+
.array(z.string())
|
|
168
|
+
.optional()
|
|
169
|
+
.default([])
|
|
170
|
+
.describe(
|
|
171
|
+
`An array of tag IDs to filter. It always starts with 'tag:'. You can retrieve a list of available tags from \`list-tags\`.`
|
|
172
|
+
),
|
|
173
|
+
keyword: z.string().optional().describe(`Keyword to filter notes`),
|
|
174
|
+
sort: z
|
|
175
|
+
.enum(['updatedAt', 'createdAt', 'title'])
|
|
176
|
+
.optional()
|
|
177
|
+
.default('updatedAt')
|
|
178
|
+
.describe(`Sort the documents by the specified field`),
|
|
179
|
+
descending: z
|
|
180
|
+
.boolean()
|
|
181
|
+
.optional()
|
|
182
|
+
.default(true)
|
|
183
|
+
.describe(`Reverse the order of the output documents`)
|
|
184
|
+
},
|
|
185
|
+
async ({ bookId, tagIds, keyword, sort, descending }) => {
|
|
186
|
+
const bookFilter = bookId ? `bookId:${bookId.split(':')[1]}` : ''
|
|
187
|
+
const tagFilter = tagIds ? tagIds.map(t => `tagId:${t}`).join(' ') : ''
|
|
188
|
+
keyword = `${bookFilter} ${tagFilter} ${keyword || ''}`.trim()
|
|
189
|
+
const notes: Note[] = await fetchJSON('/notes', {
|
|
190
|
+
keyword,
|
|
191
|
+
sort,
|
|
192
|
+
descending,
|
|
193
|
+
limit: 100
|
|
194
|
+
})
|
|
195
|
+
const summaries = notes.map(note => {
|
|
196
|
+
return {
|
|
197
|
+
...note,
|
|
198
|
+
body: note.body.substring(0, 200)
|
|
199
|
+
}
|
|
200
|
+
})
|
|
201
|
+
return {
|
|
202
|
+
content: [
|
|
203
|
+
{
|
|
204
|
+
type: 'text',
|
|
205
|
+
text: JSON.stringify(summaries, null, 2)
|
|
206
|
+
}
|
|
207
|
+
]
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
)
|
|
211
|
+
|
|
149
212
|
server.tool(
|
|
150
213
|
'create-note',
|
|
151
214
|
'Create a new note in the database',
|
|
@@ -184,7 +247,7 @@ server.tool(
|
|
|
184
247
|
|
|
185
248
|
server.tool(
|
|
186
249
|
'update-note',
|
|
187
|
-
'Update the existing note in the database',
|
|
250
|
+
'Update the existing note in the database. You should retrieve the existing note with \`read-note\` first. When updating the note, you must specify not only the changed fields but also all the un-changed fields.',
|
|
188
251
|
{
|
|
189
252
|
_id: z
|
|
190
253
|
.string()
|
|
@@ -213,7 +276,9 @@ server.tool(
|
|
|
213
276
|
body: z
|
|
214
277
|
.string()
|
|
215
278
|
.max(1048576)
|
|
216
|
-
.describe(
|
|
279
|
+
.describe(
|
|
280
|
+
'The content of the note in Markdown. NOTE: Do not escape special characters like `\\n`.'
|
|
281
|
+
),
|
|
217
282
|
|
|
218
283
|
status: z
|
|
219
284
|
.enum(['none', 'active', 'onHold', 'completed', 'dropped'])
|
|
@@ -250,6 +315,18 @@ server.tool(
|
|
|
250
315
|
}
|
|
251
316
|
)
|
|
252
317
|
|
|
318
|
+
server.tool('list-tags', `Retrieve a list of all tags`, {}, async () => {
|
|
319
|
+
const books: Book[] = await fetchJSON('/tags')
|
|
320
|
+
return {
|
|
321
|
+
content: [
|
|
322
|
+
{
|
|
323
|
+
type: 'text',
|
|
324
|
+
text: JSON.stringify(books, null, 2)
|
|
325
|
+
}
|
|
326
|
+
]
|
|
327
|
+
}
|
|
328
|
+
})
|
|
329
|
+
|
|
253
330
|
server.prompt(
|
|
254
331
|
'inkdrop-prompt',
|
|
255
332
|
'Instructions for using the Inkdrop MCP server effectively',
|
|
@@ -266,6 +343,8 @@ Key capabilities:
|
|
|
266
343
|
- Search notes by keyword
|
|
267
344
|
- Get a note by its ID
|
|
268
345
|
- Get a list of all notebooks
|
|
346
|
+
- Create a new note
|
|
347
|
+
- Update an existing note
|
|
269
348
|
|
|
270
349
|
Best practices:
|
|
271
350
|
- When searching:
|
|
@@ -283,6 +362,9 @@ ${JSON.stringify(NoteSchema, null, 2)}
|
|
|
283
362
|
${JSON.stringify(BookSchema, null, 2)}
|
|
284
363
|
\`\`\`
|
|
285
364
|
|
|
365
|
+
\`\`\`json
|
|
366
|
+
${JSON.stringify(TagSchema, null, 2)}
|
|
367
|
+
\`\`\`
|
|
286
368
|
`
|
|
287
369
|
}
|
|
288
370
|
}
|
package/src/bak.ts
DELETED
|
@@ -1,433 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Example: MCP Proxy for Inkdrop's local HTTP server.
|
|
3
|
-
*
|
|
4
|
-
* Requirements:
|
|
5
|
-
* 1) Inkdrop's local server is running at config.baseUrl (e.g. http://localhost:19840).
|
|
6
|
-
* 2) A Basic auth username/password is set in Inkdrop.
|
|
7
|
-
* 3) This script can be run with `npx ts-node inkdrop-mcp-proxy.ts`.
|
|
8
|
-
* 4) Then, an MCP client (e.g. MCP Inspector, or Claude) can connect to:
|
|
9
|
-
* GET http://localhost:3002/sse (SSE endpoint)
|
|
10
|
-
* POST http://localhost:3002/messages (MCP messages endpoint)
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { URL, URLSearchParams } from "url";
|
|
14
|
-
import {
|
|
15
|
-
McpServer,
|
|
16
|
-
ResourceTemplate
|
|
17
|
-
} from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
18
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
19
|
-
import { z } from "zod";
|
|
20
|
-
|
|
21
|
-
/** Configuration for talking to Inkdrop’s local HTTP server */
|
|
22
|
-
const config = {
|
|
23
|
-
baseUrl: "http://localhost:19841", // or https://localhost:19840
|
|
24
|
-
username: "foo@bar.com",
|
|
25
|
-
password: "bar",
|
|
26
|
-
/** If Inkdrop uses self-signed cert over HTTPS, you may need to allow that. */
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/** Build the 'Authorization: Basic ...' header */
|
|
30
|
-
function getAuthHeaders() {
|
|
31
|
-
const token = Buffer.from(`${config.username}:${config.password}`).toString(
|
|
32
|
-
"base64"
|
|
33
|
-
);
|
|
34
|
-
return {
|
|
35
|
-
Authorization: `Basic ${token}`
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** Helper to attach query parameters to a given path */
|
|
40
|
-
function buildUrl(path: string, qs: Record<string, any> = {}): string {
|
|
41
|
-
const url = new URL(path, config.baseUrl);
|
|
42
|
-
for (const [k, v] of Object.entries(qs)) {
|
|
43
|
-
if (v !== undefined && v !== null) url.searchParams.set(k, String(v));
|
|
44
|
-
}
|
|
45
|
-
return url.toString();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** Helper to do a GET request and return JSON or throw an error. */
|
|
49
|
-
async function fetchJSON(path: string, qs: Record<string, any> = {}) {
|
|
50
|
-
const url = buildUrl(path, qs);
|
|
51
|
-
const resp = await fetch(url, { headers: getAuthHeaders() });
|
|
52
|
-
if (!resp.ok) {
|
|
53
|
-
throw new Error(`Fetch error [${resp.status}] ${resp.statusText}`);
|
|
54
|
-
}
|
|
55
|
-
return await resp.json();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** Helper to do a POST request with JSON body */
|
|
59
|
-
async function postJSON(path: string, body: unknown) {
|
|
60
|
-
const url = buildUrl(path);
|
|
61
|
-
const resp = await fetch(url, {
|
|
62
|
-
method: "POST",
|
|
63
|
-
headers: {
|
|
64
|
-
...getAuthHeaders(),
|
|
65
|
-
"Content-Type": "application/json"
|
|
66
|
-
},
|
|
67
|
-
body: JSON.stringify(body)
|
|
68
|
-
});
|
|
69
|
-
if (!resp.ok) {
|
|
70
|
-
throw new Error(`Fetch error [${resp.status}] ${resp.statusText}`);
|
|
71
|
-
}
|
|
72
|
-
return await resp.json();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** Helper to do a DELETE request */
|
|
76
|
-
async function deleteJSON(path: string) {
|
|
77
|
-
const url = buildUrl(path);
|
|
78
|
-
const resp = await fetch(url, {
|
|
79
|
-
method: "DELETE",
|
|
80
|
-
headers: getAuthHeaders()
|
|
81
|
-
});
|
|
82
|
-
if (!resp.ok) {
|
|
83
|
-
throw new Error(`Fetch error [${resp.status}] ${resp.statusText}`);
|
|
84
|
-
}
|
|
85
|
-
return await resp.json();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/** Create the MCP Server that proxies to Inkdrop’s local API. */
|
|
89
|
-
function createInkdropProxyServer() {
|
|
90
|
-
const server = new McpServer({
|
|
91
|
-
name: "Inkdrop MCP Proxy",
|
|
92
|
-
version: "1.0.0"
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
//
|
|
96
|
-
// 1) Root meta info (like GET "/")
|
|
97
|
-
//
|
|
98
|
-
server.resource("root", "inkdrop://root", async (uri) => {
|
|
99
|
-
const body = await fetchJSON("/");
|
|
100
|
-
return {
|
|
101
|
-
contents: [
|
|
102
|
-
{
|
|
103
|
-
uri: uri.href,
|
|
104
|
-
text: JSON.stringify(body, null, 2)
|
|
105
|
-
}
|
|
106
|
-
]
|
|
107
|
-
};
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
//
|
|
111
|
-
// 2) Notes
|
|
112
|
-
//
|
|
113
|
-
// 2a) List all notes (proxy GET /notes, with query params)
|
|
114
|
-
server.resource(
|
|
115
|
-
"notes",
|
|
116
|
-
new ResourceTemplate("inkdrop://notes{?keyword,limit,skip,sort,descending}", {
|
|
117
|
-
list: undefined
|
|
118
|
-
}),
|
|
119
|
-
async (uri) => {
|
|
120
|
-
// forward query to /notes
|
|
121
|
-
const qs = Object.fromEntries(uri.searchParams.entries());
|
|
122
|
-
const body = await fetchJSON("/notes", qs);
|
|
123
|
-
return {
|
|
124
|
-
contents: [
|
|
125
|
-
{
|
|
126
|
-
uri: uri.href,
|
|
127
|
-
text: JSON.stringify(body, null, 2)
|
|
128
|
-
}
|
|
129
|
-
]
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
// 2b) Create/update note (proxy POST /notes)
|
|
135
|
-
server.tool(
|
|
136
|
-
"save-note",
|
|
137
|
-
{
|
|
138
|
-
_id: z.string().optional(),
|
|
139
|
-
_rev: z.string().optional(),
|
|
140
|
-
doctype: z.string().optional(),
|
|
141
|
-
bookId: z.string().optional(),
|
|
142
|
-
status: z.string().optional(),
|
|
143
|
-
share: z.string().optional(),
|
|
144
|
-
title: z.string().optional(),
|
|
145
|
-
body: z.string().optional(),
|
|
146
|
-
pinned: z.boolean().optional(),
|
|
147
|
-
tags: z.array(z.string()).optional()
|
|
148
|
-
},
|
|
149
|
-
async (args) => {
|
|
150
|
-
const ret = await postJSON("/notes", args);
|
|
151
|
-
return {
|
|
152
|
-
content: [{ type: "text", text: JSON.stringify(ret, null, 2) }]
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
// 2c) Get single note (proxy GET /note:docId)
|
|
158
|
-
server.resource(
|
|
159
|
-
"single-note",
|
|
160
|
-
new ResourceTemplate("inkdrop://note/{docId}{?rev,attachments}", { list: undefined }),
|
|
161
|
-
async (uri, { docId }) => {
|
|
162
|
-
const qs = Object.fromEntries(uri.searchParams.entries());
|
|
163
|
-
const body = await fetchJSON(`/note:${docId}`, qs);
|
|
164
|
-
return {
|
|
165
|
-
contents: [
|
|
166
|
-
{
|
|
167
|
-
uri: uri.href,
|
|
168
|
-
text: JSON.stringify(body, null, 2)
|
|
169
|
-
}
|
|
170
|
-
]
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
// 2d) Delete note (proxy DELETE /note:docId)
|
|
176
|
-
server.tool(
|
|
177
|
-
"delete-note",
|
|
178
|
-
{ docId: z.string() },
|
|
179
|
-
async ({ docId }) => {
|
|
180
|
-
const ret = await deleteJSON(`/note:${docId}`);
|
|
181
|
-
return {
|
|
182
|
-
content: [{ type: "text", text: JSON.stringify(ret, null, 2) }]
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
//
|
|
188
|
-
// 3) Books (Notebooks)
|
|
189
|
-
//
|
|
190
|
-
// 3a) List notebooks (GET /books)
|
|
191
|
-
server.resource(
|
|
192
|
-
"books",
|
|
193
|
-
new ResourceTemplate("inkdrop://books{?limit,skip}", { list: undefined }),
|
|
194
|
-
async (uri) => {
|
|
195
|
-
const qs = Object.fromEntries(uri.searchParams.entries());
|
|
196
|
-
const body = await fetchJSON("/books", qs);
|
|
197
|
-
return {
|
|
198
|
-
contents: [
|
|
199
|
-
{
|
|
200
|
-
uri: uri.href,
|
|
201
|
-
text: JSON.stringify(body, null, 2)
|
|
202
|
-
}
|
|
203
|
-
]
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
// 3b) Create/update a book (POST /books)
|
|
209
|
-
server.tool(
|
|
210
|
-
"save-book",
|
|
211
|
-
{
|
|
212
|
-
_id: z.string().optional(),
|
|
213
|
-
_rev: z.string().optional(),
|
|
214
|
-
name: z.string().optional(),
|
|
215
|
-
parentBookId: z.string().optional()
|
|
216
|
-
},
|
|
217
|
-
async (args) => {
|
|
218
|
-
const ret = await postJSON("/books", args);
|
|
219
|
-
return {
|
|
220
|
-
content: [{ type: "text", text: JSON.stringify(ret, null, 2) }]
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
);
|
|
224
|
-
|
|
225
|
-
// 3c) Get a single book (GET /book:docId)
|
|
226
|
-
server.resource(
|
|
227
|
-
"single-book",
|
|
228
|
-
new ResourceTemplate("inkdrop://book/{docId}{?rev,attachments}", { list: undefined }),
|
|
229
|
-
async (uri, { docId }) => {
|
|
230
|
-
const qs = Object.fromEntries(uri.searchParams.entries());
|
|
231
|
-
const body = await fetchJSON(`/book:${docId}`, qs);
|
|
232
|
-
return {
|
|
233
|
-
contents: [
|
|
234
|
-
{
|
|
235
|
-
uri: uri.href,
|
|
236
|
-
text: JSON.stringify(body, null, 2)
|
|
237
|
-
}
|
|
238
|
-
]
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
);
|
|
242
|
-
|
|
243
|
-
// 3d) Delete book (DELETE /book:docId)
|
|
244
|
-
server.tool(
|
|
245
|
-
"delete-book",
|
|
246
|
-
{ docId: z.string() },
|
|
247
|
-
async ({ docId }) => {
|
|
248
|
-
const ret = await deleteJSON(`/book:${docId}`);
|
|
249
|
-
return {
|
|
250
|
-
content: [{ type: "text", text: JSON.stringify(ret, null, 2) }]
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
);
|
|
254
|
-
|
|
255
|
-
//
|
|
256
|
-
// 4) Tags
|
|
257
|
-
//
|
|
258
|
-
// 4a) List tags (GET /tags)
|
|
259
|
-
server.resource(
|
|
260
|
-
"tags",
|
|
261
|
-
new ResourceTemplate("inkdrop://tags{?limit,skip}", { list: undefined }),
|
|
262
|
-
async (uri) => {
|
|
263
|
-
const qs = Object.fromEntries(uri.searchParams.entries());
|
|
264
|
-
const body = await fetchJSON("/tags", qs);
|
|
265
|
-
return {
|
|
266
|
-
contents: [
|
|
267
|
-
{
|
|
268
|
-
uri: uri.href,
|
|
269
|
-
text: JSON.stringify(body, null, 2)
|
|
270
|
-
}
|
|
271
|
-
]
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
);
|
|
275
|
-
|
|
276
|
-
// 4b) Create/update tag (POST /tags)
|
|
277
|
-
server.tool(
|
|
278
|
-
"save-tag",
|
|
279
|
-
{
|
|
280
|
-
_id: z.string().optional(),
|
|
281
|
-
_rev: z.string().optional(),
|
|
282
|
-
name: z.string(),
|
|
283
|
-
color: z.string().optional()
|
|
284
|
-
},
|
|
285
|
-
async (args) => {
|
|
286
|
-
const ret = await postJSON("/tags", args);
|
|
287
|
-
return {
|
|
288
|
-
content: [{ type: "text", text: JSON.stringify(ret, null, 2) }]
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
);
|
|
292
|
-
|
|
293
|
-
// 4c) Get tag (GET /tag:docId)
|
|
294
|
-
server.resource(
|
|
295
|
-
"single-tag",
|
|
296
|
-
new ResourceTemplate("inkdrop://tag/{docId}{?rev,attachments}", { list: undefined }),
|
|
297
|
-
async (uri, { docId }) => {
|
|
298
|
-
const qs = Object.fromEntries(uri.searchParams.entries());
|
|
299
|
-
const body = await fetchJSON(`/tag:${docId}`, qs);
|
|
300
|
-
return {
|
|
301
|
-
contents: [
|
|
302
|
-
{
|
|
303
|
-
uri: uri.href,
|
|
304
|
-
text: JSON.stringify(body, null, 2)
|
|
305
|
-
}
|
|
306
|
-
]
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
);
|
|
310
|
-
|
|
311
|
-
// 4d) Delete tag (DELETE /tag:docId)
|
|
312
|
-
server.tool(
|
|
313
|
-
"delete-tag",
|
|
314
|
-
{ docId: z.string() },
|
|
315
|
-
async ({ docId }) => {
|
|
316
|
-
const ret = await deleteJSON(`/tag:${docId}`);
|
|
317
|
-
return {
|
|
318
|
-
content: [{ type: "text", text: JSON.stringify(ret, null, 2) }]
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
);
|
|
322
|
-
|
|
323
|
-
//
|
|
324
|
-
// 5) Files
|
|
325
|
-
//
|
|
326
|
-
// 5a) List files (GET /files)
|
|
327
|
-
server.resource(
|
|
328
|
-
"files",
|
|
329
|
-
new ResourceTemplate("inkdrop://files{?limit,skip}", { list: undefined }),
|
|
330
|
-
async (uri) => {
|
|
331
|
-
const qs = Object.fromEntries(uri.searchParams.entries());
|
|
332
|
-
const body = await fetchJSON("/files", qs);
|
|
333
|
-
return {
|
|
334
|
-
contents: [
|
|
335
|
-
{
|
|
336
|
-
uri: uri.href,
|
|
337
|
-
text: JSON.stringify(body, null, 2)
|
|
338
|
-
}
|
|
339
|
-
]
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
);
|
|
343
|
-
|
|
344
|
-
// 5b) Create/update file (POST /files)
|
|
345
|
-
server.tool(
|
|
346
|
-
"save-file",
|
|
347
|
-
{
|
|
348
|
-
_id: z.string().optional(),
|
|
349
|
-
_rev: z.string().optional(),
|
|
350
|
-
name: z.string(),
|
|
351
|
-
contentType: z.string().optional(),
|
|
352
|
-
contentLength: z.number().optional(),
|
|
353
|
-
publicIn: z.array(z.string()).optional(),
|
|
354
|
-
_attachments: z.any().optional()
|
|
355
|
-
},
|
|
356
|
-
async (args) => {
|
|
357
|
-
const ret = await postJSON("/files", args);
|
|
358
|
-
return {
|
|
359
|
-
content: [{ type: "text", text: JSON.stringify(ret, null, 2) }]
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
);
|
|
363
|
-
|
|
364
|
-
// 5c) Get file (GET /file:docId)
|
|
365
|
-
server.resource(
|
|
366
|
-
"single-file",
|
|
367
|
-
new ResourceTemplate("inkdrop://file/{docId}{?rev,attachments}", { list: undefined }),
|
|
368
|
-
async (uri, { docId }) => {
|
|
369
|
-
const qs = Object.fromEntries(uri.searchParams.entries());
|
|
370
|
-
const body = await fetchJSON(`/file:${docId}`, qs);
|
|
371
|
-
return {
|
|
372
|
-
contents: [
|
|
373
|
-
{
|
|
374
|
-
uri: uri.href,
|
|
375
|
-
text: JSON.stringify(body, null, 2)
|
|
376
|
-
}
|
|
377
|
-
]
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
);
|
|
381
|
-
|
|
382
|
-
// 5d) Delete file (DELETE /file:docId)
|
|
383
|
-
server.tool(
|
|
384
|
-
"delete-file",
|
|
385
|
-
{ docId: z.string() },
|
|
386
|
-
async ({ docId }) => {
|
|
387
|
-
const ret = await deleteJSON(`/file:${docId}`);
|
|
388
|
-
return {
|
|
389
|
-
content: [{ type: "text", text: JSON.stringify(ret, null, 2) }]
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
);
|
|
393
|
-
|
|
394
|
-
//
|
|
395
|
-
// 6) Changes feed (GET /_changes)
|
|
396
|
-
//
|
|
397
|
-
server.resource(
|
|
398
|
-
"changes",
|
|
399
|
-
new ResourceTemplate(
|
|
400
|
-
"inkdrop://changes{?descending,since,limit,include_docs,conflicts,attachments}",
|
|
401
|
-
{ list: undefined }
|
|
402
|
-
),
|
|
403
|
-
async (uri) => {
|
|
404
|
-
const qs = Object.fromEntries(uri.searchParams.entries());
|
|
405
|
-
const body = await fetchJSON("/_changes", qs);
|
|
406
|
-
return {
|
|
407
|
-
contents: [
|
|
408
|
-
{
|
|
409
|
-
uri: uri.href,
|
|
410
|
-
text: JSON.stringify(body, null, 2)
|
|
411
|
-
}
|
|
412
|
-
]
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
);
|
|
416
|
-
|
|
417
|
-
// Done! We have a resource/tool for every Inkdrop endpoint.
|
|
418
|
-
return server;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
/** Actually run an HTTP server exposing this MCP server over SSE and POST. */
|
|
422
|
-
async function main() {
|
|
423
|
-
const mcpServer = createInkdropProxyServer();
|
|
424
|
-
const transport = new StdioServerTransport();
|
|
425
|
-
console.log("MCP (stdio) proxy for Inkdrop is now running...");
|
|
426
|
-
console.log("Send MCP requests on stdin, responses come out on stdout.\n");
|
|
427
|
-
await mcpServer.connect(transport);
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
main().catch((err) => {
|
|
431
|
-
console.error("Error starting proxy:", err);
|
|
432
|
-
process.exit(1);
|
|
433
|
-
});
|