1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
import { CallToolResult } from "@modelcontextprotocol/sdk/types";
import { z } from "zod";
import { karakeepClient, mcpServer } from "./shared";
import { compactBookmark, toMcpToolError } from "./utils";
mcpServer.tool(
"get-lists",
`Search for bookmarks matching a specific a query.`,
async (): Promise<CallToolResult> => {
const res = await karakeepClient.GET("/lists");
if (!res.data) {
return toMcpToolError(res.error);
}
return {
content: res.data.lists.map((list) => ({
type: "text",
text: JSON.stringify(list),
})),
};
},
);
mcpServer.tool(
"get-bookmarks-in-list",
`Search for bookmarks matching a specific a query.`,
{
listId: z.string().describe(`The listId to search in.`),
},
async ({ listId }): Promise<CallToolResult> => {
const res = await karakeepClient.GET(`/lists/{listId}/bookmarks`, {
params: {
path: {
listId,
},
query: {
includeContent: false,
},
},
});
if (res.error) {
return toMcpToolError(res.error);
}
return {
content: res.data.bookmarks.map((bookmark) => ({
type: "text",
text: JSON.stringify(compactBookmark(bookmark)),
})),
};
},
);
mcpServer.tool(
"add-bookmark-to-list",
`Add a bookmark to a list.`,
{
listId: z.string().describe(`The listId to add the bookmark to.`),
bookmarkId: z.string().describe(`The bookmarkId to add.`),
},
async ({ listId, bookmarkId }): Promise<CallToolResult> => {
const res = await karakeepClient.PUT(
`/lists/{listId}/bookmarks/{bookmarkId}`,
{
params: {
path: {
listId,
bookmarkId,
},
},
},
);
if (res.error) {
return toMcpToolError(res.error);
}
return {
content: [
{
type: "text",
text: `Bookmark ${bookmarkId} added to list ${listId}`,
},
],
};
},
);
mcpServer.tool(
"remove-bookmark-from-list",
`Remove a bookmark from a list.`,
{
listId: z.string().describe(`The listId to remove the bookmark from.`),
bookmarkId: z.string().describe(`The bookmarkId to remove.`),
},
async ({ listId, bookmarkId }): Promise<CallToolResult> => {
const res = await karakeepClient.DELETE(
`/lists/{listId}/bookmarks/{bookmarkId}`,
{
params: {
path: {
listId,
bookmarkId,
},
},
},
);
if (res.error) {
return toMcpToolError(res.error);
}
return {
content: [
{
type: "text",
text: `Bookmark ${bookmarkId} removed from list ${listId}`,
},
],
};
},
);
mcpServer.tool(
"create-list",
`Create a list.`,
{
name: z.string().describe(`The name of the list.`),
icon: z.string().describe(`The emoji icon of the list.`),
parentId: z
.string()
.optional()
.describe(`The parent list id of this list.`),
},
async ({ name, icon }): Promise<CallToolResult> => {
const res = await karakeepClient.POST("/lists", {
body: {
name,
icon,
},
});
if (res.error) {
return toMcpToolError(res.error);
}
return {
content: [
{
type: "text",
text: `List ${name} created with id ${res.data.id}`,
},
],
};
},
);
|