@inkdropapp/mcp-server 1.1.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +7 -0
- package/.github/workflows/claude-code-review.yml +78 -0
- package/.github/workflows/claude.yml +64 -0
- package/README.md +30 -5
- package/dist/index.js +246 -85
- package/package.json +8 -7
- package/src/index.ts +343 -121
- package/tsconfig.json +2 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
name: Claude Code Review
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
types: [opened, synchronize]
|
|
6
|
+
# Optional: Only run on specific file changes
|
|
7
|
+
# paths:
|
|
8
|
+
# - "src/**/*.ts"
|
|
9
|
+
# - "src/**/*.tsx"
|
|
10
|
+
# - "src/**/*.js"
|
|
11
|
+
# - "src/**/*.jsx"
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
claude-review:
|
|
15
|
+
# Optional: Filter by PR author
|
|
16
|
+
# if: |
|
|
17
|
+
# github.event.pull_request.user.login == 'external-contributor' ||
|
|
18
|
+
# github.event.pull_request.user.login == 'new-developer' ||
|
|
19
|
+
# github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR'
|
|
20
|
+
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
permissions:
|
|
23
|
+
contents: read
|
|
24
|
+
pull-requests: read
|
|
25
|
+
issues: read
|
|
26
|
+
id-token: write
|
|
27
|
+
|
|
28
|
+
steps:
|
|
29
|
+
- name: Checkout repository
|
|
30
|
+
uses: actions/checkout@v4
|
|
31
|
+
with:
|
|
32
|
+
fetch-depth: 1
|
|
33
|
+
|
|
34
|
+
- name: Run Claude Code Review
|
|
35
|
+
id: claude-review
|
|
36
|
+
uses: anthropics/claude-code-action@beta
|
|
37
|
+
with:
|
|
38
|
+
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
|
|
39
|
+
|
|
40
|
+
# Optional: Specify model (defaults to Claude Sonnet 4, uncomment for Claude Opus 4)
|
|
41
|
+
# model: "claude-opus-4-20250514"
|
|
42
|
+
|
|
43
|
+
# Direct prompt for automated review (no @claude mention needed)
|
|
44
|
+
direct_prompt: |
|
|
45
|
+
Please review this pull request and provide feedback on:
|
|
46
|
+
- Code quality and best practices
|
|
47
|
+
- Potential bugs or issues
|
|
48
|
+
- Performance considerations
|
|
49
|
+
- Security concerns
|
|
50
|
+
- Test coverage
|
|
51
|
+
|
|
52
|
+
Be constructive and helpful in your feedback.
|
|
53
|
+
|
|
54
|
+
# Optional: Use sticky comments to make Claude reuse the same comment on subsequent pushes to the same PR
|
|
55
|
+
# use_sticky_comment: true
|
|
56
|
+
|
|
57
|
+
# Optional: Customize review based on file types
|
|
58
|
+
# direct_prompt: |
|
|
59
|
+
# Review this PR focusing on:
|
|
60
|
+
# - For TypeScript files: Type safety and proper interface usage
|
|
61
|
+
# - For API endpoints: Security, input validation, and error handling
|
|
62
|
+
# - For React components: Performance, accessibility, and best practices
|
|
63
|
+
# - For tests: Coverage, edge cases, and test quality
|
|
64
|
+
|
|
65
|
+
# Optional: Different prompts for different authors
|
|
66
|
+
# direct_prompt: |
|
|
67
|
+
# ${{ github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' &&
|
|
68
|
+
# 'Welcome! Please review this PR from a first-time contributor. Be encouraging and provide detailed explanations for any suggestions.' ||
|
|
69
|
+
# 'Please provide a thorough code review focusing on our coding standards and best practices.' }}
|
|
70
|
+
|
|
71
|
+
# Optional: Add specific tools for running tests or linting
|
|
72
|
+
# allowed_tools: "Bash(npm run test),Bash(npm run lint),Bash(npm run typecheck)"
|
|
73
|
+
|
|
74
|
+
# Optional: Skip review for certain conditions
|
|
75
|
+
# if: |
|
|
76
|
+
# !contains(github.event.pull_request.title, '[skip-review]') &&
|
|
77
|
+
# !contains(github.event.pull_request.title, '[WIP]')
|
|
78
|
+
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
name: Claude Code
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
issue_comment:
|
|
5
|
+
types: [created]
|
|
6
|
+
pull_request_review_comment:
|
|
7
|
+
types: [created]
|
|
8
|
+
issues:
|
|
9
|
+
types: [opened, assigned]
|
|
10
|
+
pull_request_review:
|
|
11
|
+
types: [submitted]
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
claude:
|
|
15
|
+
if: |
|
|
16
|
+
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
|
|
17
|
+
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
|
|
18
|
+
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
|
|
19
|
+
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
|
|
20
|
+
runs-on: ubuntu-latest
|
|
21
|
+
permissions:
|
|
22
|
+
contents: read
|
|
23
|
+
pull-requests: read
|
|
24
|
+
issues: read
|
|
25
|
+
id-token: write
|
|
26
|
+
actions: read # Required for Claude to read CI results on PRs
|
|
27
|
+
steps:
|
|
28
|
+
- name: Checkout repository
|
|
29
|
+
uses: actions/checkout@v4
|
|
30
|
+
with:
|
|
31
|
+
fetch-depth: 1
|
|
32
|
+
|
|
33
|
+
- name: Run Claude Code
|
|
34
|
+
id: claude
|
|
35
|
+
uses: anthropics/claude-code-action@beta
|
|
36
|
+
with:
|
|
37
|
+
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
|
|
38
|
+
|
|
39
|
+
# This is an optional setting that allows Claude to read CI results on PRs
|
|
40
|
+
additional_permissions: |
|
|
41
|
+
actions: read
|
|
42
|
+
|
|
43
|
+
# Optional: Specify model (defaults to Claude Sonnet 4, uncomment for Claude Opus 4)
|
|
44
|
+
# model: "claude-opus-4-20250514"
|
|
45
|
+
|
|
46
|
+
# Optional: Customize the trigger phrase (default: @claude)
|
|
47
|
+
# trigger_phrase: "/claude"
|
|
48
|
+
|
|
49
|
+
# Optional: Trigger when specific user is assigned to an issue
|
|
50
|
+
# assignee_trigger: "claude-bot"
|
|
51
|
+
|
|
52
|
+
# Optional: Allow Claude to run specific commands
|
|
53
|
+
# allowed_tools: "Bash(npm install),Bash(npm run build),Bash(npm run test:*),Bash(npm run lint:*)"
|
|
54
|
+
|
|
55
|
+
# Optional: Add custom instructions for Claude to customize its behavior for your project
|
|
56
|
+
# custom_instructions: |
|
|
57
|
+
# Follow our coding standards
|
|
58
|
+
# Ensure all new code has tests
|
|
59
|
+
# Use TypeScript for new files
|
|
60
|
+
|
|
61
|
+
# Optional: Custom environment variables for Claude
|
|
62
|
+
# claude_env: |
|
|
63
|
+
# NODE_ENV: test
|
|
64
|
+
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ A [Model Context Protocol](https://github.com/modelcontextprotocol) server for t
|
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
11
|
-
1. [Set up a local HTTP server](https://developers.inkdrop.app/guides/
|
|
11
|
+
1. [Set up a local HTTP server](https://developers.inkdrop.app/guides/integrate-with-external-programs)
|
|
12
12
|
|
|
13
13
|
2. Add server config to Claude Desktop:
|
|
14
14
|
- MacOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
@@ -58,17 +58,42 @@ A [Model Context Protocol](https://github.com/modelcontextprotocol) server for t
|
|
|
58
58
|
- `body`: The content of the note in Markdown.
|
|
59
59
|
- Optional inputs:
|
|
60
60
|
- `status`: The note status (`none`, `active`, `onHold`, `completed`, `dropped`).
|
|
61
|
-
|
|
61
|
+
- `tags`: An array of tag IDs to assign to the note. Each must start with 'tag:'.
|
|
62
|
+
5. **`update-note`**: Update an existing note in the database. Only the fields you provide will be updated; omitted fields remain unchanged.
|
|
62
63
|
- Required inputs:
|
|
63
64
|
- `_id`: The note ID. Must start with 'note:'.
|
|
64
65
|
- `_rev`: The revision ID (CouchDB MVCC-token).
|
|
66
|
+
- Optional inputs:
|
|
65
67
|
- `bookId`: The notebook ID. Must start with 'book:' or be 'trash'.
|
|
66
68
|
- `title`: The note title.
|
|
67
69
|
- `body`: The content of the note in Markdown.
|
|
68
|
-
- Optional inputs:
|
|
69
70
|
- `status`: The note status (`none`, `active`, `onHold`, `completed`, `dropped`).
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
- `tags`: An array of tag IDs to assign to the note. Each must start with 'tag:'.
|
|
72
|
+
6. **`patch-note`**: Update the body of an existing note by applying a unified diff patch. More efficient than `update-note` for small edits to large notes as it saves tokens.
|
|
73
|
+
- Required inputs:
|
|
74
|
+
- `_id`: The note ID. Must start with 'note:'.
|
|
75
|
+
- `_rev`: The revision ID (CouchDB MVCC-token).
|
|
76
|
+
- `patch`: A unified diff string to apply to the note body. Use standard unified diff format with `---`/`+++` headers and `@@ -start,count +start,count @@` hunk markers.
|
|
77
|
+
7. **`list-notebooks`**: Retrieve a list of all notebooks.
|
|
78
|
+
8. **`read-book`**: Retrieve a single notebook by its ID.
|
|
79
|
+
- Required inputs:
|
|
80
|
+
- `bookId`: The notebook ID. Must start with 'book:'.
|
|
81
|
+
9. **`list-tags`**: Retrieve a list of all tags.
|
|
82
|
+
10. **`read-tag`**: Retrieve a single tag by its ID.
|
|
83
|
+
- Required inputs:
|
|
84
|
+
- `tagId`: The tag ID. Must start with 'tag:'.
|
|
85
|
+
11. **`create-tag`**: Create a new tag in the database.
|
|
86
|
+
- Required inputs:
|
|
87
|
+
- `name`: The name of the tag.
|
|
88
|
+
- Optional inputs:
|
|
89
|
+
- `color`: The color type of the tag (`default`, `red`, `orange`, `yellow`, `olive`, `green`, `teal`, `blue`, `violet`, `purple`, `pink`, `brown`, `grey`, `black`). Default: `default`.
|
|
90
|
+
12. **`update-tag`**: Update an existing tag in the database.
|
|
91
|
+
- Required inputs:
|
|
92
|
+
- `_id`: The tag ID. Must start with 'tag:'.
|
|
93
|
+
- `_rev`: The revision ID (CouchDB MVCC-token).
|
|
94
|
+
- `name`: The name of the tag.
|
|
95
|
+
- Optional inputs:
|
|
96
|
+
- `color`: The color type of the tag. Default: `default`.
|
|
72
97
|
|
|
73
98
|
## Debugging
|
|
74
99
|
|
package/dist/index.js
CHANGED
|
@@ -5,12 +5,13 @@ 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");
|
|
8
9
|
const api_1 = require("./api");
|
|
9
10
|
const server = new mcp_js_1.McpServer({
|
|
10
11
|
name: 'Inkdrop',
|
|
11
|
-
version: '1.
|
|
12
|
+
version: '1.3.0'
|
|
12
13
|
});
|
|
13
|
-
server.
|
|
14
|
+
server.registerResource('note', new mcp_js_1.ResourceTemplate('inkdrop://note/{noteId}', { list: undefined }), {
|
|
14
15
|
description: 'A note data',
|
|
15
16
|
mimeType: 'application/json'
|
|
16
17
|
}, async (uri, { noteId }) => {
|
|
@@ -25,10 +26,13 @@ server.resource('note', new mcp_js_1.ResourceTemplate('inkdrop://note/{noteId}',
|
|
|
25
26
|
]
|
|
26
27
|
};
|
|
27
28
|
});
|
|
28
|
-
server.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
server.registerTool('read-note', {
|
|
30
|
+
description: 'Retrieve the complete contents of the note by its ID from the database.',
|
|
31
|
+
inputSchema: {
|
|
32
|
+
noteId: zod_1.z
|
|
33
|
+
.string()
|
|
34
|
+
.describe('ID of the note to retrieve. It can be found as `_id` in the note docs. It always starts with \`note:\`.')
|
|
35
|
+
}
|
|
32
36
|
}, async ({ noteId }) => {
|
|
33
37
|
if (!noteId.startsWith('note:'))
|
|
34
38
|
noteId = `note:${noteId}`;
|
|
@@ -42,7 +46,8 @@ server.tool('read-note', 'Retrieve the complete contents of the note by its ID f
|
|
|
42
46
|
]
|
|
43
47
|
};
|
|
44
48
|
});
|
|
45
|
-
server.
|
|
49
|
+
server.registerTool('search-notes', {
|
|
50
|
+
description: `List all notes that contain a given keyword.
|
|
46
51
|
The result does not include entire note bodies as they are truncated in 200 characters.
|
|
47
52
|
You have to retrieve the full note content by calling \`read-note\`.
|
|
48
53
|
Here are tips to specify keywords effectively:
|
|
@@ -51,18 +56,18 @@ Here are tips to specify keywords effectively:
|
|
|
51
56
|
|
|
52
57
|
You can use special qualifiers to get more accurate results. See the qualifiers and their usage examples:
|
|
53
58
|
|
|
54
|
-
- **book**
|
|
59
|
+
- **book**
|
|
55
60
|
\`book:Blog\`: Searches for notes in the 'Blog' notebook.
|
|
56
61
|
\`book:"Desktop App"\`: Searches for notes in the 'Desktop App' notebook.
|
|
57
62
|
- **bookId**
|
|
58
63
|
\`bookId:kGlLniaV\`: Searches for notes in the notebook ID 'book:kGlLniaV'.
|
|
59
|
-
- **tag**
|
|
64
|
+
- **tag**
|
|
60
65
|
\`tag:JavaScript\`: Searches for all notes having the 'JavaScript' tag. Read more about [tags](https://docs.inkdrop.app/manual/write-notes#tag-notes).
|
|
61
|
-
- **status**
|
|
66
|
+
- **status**
|
|
62
67
|
\`status:onHold\`: Searches for all notes with the 'On hold' status. Read more about [statuses](/reference/note-statuses).
|
|
63
|
-
- **title**
|
|
68
|
+
- **title**
|
|
64
69
|
\`title:"JavaScript setTimeout"\`: Searches for the note with the specified title.
|
|
65
|
-
- **body**
|
|
70
|
+
- **body**
|
|
66
71
|
\`body:KEYWORD\`: Searches for a specific word in all notes. Equivalent to a [global search](#search-for-notes-across-all-notebooks).
|
|
67
72
|
|
|
68
73
|
### Combine qualifiers
|
|
@@ -103,13 +108,15 @@ Note that you can't specify excluding modifiers only without including condition
|
|
|
103
108
|
|
|
104
109
|
**WARNING**: Make sure to enter a text to search for after the exclusion modifier.
|
|
105
110
|
|
|
106
|
-
- ✅ Will work
|
|
111
|
+
- ✅ Will work
|
|
107
112
|
\`-book:Backend "closure functions"\`
|
|
108
113
|
|
|
109
|
-
- ⛔️ Won't work
|
|
114
|
+
- ⛔️ Won't work
|
|
110
115
|
\`-book:Backend\`. There's no query. Inkdrop doesn't understand what to search for.
|
|
111
|
-
`,
|
|
112
|
-
|
|
116
|
+
`,
|
|
117
|
+
inputSchema: {
|
|
118
|
+
keyword: zod_1.z.string().describe(`Keyword to search for.`)
|
|
119
|
+
}
|
|
113
120
|
}, async ({ keyword }) => {
|
|
114
121
|
const notes = await (0, api_1.fetchJSON)('/notes', { keyword, limit: 10 });
|
|
115
122
|
const summaries = notes.map(note => {
|
|
@@ -127,30 +134,33 @@ Note that you can't specify excluding modifiers only without including condition
|
|
|
127
134
|
]
|
|
128
135
|
};
|
|
129
136
|
});
|
|
130
|
-
server.
|
|
137
|
+
server.registerTool('list-notes', {
|
|
138
|
+
description: `List all notes with specified conditions.
|
|
131
139
|
The result does not include entire note bodies as they are truncated in 200 characters.
|
|
132
140
|
You have to retrieve the full note content by calling \`read-note\`.
|
|
133
|
-
`,
|
|
134
|
-
|
|
135
|
-
.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
.
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
141
|
+
`,
|
|
142
|
+
inputSchema: {
|
|
143
|
+
bookId: zod_1.z
|
|
144
|
+
.string()
|
|
145
|
+
.optional()
|
|
146
|
+
.describe(`ID of the notebook. It always starts with 'book:'. You can retrieve a list of notebooks with \`list-notebooks\``),
|
|
147
|
+
tagIds: zod_1.z
|
|
148
|
+
.array(zod_1.z.string())
|
|
149
|
+
.optional()
|
|
150
|
+
.default([])
|
|
151
|
+
.describe(`An array of tag IDs to filter. It always starts with 'tag:'. You can retrieve a list of available tags from \`list-tags\`.`),
|
|
152
|
+
keyword: zod_1.z.string().optional().describe(`Keyword to filter notes`),
|
|
153
|
+
sort: zod_1.z
|
|
154
|
+
.enum(['updatedAt', 'createdAt', 'title'])
|
|
155
|
+
.optional()
|
|
156
|
+
.default('updatedAt')
|
|
157
|
+
.describe(`Sort the documents by the specified field`),
|
|
158
|
+
descending: zod_1.z
|
|
159
|
+
.boolean()
|
|
160
|
+
.optional()
|
|
161
|
+
.default(true)
|
|
162
|
+
.describe(`Reverse the order of the output documents`)
|
|
163
|
+
}
|
|
154
164
|
}, async ({ bookId, tagIds, keyword, sort, descending }) => {
|
|
155
165
|
const bookFilter = bookId ? `bookId:${bookId.split(':')[1]}` : '';
|
|
156
166
|
const tagFilter = tagIds ? tagIds.map(t => `tagId:${t}`).join(' ') : '';
|
|
@@ -176,22 +186,29 @@ You have to retrieve the full note content by calling \`read-note\`.
|
|
|
176
186
|
]
|
|
177
187
|
};
|
|
178
188
|
});
|
|
179
|
-
server.
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
.string()
|
|
189
|
-
.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
.
|
|
194
|
-
|
|
189
|
+
server.registerTool('create-note', {
|
|
190
|
+
description: 'Create a new note in the database',
|
|
191
|
+
inputSchema: {
|
|
192
|
+
bookId: zod_1.z
|
|
193
|
+
.string()
|
|
194
|
+
.min(5)
|
|
195
|
+
.max(128)
|
|
196
|
+
.regex(/^(book:|trash$)/)
|
|
197
|
+
.describe('The notebook ID'),
|
|
198
|
+
title: zod_1.z.string().max(128).describe('The note title'),
|
|
199
|
+
body: zod_1.z
|
|
200
|
+
.string()
|
|
201
|
+
.max(1048576)
|
|
202
|
+
.describe('The content of the note represented with Markdown'),
|
|
203
|
+
status: zod_1.z
|
|
204
|
+
.enum(['none', 'active', 'onHold', 'completed', 'dropped'])
|
|
205
|
+
.optional()
|
|
206
|
+
.describe('The status of the note'),
|
|
207
|
+
tags: zod_1.z
|
|
208
|
+
.array(zod_1.z.string().startsWith('tag:'))
|
|
209
|
+
.optional()
|
|
210
|
+
.describe('An array of tag IDs to assign to the note. Call `list-tags` or `read-tag` to retrieve available tags. You can create a new tag with `create-tag` tool if necessary.')
|
|
211
|
+
}
|
|
195
212
|
}, async (noteData) => {
|
|
196
213
|
const res = await (0, api_1.postJSON)(`/notes`, noteData);
|
|
197
214
|
return {
|
|
@@ -203,33 +220,168 @@ server.tool('create-note', 'Create a new note in the database', {
|
|
|
203
220
|
]
|
|
204
221
|
};
|
|
205
222
|
});
|
|
206
|
-
server.
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
.
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
.
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
.max(
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
223
|
+
server.registerTool('update-note', {
|
|
224
|
+
description: 'Update the existing note in the database. Only the fields you provide will be updated; omitted fields remain unchanged.',
|
|
225
|
+
inputSchema: {
|
|
226
|
+
_id: zod_1.z
|
|
227
|
+
.string()
|
|
228
|
+
.min(6)
|
|
229
|
+
.max(128)
|
|
230
|
+
.regex(/^note:/)
|
|
231
|
+
.describe('The unique document ID which should start with `note:` and the remains are randomly generated string'),
|
|
232
|
+
_rev: zod_1.z
|
|
233
|
+
.string()
|
|
234
|
+
.describe('This is a CouchDB specific field. The current MVCC-token/revision of this document (mandatory and immutable).'),
|
|
235
|
+
bookId: zod_1.z
|
|
236
|
+
.string()
|
|
237
|
+
.min(5)
|
|
238
|
+
.max(128)
|
|
239
|
+
.regex(/^(book:|trash$)/)
|
|
240
|
+
.optional()
|
|
241
|
+
.describe('The notebook ID'),
|
|
242
|
+
title: zod_1.z.string().max(128).optional().describe('The note title'),
|
|
243
|
+
body: zod_1.z
|
|
244
|
+
.string()
|
|
245
|
+
.max(1048576)
|
|
246
|
+
.optional()
|
|
247
|
+
.describe('The content of the note in Markdown. NOTE: Do not escape special characters like `\\n`.'),
|
|
248
|
+
status: zod_1.z
|
|
249
|
+
.enum(['none', 'active', 'onHold', 'completed', 'dropped'])
|
|
250
|
+
.optional()
|
|
251
|
+
.describe('The status of the note'),
|
|
252
|
+
tags: zod_1.z
|
|
253
|
+
.array(zod_1.z.string().startsWith('tag:'))
|
|
254
|
+
.optional()
|
|
255
|
+
.describe('An array of tag IDs to assign to the note. Call `list-tags` or `read-tag` to retrieve available tags. You can create a new tag with `create-tag` tool if necessary.')
|
|
256
|
+
}
|
|
231
257
|
}, async (noteData) => {
|
|
232
|
-
const
|
|
258
|
+
const rev = noteData._rev;
|
|
259
|
+
const existingNote = await (0, api_1.fetchJSON)(`/${noteData._id}`, { rev });
|
|
260
|
+
const res = await (0, api_1.postJSON)(`/notes`, {
|
|
261
|
+
...existingNote,
|
|
262
|
+
...noteData
|
|
263
|
+
});
|
|
264
|
+
return {
|
|
265
|
+
content: [
|
|
266
|
+
{
|
|
267
|
+
type: 'text',
|
|
268
|
+
text: JSON.stringify(res, null, 2)
|
|
269
|
+
}
|
|
270
|
+
]
|
|
271
|
+
};
|
|
272
|
+
});
|
|
273
|
+
server.registerTool('patch-note', {
|
|
274
|
+
description: 'Update the body of the existing note by applying a diff patch in the database. You should use this tool when you want to make partial updates to the note body without replacing the entire content because it is much more efficient for saving token window.',
|
|
275
|
+
inputSchema: {
|
|
276
|
+
_id: zod_1.z
|
|
277
|
+
.string()
|
|
278
|
+
.min(6)
|
|
279
|
+
.max(128)
|
|
280
|
+
.regex(/^note:/)
|
|
281
|
+
.describe('The unique document ID which should start with `note:` and the remains are randomly generated string'),
|
|
282
|
+
_rev: zod_1.z
|
|
283
|
+
.string()
|
|
284
|
+
.describe('This is a CouchDB specific field. The current MVCC-token/revision of this document (mandatory and immutable).'),
|
|
285
|
+
patch: zod_1.z
|
|
286
|
+
.string()
|
|
287
|
+
.describe('A unified diff string to apply to the note body. Use standard unified diff format with `---`/`+++` headers and `@@ -start,count +start,count @@` hunk markers.')
|
|
288
|
+
}
|
|
289
|
+
}, async ({ _id, _rev, patch }) => {
|
|
290
|
+
const existingNote = await (0, api_1.fetchJSON)(`/${_id}`, { rev: _rev });
|
|
291
|
+
const patched = (0, diff_1.applyPatch)(existingNote.body, patch);
|
|
292
|
+
if (patched === false) {
|
|
293
|
+
return {
|
|
294
|
+
content: [
|
|
295
|
+
{
|
|
296
|
+
type: 'text',
|
|
297
|
+
text: 'Failed to apply the patch. The diff may be malformed or does not match the current note body.'
|
|
298
|
+
}
|
|
299
|
+
],
|
|
300
|
+
isError: true
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
const res = await (0, api_1.postJSON)('/notes', { ...existingNote, body: patched });
|
|
304
|
+
return {
|
|
305
|
+
content: [
|
|
306
|
+
{
|
|
307
|
+
type: 'text',
|
|
308
|
+
text: JSON.stringify(res, null, 2)
|
|
309
|
+
}
|
|
310
|
+
]
|
|
311
|
+
};
|
|
312
|
+
});
|
|
313
|
+
server.registerTool('list-tags', { description: 'Retrieve a list of all tags' }, async () => {
|
|
314
|
+
const tags = await (0, api_1.fetchJSON)('/tags');
|
|
315
|
+
return {
|
|
316
|
+
content: [
|
|
317
|
+
{
|
|
318
|
+
type: 'text',
|
|
319
|
+
text: JSON.stringify(tags, null, 2)
|
|
320
|
+
}
|
|
321
|
+
]
|
|
322
|
+
};
|
|
323
|
+
});
|
|
324
|
+
server.registerTool('read-tag', {
|
|
325
|
+
description: 'Retrieve a single tag',
|
|
326
|
+
inputSchema: {
|
|
327
|
+
tagId: zod_1.z
|
|
328
|
+
.string()
|
|
329
|
+
.describe('ID of the tag to retrieve. It can be found as `_id` in the tag docs. It always starts with \`tag:\`.')
|
|
330
|
+
}
|
|
331
|
+
}, async ({ tagId }) => {
|
|
332
|
+
if (!tagId.startsWith('tag:'))
|
|
333
|
+
tagId = `tag:${tagId}`;
|
|
334
|
+
const tag = await (0, api_1.fetchJSON)(`/${tagId}`, {});
|
|
335
|
+
return {
|
|
336
|
+
content: [
|
|
337
|
+
{
|
|
338
|
+
type: 'text',
|
|
339
|
+
text: JSON.stringify(tag, null, 2)
|
|
340
|
+
}
|
|
341
|
+
]
|
|
342
|
+
};
|
|
343
|
+
});
|
|
344
|
+
const TagColors = Object.values(inkdrop_model_1.TAG_COLOR);
|
|
345
|
+
server.registerTool('create-tag', {
|
|
346
|
+
description: 'Create a new tag in the database',
|
|
347
|
+
inputSchema: {
|
|
348
|
+
color: zod_1.z
|
|
349
|
+
.enum(TagColors)
|
|
350
|
+
.default('default')
|
|
351
|
+
.describe('The color type of the tag'),
|
|
352
|
+
name: zod_1.z.string().max(64).describe('The name of the tag')
|
|
353
|
+
}
|
|
354
|
+
}, async (tagData) => {
|
|
355
|
+
const res = await (0, api_1.postJSON)(`/tags`, tagData);
|
|
356
|
+
return {
|
|
357
|
+
content: [
|
|
358
|
+
{
|
|
359
|
+
type: 'text',
|
|
360
|
+
text: JSON.stringify(res, null, 2)
|
|
361
|
+
}
|
|
362
|
+
]
|
|
363
|
+
};
|
|
364
|
+
});
|
|
365
|
+
server.registerTool('update-tag', {
|
|
366
|
+
description: 'Update the existing tag in the database. You should retrieve the existing tag with \`list-tags\` first. When updating the tag, you must specify not only the changed fields but also all the un-changed fields.',
|
|
367
|
+
inputSchema: {
|
|
368
|
+
_id: zod_1.z
|
|
369
|
+
.string()
|
|
370
|
+
.min(6)
|
|
371
|
+
.max(128)
|
|
372
|
+
.regex(/^tag:/)
|
|
373
|
+
.describe('The unique document ID which should start with `tag:` and the remains are randomly generated string'),
|
|
374
|
+
_rev: zod_1.z
|
|
375
|
+
.string()
|
|
376
|
+
.describe('This is a CouchDB specific field. The current MVCC-token/revision of this document (mandatory and immutable).'),
|
|
377
|
+
color: zod_1.z
|
|
378
|
+
.enum(TagColors)
|
|
379
|
+
.default('default')
|
|
380
|
+
.describe('The color type of the tag'),
|
|
381
|
+
name: zod_1.z.string().max(64).describe('The name of the tag')
|
|
382
|
+
}
|
|
383
|
+
}, async (tagData) => {
|
|
384
|
+
const res = await (0, api_1.postJSON)(`/tags`, tagData);
|
|
233
385
|
return {
|
|
234
386
|
content: [
|
|
235
387
|
{
|
|
@@ -239,7 +391,7 @@ server.tool('update-note', 'Update the existing note in the database. You should
|
|
|
239
391
|
]
|
|
240
392
|
};
|
|
241
393
|
});
|
|
242
|
-
server.
|
|
394
|
+
server.registerTool('list-notebooks', { description: 'Retrieve a list of all notebooks' }, async () => {
|
|
243
395
|
const books = await (0, api_1.fetchJSON)('/books');
|
|
244
396
|
return {
|
|
245
397
|
content: [
|
|
@@ -250,18 +402,27 @@ server.tool('list-notebooks', `Retrieve a list of all notebooks`, {}, async () =
|
|
|
250
402
|
]
|
|
251
403
|
};
|
|
252
404
|
});
|
|
253
|
-
server.
|
|
254
|
-
|
|
405
|
+
server.registerTool('read-book', {
|
|
406
|
+
description: 'Retrieve a single book',
|
|
407
|
+
inputSchema: {
|
|
408
|
+
bookId: zod_1.z
|
|
409
|
+
.string()
|
|
410
|
+
.describe('ID of the book to retrieve. It can be found as `_id` in the book docs. It always starts with \`book:\`.')
|
|
411
|
+
}
|
|
412
|
+
}, async ({ bookId }) => {
|
|
413
|
+
if (!bookId.startsWith('book:'))
|
|
414
|
+
bookId = `book:${bookId}`;
|
|
415
|
+
const book = await (0, api_1.fetchJSON)(`/${bookId}`, {});
|
|
255
416
|
return {
|
|
256
417
|
content: [
|
|
257
418
|
{
|
|
258
419
|
type: 'text',
|
|
259
|
-
text: JSON.stringify(
|
|
420
|
+
text: JSON.stringify(book, null, 2)
|
|
260
421
|
}
|
|
261
422
|
]
|
|
262
423
|
};
|
|
263
424
|
});
|
|
264
|
-
server.
|
|
425
|
+
server.registerPrompt('inkdrop-prompt', { description: 'Instructions for using the Inkdrop MCP server effectively' }, () => ({
|
|
265
426
|
messages: [
|
|
266
427
|
{
|
|
267
428
|
role: 'assistant',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkdropapp/mcp-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Inkdrop Model Context Protocol Server",
|
|
5
5
|
"bin": {
|
|
6
6
|
"inkdrop-mcp-server": "dist/index.js"
|
|
@@ -24,14 +24,15 @@
|
|
|
24
24
|
"author": "Takuya Matsuyama<contact@inkdrop.app>",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
27
|
+
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
28
28
|
"ajv": "^8.17.1",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
29
|
+
"diff": "^8.0.3",
|
|
30
|
+
"inkdrop-model": "^2.11.1",
|
|
31
|
+
"zod": "^4.3.6"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
|
-
"@types/node": "^
|
|
34
|
-
"prettier": "^3.
|
|
35
|
-
"typescript": "^5.
|
|
34
|
+
"@types/node": "^25.2.3",
|
|
35
|
+
"prettier": "^3.8.1",
|
|
36
|
+
"typescript": "^5.9.3"
|
|
36
37
|
}
|
|
37
38
|
}
|
package/src/index.ts
CHANGED
|
@@ -5,16 +5,25 @@ import {
|
|
|
5
5
|
ResourceTemplate
|
|
6
6
|
} from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
7
7
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
Note,
|
|
10
|
+
NoteSchema,
|
|
11
|
+
Book,
|
|
12
|
+
BookSchema,
|
|
13
|
+
TagSchema,
|
|
14
|
+
TAG_COLOR,
|
|
15
|
+
Tag
|
|
16
|
+
} from 'inkdrop-model'
|
|
9
17
|
import { z } from 'zod'
|
|
18
|
+
import { applyPatch } from 'diff'
|
|
10
19
|
import { fetchJSON, postJSON } from './api'
|
|
11
20
|
|
|
12
21
|
const server = new McpServer({
|
|
13
22
|
name: 'Inkdrop',
|
|
14
|
-
version: '1.
|
|
23
|
+
version: '1.3.0'
|
|
15
24
|
})
|
|
16
25
|
|
|
17
|
-
server.
|
|
26
|
+
server.registerResource(
|
|
18
27
|
'note',
|
|
19
28
|
new ResourceTemplate('inkdrop://note/{noteId}', { list: undefined }),
|
|
20
29
|
{
|
|
@@ -35,15 +44,18 @@ server.resource(
|
|
|
35
44
|
}
|
|
36
45
|
)
|
|
37
46
|
|
|
38
|
-
server.
|
|
47
|
+
server.registerTool(
|
|
39
48
|
'read-note',
|
|
40
|
-
'Retrieve the complete contents of the note by its ID from the database.',
|
|
41
49
|
{
|
|
42
|
-
|
|
43
|
-
.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
description:
|
|
51
|
+
'Retrieve the complete contents of the note by its ID from the database.',
|
|
52
|
+
inputSchema: {
|
|
53
|
+
noteId: z
|
|
54
|
+
.string()
|
|
55
|
+
.describe(
|
|
56
|
+
'ID of the note to retrieve. It can be found as `_id` in the note docs. It always starts with \`note:\`.'
|
|
57
|
+
)
|
|
58
|
+
}
|
|
47
59
|
},
|
|
48
60
|
async ({ noteId }) => {
|
|
49
61
|
if (!noteId.startsWith('note:')) noteId = `note:${noteId}`
|
|
@@ -59,9 +71,10 @@ server.tool(
|
|
|
59
71
|
}
|
|
60
72
|
)
|
|
61
73
|
|
|
62
|
-
server.
|
|
74
|
+
server.registerTool(
|
|
63
75
|
'search-notes',
|
|
64
|
-
|
|
76
|
+
{
|
|
77
|
+
description: `List all notes that contain a given keyword.
|
|
65
78
|
The result does not include entire note bodies as they are truncated in 200 characters.
|
|
66
79
|
You have to retrieve the full note content by calling \`read-note\`.
|
|
67
80
|
Here are tips to specify keywords effectively:
|
|
@@ -70,18 +83,18 @@ Here are tips to specify keywords effectively:
|
|
|
70
83
|
|
|
71
84
|
You can use special qualifiers to get more accurate results. See the qualifiers and their usage examples:
|
|
72
85
|
|
|
73
|
-
- **book**
|
|
86
|
+
- **book**
|
|
74
87
|
\`book:Blog\`: Searches for notes in the 'Blog' notebook.
|
|
75
88
|
\`book:"Desktop App"\`: Searches for notes in the 'Desktop App' notebook.
|
|
76
89
|
- **bookId**
|
|
77
90
|
\`bookId:kGlLniaV\`: Searches for notes in the notebook ID 'book:kGlLniaV'.
|
|
78
|
-
- **tag**
|
|
91
|
+
- **tag**
|
|
79
92
|
\`tag:JavaScript\`: Searches for all notes having the 'JavaScript' tag. Read more about [tags](https://docs.inkdrop.app/manual/write-notes#tag-notes).
|
|
80
|
-
- **status**
|
|
93
|
+
- **status**
|
|
81
94
|
\`status:onHold\`: Searches for all notes with the 'On hold' status. Read more about [statuses](/reference/note-statuses).
|
|
82
|
-
- **title**
|
|
95
|
+
- **title**
|
|
83
96
|
\`title:"JavaScript setTimeout"\`: Searches for the note with the specified title.
|
|
84
|
-
- **body**
|
|
97
|
+
- **body**
|
|
85
98
|
\`body:KEYWORD\`: Searches for a specific word in all notes. Equivalent to a [global search](#search-for-notes-across-all-notebooks).
|
|
86
99
|
|
|
87
100
|
### Combine qualifiers
|
|
@@ -122,14 +135,15 @@ Note that you can't specify excluding modifiers only without including condition
|
|
|
122
135
|
|
|
123
136
|
**WARNING**: Make sure to enter a text to search for after the exclusion modifier.
|
|
124
137
|
|
|
125
|
-
- ✅ Will work
|
|
138
|
+
- ✅ Will work
|
|
126
139
|
\`-book:Backend "closure functions"\`
|
|
127
140
|
|
|
128
|
-
- ⛔️ Won't work
|
|
141
|
+
- ⛔️ Won't work
|
|
129
142
|
\`-book:Backend\`. There's no query. Inkdrop doesn't understand what to search for.
|
|
130
143
|
`,
|
|
131
|
-
|
|
132
|
-
|
|
144
|
+
inputSchema: {
|
|
145
|
+
keyword: z.string().describe(`Keyword to search for.`)
|
|
146
|
+
}
|
|
133
147
|
},
|
|
134
148
|
async ({ keyword }) => {
|
|
135
149
|
const notes: Note[] = await fetchJSON('/notes', { keyword, limit: 10 })
|
|
@@ -150,37 +164,39 @@ Note that you can't specify excluding modifiers only without including condition
|
|
|
150
164
|
}
|
|
151
165
|
)
|
|
152
166
|
|
|
153
|
-
server.
|
|
167
|
+
server.registerTool(
|
|
154
168
|
'list-notes',
|
|
155
|
-
|
|
169
|
+
{
|
|
170
|
+
description: `List all notes with specified conditions.
|
|
156
171
|
The result does not include entire note bodies as they are truncated in 200 characters.
|
|
157
172
|
You have to retrieve the full note content by calling \`read-note\`.
|
|
158
173
|
`,
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
174
|
+
inputSchema: {
|
|
175
|
+
bookId: z
|
|
176
|
+
.string()
|
|
177
|
+
.optional()
|
|
178
|
+
.describe(
|
|
179
|
+
`ID of the notebook. It always starts with 'book:'. You can retrieve a list of notebooks with \`list-notebooks\``
|
|
180
|
+
),
|
|
181
|
+
tagIds: z
|
|
182
|
+
.array(z.string())
|
|
183
|
+
.optional()
|
|
184
|
+
.default([])
|
|
185
|
+
.describe(
|
|
186
|
+
`An array of tag IDs to filter. It always starts with 'tag:'. You can retrieve a list of available tags from \`list-tags\`.`
|
|
187
|
+
),
|
|
188
|
+
keyword: z.string().optional().describe(`Keyword to filter notes`),
|
|
189
|
+
sort: z
|
|
190
|
+
.enum(['updatedAt', 'createdAt', 'title'])
|
|
191
|
+
.optional()
|
|
192
|
+
.default('updatedAt')
|
|
193
|
+
.describe(`Sort the documents by the specified field`),
|
|
194
|
+
descending: z
|
|
195
|
+
.boolean()
|
|
196
|
+
.optional()
|
|
197
|
+
.default(true)
|
|
198
|
+
.describe(`Reverse the order of the output documents`)
|
|
199
|
+
}
|
|
184
200
|
},
|
|
185
201
|
async ({ bookId, tagIds, keyword, sort, descending }) => {
|
|
186
202
|
const bookFilter = bookId ? `bookId:${bookId.split(':')[1]}` : ''
|
|
@@ -209,28 +225,37 @@ You have to retrieve the full note content by calling \`read-note\`.
|
|
|
209
225
|
}
|
|
210
226
|
)
|
|
211
227
|
|
|
212
|
-
server.
|
|
228
|
+
server.registerTool(
|
|
213
229
|
'create-note',
|
|
214
|
-
'Create a new note in the database',
|
|
215
230
|
{
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
231
|
+
description: 'Create a new note in the database',
|
|
232
|
+
inputSchema: {
|
|
233
|
+
bookId: z
|
|
234
|
+
.string()
|
|
235
|
+
.min(5)
|
|
236
|
+
.max(128)
|
|
237
|
+
.regex(/^(book:|trash$)/)
|
|
238
|
+
.describe('The notebook ID'),
|
|
239
|
+
|
|
240
|
+
title: z.string().max(128).describe('The note title'),
|
|
241
|
+
|
|
242
|
+
body: z
|
|
243
|
+
.string()
|
|
244
|
+
.max(1048576)
|
|
245
|
+
.describe('The content of the note represented with Markdown'),
|
|
246
|
+
|
|
247
|
+
status: z
|
|
248
|
+
.enum(['none', 'active', 'onHold', 'completed', 'dropped'])
|
|
249
|
+
.optional()
|
|
250
|
+
.describe('The status of the note'),
|
|
251
|
+
|
|
252
|
+
tags: z
|
|
253
|
+
.array(z.string().startsWith('tag:'))
|
|
254
|
+
.optional()
|
|
255
|
+
.describe(
|
|
256
|
+
'An array of tag IDs to assign to the note. Call `list-tags` or `read-tag` to retrieve available tags. You can create a new tag with `create-tag` tool if necessary.'
|
|
257
|
+
)
|
|
258
|
+
}
|
|
234
259
|
},
|
|
235
260
|
async noteData => {
|
|
236
261
|
const res = await postJSON(`/notes`, noteData)
|
|
@@ -245,48 +270,190 @@ server.tool(
|
|
|
245
270
|
}
|
|
246
271
|
)
|
|
247
272
|
|
|
248
|
-
server.
|
|
273
|
+
server.registerTool(
|
|
249
274
|
'update-note',
|
|
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.',
|
|
251
275
|
{
|
|
252
|
-
|
|
253
|
-
.
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
.max(
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
276
|
+
description:
|
|
277
|
+
'Update the existing note in the database. Only the fields you provide will be updated; omitted fields remain unchanged.',
|
|
278
|
+
inputSchema: {
|
|
279
|
+
_id: z
|
|
280
|
+
.string()
|
|
281
|
+
.min(6)
|
|
282
|
+
.max(128)
|
|
283
|
+
.regex(/^note:/)
|
|
284
|
+
.describe(
|
|
285
|
+
'The unique document ID which should start with `note:` and the remains are randomly generated string'
|
|
286
|
+
),
|
|
287
|
+
|
|
288
|
+
_rev: z
|
|
289
|
+
.string()
|
|
290
|
+
.describe(
|
|
291
|
+
'This is a CouchDB specific field. The current MVCC-token/revision of this document (mandatory and immutable).'
|
|
292
|
+
),
|
|
293
|
+
|
|
294
|
+
bookId: z
|
|
295
|
+
.string()
|
|
296
|
+
.min(5)
|
|
297
|
+
.max(128)
|
|
298
|
+
.regex(/^(book:|trash$)/)
|
|
299
|
+
.optional()
|
|
300
|
+
.describe('The notebook ID'),
|
|
301
|
+
|
|
302
|
+
title: z.string().max(128).optional().describe('The note title'),
|
|
303
|
+
|
|
304
|
+
body: z
|
|
305
|
+
.string()
|
|
306
|
+
.max(1048576)
|
|
307
|
+
.optional()
|
|
308
|
+
.describe(
|
|
309
|
+
'The content of the note in Markdown. NOTE: Do not escape special characters like `\\n`.'
|
|
310
|
+
),
|
|
311
|
+
|
|
312
|
+
status: z
|
|
313
|
+
.enum(['none', 'active', 'onHold', 'completed', 'dropped'])
|
|
314
|
+
.optional()
|
|
315
|
+
.describe('The status of the note'),
|
|
316
|
+
|
|
317
|
+
tags: z
|
|
318
|
+
.array(z.string().startsWith('tag:'))
|
|
319
|
+
.optional()
|
|
320
|
+
.describe(
|
|
321
|
+
'An array of tag IDs to assign to the note. Call `list-tags` or `read-tag` to retrieve available tags. You can create a new tag with `create-tag` tool if necessary.'
|
|
322
|
+
)
|
|
323
|
+
}
|
|
287
324
|
},
|
|
288
325
|
async noteData => {
|
|
289
|
-
const
|
|
326
|
+
const rev = noteData._rev
|
|
327
|
+
const existingNote = await fetchJSON<Note>(`/${noteData._id}`, { rev })
|
|
328
|
+
|
|
329
|
+
const res = await postJSON(`/notes`, {
|
|
330
|
+
...existingNote,
|
|
331
|
+
...noteData
|
|
332
|
+
})
|
|
333
|
+
return {
|
|
334
|
+
content: [
|
|
335
|
+
{
|
|
336
|
+
type: 'text',
|
|
337
|
+
text: JSON.stringify(res, null, 2)
|
|
338
|
+
}
|
|
339
|
+
]
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
)
|
|
343
|
+
|
|
344
|
+
server.registerTool(
|
|
345
|
+
'patch-note',
|
|
346
|
+
{
|
|
347
|
+
description:
|
|
348
|
+
'Update the body of the existing note by applying a diff patch in the database. You should use this tool when you want to make partial updates to the note body without replacing the entire content because it is much more efficient for saving token window.',
|
|
349
|
+
inputSchema: {
|
|
350
|
+
_id: z
|
|
351
|
+
.string()
|
|
352
|
+
.min(6)
|
|
353
|
+
.max(128)
|
|
354
|
+
.regex(/^note:/)
|
|
355
|
+
.describe(
|
|
356
|
+
'The unique document ID which should start with `note:` and the remains are randomly generated string'
|
|
357
|
+
),
|
|
358
|
+
|
|
359
|
+
_rev: z
|
|
360
|
+
.string()
|
|
361
|
+
.describe(
|
|
362
|
+
'This is a CouchDB specific field. The current MVCC-token/revision of this document (mandatory and immutable).'
|
|
363
|
+
),
|
|
364
|
+
|
|
365
|
+
patch: z
|
|
366
|
+
.string()
|
|
367
|
+
.describe(
|
|
368
|
+
'A unified diff string to apply to the note body. Use standard unified diff format with `---`/`+++` headers and `@@ -start,count +start,count @@` hunk markers.'
|
|
369
|
+
)
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
async ({ _id, _rev, patch }) => {
|
|
373
|
+
const existingNote = await fetchJSON<Note>(`/${_id}`, { rev: _rev })
|
|
374
|
+
const patched = applyPatch(existingNote.body, patch)
|
|
375
|
+
if (patched === false) {
|
|
376
|
+
return {
|
|
377
|
+
content: [
|
|
378
|
+
{
|
|
379
|
+
type: 'text',
|
|
380
|
+
text: 'Failed to apply the patch. The diff may be malformed or does not match the current note body.'
|
|
381
|
+
}
|
|
382
|
+
],
|
|
383
|
+
isError: true
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
const res = await postJSON('/notes', { ...existingNote, body: patched })
|
|
387
|
+
return {
|
|
388
|
+
content: [
|
|
389
|
+
{
|
|
390
|
+
type: 'text',
|
|
391
|
+
text: JSON.stringify(res, null, 2)
|
|
392
|
+
}
|
|
393
|
+
]
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
)
|
|
397
|
+
|
|
398
|
+
server.registerTool(
|
|
399
|
+
'list-tags',
|
|
400
|
+
{ description: 'Retrieve a list of all tags' },
|
|
401
|
+
async () => {
|
|
402
|
+
const tags: Tag[] = await fetchJSON('/tags')
|
|
403
|
+
return {
|
|
404
|
+
content: [
|
|
405
|
+
{
|
|
406
|
+
type: 'text',
|
|
407
|
+
text: JSON.stringify(tags, null, 2)
|
|
408
|
+
}
|
|
409
|
+
]
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
server.registerTool(
|
|
415
|
+
'read-tag',
|
|
416
|
+
{
|
|
417
|
+
description: 'Retrieve a single tag',
|
|
418
|
+
inputSchema: {
|
|
419
|
+
tagId: z
|
|
420
|
+
.string()
|
|
421
|
+
.describe(
|
|
422
|
+
'ID of the tag to retrieve. It can be found as `_id` in the tag docs. It always starts with \`tag:\`.'
|
|
423
|
+
)
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
async ({ tagId }) => {
|
|
427
|
+
if (!tagId.startsWith('tag:')) tagId = `tag:${tagId}`
|
|
428
|
+
const tag: Tag = await fetchJSON(`/${tagId}`, {})
|
|
429
|
+
return {
|
|
430
|
+
content: [
|
|
431
|
+
{
|
|
432
|
+
type: 'text',
|
|
433
|
+
text: JSON.stringify(tag, null, 2)
|
|
434
|
+
}
|
|
435
|
+
]
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
)
|
|
439
|
+
|
|
440
|
+
const TagColors = Object.values(TAG_COLOR) as [string, ...string[]]
|
|
441
|
+
|
|
442
|
+
server.registerTool(
|
|
443
|
+
'create-tag',
|
|
444
|
+
{
|
|
445
|
+
description: 'Create a new tag in the database',
|
|
446
|
+
inputSchema: {
|
|
447
|
+
color: z
|
|
448
|
+
.enum(TagColors)
|
|
449
|
+
.default('default')
|
|
450
|
+
.describe('The color type of the tag'),
|
|
451
|
+
|
|
452
|
+
name: z.string().max(64).describe('The name of the tag')
|
|
453
|
+
}
|
|
454
|
+
},
|
|
455
|
+
async tagData => {
|
|
456
|
+
const res = await postJSON(`/tags`, tagData)
|
|
290
457
|
return {
|
|
291
458
|
content: [
|
|
292
459
|
{
|
|
@@ -298,10 +465,51 @@ server.tool(
|
|
|
298
465
|
}
|
|
299
466
|
)
|
|
300
467
|
|
|
301
|
-
server.
|
|
468
|
+
server.registerTool(
|
|
469
|
+
'update-tag',
|
|
470
|
+
{
|
|
471
|
+
description:
|
|
472
|
+
'Update the existing tag in the database. You should retrieve the existing tag with \`list-tags\` first. When updating the tag, you must specify not only the changed fields but also all the un-changed fields.',
|
|
473
|
+
inputSchema: {
|
|
474
|
+
_id: z
|
|
475
|
+
.string()
|
|
476
|
+
.min(6)
|
|
477
|
+
.max(128)
|
|
478
|
+
.regex(/^tag:/)
|
|
479
|
+
.describe(
|
|
480
|
+
'The unique document ID which should start with `tag:` and the remains are randomly generated string'
|
|
481
|
+
),
|
|
482
|
+
|
|
483
|
+
_rev: z
|
|
484
|
+
.string()
|
|
485
|
+
.describe(
|
|
486
|
+
'This is a CouchDB specific field. The current MVCC-token/revision of this document (mandatory and immutable).'
|
|
487
|
+
),
|
|
488
|
+
|
|
489
|
+
color: z
|
|
490
|
+
.enum(TagColors)
|
|
491
|
+
.default('default')
|
|
492
|
+
.describe('The color type of the tag'),
|
|
493
|
+
|
|
494
|
+
name: z.string().max(64).describe('The name of the tag')
|
|
495
|
+
}
|
|
496
|
+
},
|
|
497
|
+
async tagData => {
|
|
498
|
+
const res = await postJSON(`/tags`, tagData)
|
|
499
|
+
return {
|
|
500
|
+
content: [
|
|
501
|
+
{
|
|
502
|
+
type: 'text',
|
|
503
|
+
text: JSON.stringify(res, null, 2)
|
|
504
|
+
}
|
|
505
|
+
]
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
)
|
|
509
|
+
|
|
510
|
+
server.registerTool(
|
|
302
511
|
'list-notebooks',
|
|
303
|
-
|
|
304
|
-
{},
|
|
512
|
+
{ description: 'Retrieve a list of all notebooks' },
|
|
305
513
|
async () => {
|
|
306
514
|
const books: Book[] = await fetchJSON('/books')
|
|
307
515
|
return {
|
|
@@ -315,21 +523,35 @@ server.tool(
|
|
|
315
523
|
}
|
|
316
524
|
)
|
|
317
525
|
|
|
318
|
-
server.
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
526
|
+
server.registerTool(
|
|
527
|
+
'read-book',
|
|
528
|
+
{
|
|
529
|
+
description: 'Retrieve a single book',
|
|
530
|
+
inputSchema: {
|
|
531
|
+
bookId: z
|
|
532
|
+
.string()
|
|
533
|
+
.describe(
|
|
534
|
+
'ID of the book to retrieve. It can be found as `_id` in the book docs. It always starts with \`book:\`.'
|
|
535
|
+
)
|
|
536
|
+
}
|
|
537
|
+
},
|
|
538
|
+
async ({ bookId }) => {
|
|
539
|
+
if (!bookId.startsWith('book:')) bookId = `book:${bookId}`
|
|
540
|
+
const book: Book = await fetchJSON(`/${bookId}`, {})
|
|
541
|
+
return {
|
|
542
|
+
content: [
|
|
543
|
+
{
|
|
544
|
+
type: 'text',
|
|
545
|
+
text: JSON.stringify(book, null, 2)
|
|
546
|
+
}
|
|
547
|
+
]
|
|
548
|
+
}
|
|
327
549
|
}
|
|
328
|
-
|
|
550
|
+
)
|
|
329
551
|
|
|
330
|
-
server.
|
|
552
|
+
server.registerPrompt(
|
|
331
553
|
'inkdrop-prompt',
|
|
332
|
-
'Instructions for using the Inkdrop MCP server effectively',
|
|
554
|
+
{ description: 'Instructions for using the Inkdrop MCP server effectively' },
|
|
333
555
|
() => ({
|
|
334
556
|
messages: [
|
|
335
557
|
{
|