From cf97bace33fdd14f29ce947d55d17cba8fa85c11 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sun, 13 Apr 2025 01:27:45 +0000 Subject: feat: Add an MCP server for karakeep --- apps/mcp/src/shared.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 apps/mcp/src/shared.ts (limited to 'apps/mcp/src/shared.ts') diff --git a/apps/mcp/src/shared.ts b/apps/mcp/src/shared.ts new file mode 100644 index 00000000..69672769 --- /dev/null +++ b/apps/mcp/src/shared.ts @@ -0,0 +1,34 @@ +import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; +import { CallToolResult } from "@modelcontextprotocol/sdk/types"; + +import { createHoarderClient } from "@karakeep/sdk"; + +const addr = process.env.KARAKEEP_API_ADDR; +const apiKey = process.env.KARAKEEP_API_KEY; + +export const karakeepClient = createHoarderClient({ + baseUrl: `${addr}/api/v1`, + headers: { + "Content-Type": "application/json", + authorization: `Bearer ${apiKey}`, + }, +}); + +export const mcpServer = new McpServer({ + name: "Karakeep", + version: "0.23.0", +}); + +export function toMcpToolError( + error: { code: string; message: string } | undefined, +): CallToolResult { + return { + isError: true, + content: [ + { + type: "text", + text: error ? JSON.stringify(error) : `Something went wrong`, + }, + ], + }; +} -- cgit v1.2.3-70-g09d2