diff options
| author | Mohamed Bassem <me@mbassem.com> | 2025-04-13 13:47:40 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2025-04-13 13:47:40 +0000 |
| commit | 8c6cfc8f5fdab4bbdae41060518c08731720976a (patch) | |
| tree | 9e0bf2cbd2e61342380f295faaec88e014c33fa9 /apps/mcp/src/bookmarks.ts | |
| parent | 46277c74d5df376e4350cb3c8035ec9dda329a7a (diff) | |
| download | karakeep-8c6cfc8f5fdab4bbdae41060518c08731720976a.tar.zst | |
fix(mcp): compact the response of get bookmark lists
Diffstat (limited to 'apps/mcp/src/bookmarks.ts')
| -rw-r--r-- | apps/mcp/src/bookmarks.ts | 85 |
1 files changed, 2 insertions, 83 deletions
diff --git a/apps/mcp/src/bookmarks.ts b/apps/mcp/src/bookmarks.ts index 04e4480d..ed2da2fd 100644 --- a/apps/mcp/src/bookmarks.ts +++ b/apps/mcp/src/bookmarks.ts @@ -1,89 +1,8 @@ import { CallToolResult } from "@modelcontextprotocol/sdk/types"; import { z } from "zod"; -import { KarakeepAPISchemas } from "@karakeep/sdk"; - -import { - karakeepClient, - mcpServer, - toMcpToolError, - turndownService, -} from "./shared"; - -interface CompactBookmark { - id: string; - createdAt: string; - title: string; - summary: string; - note: string; - content: - | { - type: "link"; - url: string; - description: string; - author: string; - publisher: string; - } - | { - type: "text"; - sourceUrl: string; - } - | { - type: "media"; - assetId: string; - assetType: string; - sourceUrl: string; - } - | { - type: "unknown"; - }; - tags: string[]; -} - -function compactBookmark( - bookmark: KarakeepAPISchemas["Bookmark"], -): CompactBookmark { - let content: CompactBookmark["content"]; - if (bookmark.content.type === "link") { - content = { - type: "link", - url: bookmark.content.url, - description: bookmark.content.description ?? "", - author: bookmark.content.author ?? "", - publisher: bookmark.content.publisher ?? "", - }; - } else if (bookmark.content.type === "text") { - content = { - type: "text", - sourceUrl: bookmark.content.sourceUrl ?? "", - }; - } else if (bookmark.content.type === "asset") { - content = { - type: "media", - assetId: bookmark.content.assetId, - assetType: bookmark.content.assetType, - sourceUrl: bookmark.content.sourceUrl ?? "", - }; - } else { - content = { - type: "unknown", - }; - } - - return { - id: bookmark.id, - createdAt: bookmark.createdAt, - title: bookmark.title - ? bookmark.title - : ((bookmark.content.type === "link" - ? bookmark.content.title - : undefined) ?? ""), - summary: bookmark.summary ?? "", - note: bookmark.note ?? "", - content, - tags: bookmark.tags.map((t) => t.name), - }; -} +import { karakeepClient, mcpServer, turndownService } from "./shared"; +import { compactBookmark, toMcpToolError } from "./utils"; // Tools mcpServer.tool( |
