blob: 6d7d8ad5d64f496f40dd22296f9b35e06d700954 (
plain) (
blame)
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
|
import { CallToolResult } from "@modelcontextprotocol/sdk/types";
import { KarakeepAPISchemas } from "@karakeep/sdk";
export function toMcpToolError(
error: { code: string; message: string } | undefined,
): CallToolResult {
return {
isError: true,
content: [
{
type: "text",
text: error ? JSON.stringify(error) : `Something went wrong`,
},
],
};
}
export function compactBookmark(
bookmark: KarakeepAPISchemas["Bookmark"],
): string {
let content: string;
if (bookmark.content.type === "link") {
content = `
Bookmark type: link
urk: ${bookmark.content.url}
description: ${bookmark.content.description ?? ""}
author: ${bookmark.content.author ?? ""}
publisher: ${bookmark.content.publisher ?? ""}
`;
} else if (bookmark.content.type === "text") {
content = `
Bookmark type: text
Source URL: ${bookmark.content.sourceUrl ?? ""}
`;
} else if (bookmark.content.type === "asset") {
content = `
Bookmark type: media
Asset ID: ${bookmark.content.assetId}
Asset type: ${bookmark.content.assetType}
Source URL: ${bookmark.content.sourceUrl ?? ""}
`;
} else {
content = `
Bookmark type: unknown
`;
}
return `
Bookmark ID: ${bookmark.id}
Created at: ${bookmark.createdAt}
Title: ${
bookmark.title
? bookmark.title
: ((bookmark.content.type === "link" ? bookmark.content.title : "") ?? "")
}
Summary: ${bookmark.summary ?? ""}
Note: ${bookmark.note ?? ""}
${content}
Tags: ${bookmark.tags.map((t) => t.name).join(", ")}
`;
}
|