File size: 2,098 Bytes
c09f67c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { CATEGORIES } from "@midday/categories";
import { getTags, getTeamById } from "@midday/db/queries";
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { hasScope, type McpContext } from "./types";

export function registerResources(server: McpServer, ctx: McpContext): void {
  const { db, teamId } = ctx;

  // Team info requires teams.read scope
  if (hasScope(ctx, "teams.read")) {
    server.registerResource(
      "team",
      "midday://team/info",
      {
        description:
          "Current team information including name, base currency, and settings",
        mimeType: "application/json",
      },
      async () => {
        const team = await getTeamById(db, teamId);
        return {
          contents: [
            {
              uri: "midday://team/info",
              mimeType: "application/json",
              text: JSON.stringify(team, null, 2),
            },
          ],
        };
      },
    );
  }

  // Categories are static data, available to all authenticated users
  server.registerResource(
    "categories",
    "midday://categories",
    {
      description:
        "List of all transaction categories with their hierarchy, colors, and slugs",
      mimeType: "application/json",
    },
    async () => {
      return {
        contents: [
          {
            uri: "midday://categories",
            mimeType: "application/json",
            text: JSON.stringify(CATEGORIES, null, 2),
          },
        ],
      };
    },
  );

  // Tags require tags.read scope
  if (hasScope(ctx, "tags.read")) {
    server.registerResource(
      "tags",
      "midday://tags",
      {
        description: "List of all custom tags used for organizing data",
        mimeType: "application/json",
      },
      async () => {
        const tags = await getTags(db, { teamId });
        return {
          contents: [
            {
              uri: "midday://tags",
              mimeType: "application/json",
              text: JSON.stringify(tags, null, 2),
            },
          ],
        };
      },
    );
  }
}