aboutsummaryrefslogtreecommitdiffstats
path: root/apps/mcp/src/shared.ts
blob: 2c553d17a6bce227ed20ab171803718d34768f5f (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
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { CallToolResult } from "@modelcontextprotocol/sdk/types";
import TurndownService from "turndown";

import { createKarakeepClient } from "@karakeep/sdk";

const addr = process.env.KARAKEEP_API_ADDR;
const apiKey = process.env.KARAKEEP_API_KEY;

export const karakeepClient = createKarakeepClient({
  baseUrl: `${addr}/api/v1`,
  headers: {
    "Content-Type": "application/json",
    authorization: `Bearer ${apiKey}`,
  },
});

export const mcpServer = new McpServer({
  name: "Karakeep",
  version: "0.23.0",
});

export const turndownService = new TurndownService();

export function toMcpToolError(
  error: { code: string; message: string } | undefined,
): CallToolResult {
  return {
    isError: true,
    content: [
      {
        type: "text",
        text: error ? JSON.stringify(error) : `Something went wrong`,
      },
    ],
  };
}