aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-04-27 01:57:41 +0000
committerMohamed Bassem <me@mbassem.com>2025-04-27 01:57:41 +0000
commit1a24eb690803292286513404d27a0955d2b7ab44 (patch)
tree6c15e8414bc1567547a38e33d4e1fb631a1388da
parentd3cf3e4d5eec8bc7b46c568910f7a49eab2b12cb (diff)
downloadkarakeep-1a24eb690803292286513404d27a0955d2b7ab44.tar.zst
fix(mcp): Ditch JSON and respond in plain text
-rw-r--r--apps/mcp/package.json2
-rw-r--r--apps/mcp/src/bookmarks.ts14
-rw-r--r--apps/mcp/src/lists.ts18
-rw-r--r--apps/mcp/src/utils.ts98
-rw-r--r--apps/mcp/vite.config.mts5
5 files changed, 56 insertions, 81 deletions
diff --git a/apps/mcp/package.json b/apps/mcp/package.json
index d06223d1..dfa38ed7 100644
--- a/apps/mcp/package.json
+++ b/apps/mcp/package.json
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@karakeep/mcp",
- "version": "0.23.7",
+ "version": "0.23.8",
"description": "MCP server for Karakeep",
"license": "GNU Affero General Public License version 3",
"type": "module",
diff --git a/apps/mcp/src/bookmarks.ts b/apps/mcp/src/bookmarks.ts
index 62893f2f..747bcd18 100644
--- a/apps/mcp/src/bookmarks.ts
+++ b/apps/mcp/src/bookmarks.ts
@@ -57,13 +57,13 @@ machine learning is:fav`),
}
return {
content: [
- ...res.data.bookmarks.map((bookmark) => ({
- type: "text" as const,
- text: JSON.stringify(compactBookmark(bookmark)),
- })),
{
type: "text",
- text: `Next cursor: ${res.data.nextCursor ? `'${res.data.nextCursor}'` : "no more pages"}`,
+ text: `
+${res.data.bookmarks.map(compactBookmark).join("\n\n")}
+
+Next cursor: ${res.data.nextCursor ? `'${res.data.nextCursor}'` : "no more pages"}
+`,
},
],
};
@@ -94,7 +94,7 @@ mcpServer.tool(
content: [
{
type: "text",
- text: JSON.stringify(compactBookmark(res.data)),
+ text: compactBookmark(res.data),
},
],
};
@@ -137,7 +137,7 @@ mcpServer.tool(
content: [
{
type: "text",
- text: JSON.stringify(compactBookmark(res.data)),
+ text: compactBookmark(res.data),
},
],
};
diff --git a/apps/mcp/src/lists.ts b/apps/mcp/src/lists.ts
index 36eb6661..242229cb 100644
--- a/apps/mcp/src/lists.ts
+++ b/apps/mcp/src/lists.ts
@@ -13,10 +13,20 @@ mcpServer.tool(
return toMcpToolError(res.error);
}
return {
- content: res.data.lists.map((list) => ({
- type: "text",
- text: JSON.stringify(list),
- })),
+ content: [
+ {
+ type: "text",
+ text: res.data.lists
+ .map(
+ (list) => `
+List ID: ${list.id}
+Name: ${list.icon} ${list.name}
+Description: ${list.description ?? ""}
+Parent ID: ${list.parentId}`,
+ )
+ .join("\n\n"),
+ },
+ ],
};
},
);
diff --git a/apps/mcp/src/utils.ts b/apps/mcp/src/utils.ts
index 26a86436..6d7d8ad5 100644
--- a/apps/mcp/src/utils.ts
+++ b/apps/mcp/src/utils.ts
@@ -16,77 +16,47 @@ export function toMcpToolError(
};
}
-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[];
-}
-
export function compactBookmark(
bookmark: KarakeepAPISchemas["Bookmark"],
-): CompactBookmark {
- let content: CompactBookmark["content"];
+): string {
+ let content: string;
if (bookmark.content.type === "link") {
- content = {
- type: "link",
- url: bookmark.content.url,
- description: bookmark.content.description ?? "",
- author: bookmark.content.author ?? "",
- publisher: bookmark.content.publisher ?? "",
- };
+ 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 = {
- type: "text",
- sourceUrl: bookmark.content.sourceUrl ?? "",
- };
+ content = `
+ Bookmark type: text
+ Source URL: ${bookmark.content.sourceUrl ?? ""}
+`;
} else if (bookmark.content.type === "asset") {
- content = {
- type: "media",
- assetId: bookmark.content.assetId,
- assetType: bookmark.content.assetType,
- sourceUrl: bookmark.content.sourceUrl ?? "",
- };
+ content = `
+Bookmark type: media
+Asset ID: ${bookmark.content.assetId}
+Asset type: ${bookmark.content.assetType}
+Source URL: ${bookmark.content.sourceUrl ?? ""}
+`;
} else {
- content = {
- type: "unknown",
- };
+ content = `
+Bookmark type: unknown
+`;
}
- return {
- id: bookmark.id,
- createdAt: bookmark.createdAt,
- title: bookmark.title
+ return `
+ Bookmark ID: ${bookmark.id}
+ Created at: ${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),
- };
+ : ((bookmark.content.type === "link" ? bookmark.content.title : "") ?? "")
+ }
+ Summary: ${bookmark.summary ?? ""}
+ Note: ${bookmark.note ?? ""}
+ ${content}
+ Tags: ${bookmark.tags.map((t) => t.name).join(", ")}
+ `;
}
diff --git a/apps/mcp/vite.config.mts b/apps/mcp/vite.config.mts
index 4d354fd6..54ec5cff 100644
--- a/apps/mcp/vite.config.mts
+++ b/apps/mcp/vite.config.mts
@@ -21,9 +21,4 @@ export default defineConfig({
noExternal: /^(?!node:).*$/,
},
plugins: [tsconfigPaths()],
- define: {
- "import.meta.env.CLI_VERSION": JSON.stringify(
- process.env.npm_package_version,
- ),
- },
});