@mosadd/mcp 3.0.0-alpha.51 → 3.0.0-alpha.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +334 -309
  2. package/README.md +150 -150
  3. package/dist/bin/mcp.js +1 -1
  4. package/dist/{chunk-BTAIZKYT.js → chunk-AWKITPZQ.js} +407 -106
  5. package/dist/index.d.ts +11 -1
  6. package/dist/index.js +1 -1
  7. package/package.json +9 -9
  8. package/src/__tests__/blob-upload.test.ts +93 -0
  9. package/src/__tests__/golden-path.test.ts +139 -139
  10. package/src/__tests__/integration.test.ts +182 -182
  11. package/src/__tests__/knowledge-ingest.test.ts +114 -114
  12. package/src/__tests__/mdm-e2ee.test.ts +212 -212
  13. package/src/__tests__/mdm-mcp-readable.test.ts +284 -0
  14. package/src/__tests__/mirc-invite.test.ts +112 -112
  15. package/src/__tests__/mtalk.test.ts +122 -122
  16. package/src/__tests__/server.test.ts +71 -71
  17. package/src/__tests__/serverJsonVersion.test.ts +45 -45
  18. package/src/__tests__/tool-count-consistency.test.ts +199 -199
  19. package/src/bin/login.ts +138 -138
  20. package/src/bin/mcp.ts +145 -145
  21. package/src/config.ts +66 -66
  22. package/src/crypto/mdm-session.ts +798 -502
  23. package/src/index.ts +19 -19
  24. package/src/observability/sentry.ts +79 -79
  25. package/src/providers/blob-upload.ts +52 -6
  26. package/src/providers/memory-voice.ts +79 -79
  27. package/src/providers/supabase-dm.ts +174 -122
  28. package/src/providers/supabase-voice.ts +91 -91
  29. package/src/providers/supabase.ts +231 -231
  30. package/src/server.ts +186 -162
  31. package/src/tools/__tests__/ragDeleteFoldsSourceId.test.ts +67 -67
  32. package/src/tools/actions.ts +166 -166
  33. package/src/tools/attachments.ts +276 -276
  34. package/src/tools/capabilities.ts +70 -70
  35. package/src/tools/embed.ts +110 -110
  36. package/src/tools/index.ts +181 -181
  37. package/src/tools/knowledge-graph.ts +186 -186
  38. package/src/tools/knowledge.ts +344 -344
  39. package/src/tools/mail-agentbox.ts +155 -155
  40. package/src/tools/mail-aliases.ts +25 -25
  41. package/src/tools/mail-provenance.ts +137 -137
  42. package/src/tools/mail.ts +403 -403
  43. package/src/tools/mcall.ts +216 -216
  44. package/src/tools/mdm-as-agent.ts +126 -126
  45. package/src/tools/mdm-voice.ts +220 -220
  46. package/src/tools/mdm.ts +119 -17
  47. package/src/tools/mirc-edge.ts +196 -196
  48. package/src/tools/mirc-members.ts +287 -287
  49. package/src/tools/mirc.ts +308 -308
  50. package/src/tools/mroom-messages.ts +142 -142
  51. package/src/tools/mroom.ts +221 -221
  52. package/src/tools/mtalk.ts +131 -131
  53. package/src/tools/murl.ts +314 -314
  54. package/src/tools/presence.ts +442 -442
  55. package/src/tools/ptt-ingest.ts +99 -99
  56. package/src/tools/threat.ts +123 -123
  57. package/src/types.ts +121 -121
  58. package/src/version.ts +8 -8
  59. package/src/voice/floor.ts +132 -132
  60. package/LICENSE +0 -201
@@ -1,186 +1,186 @@
1
- /**
2
- * mRAG_graph — the KNOWLEDGE GRAPH over the user's own mosadd data.
3
- *
4
- * mRAG_search recalls WHAT was said; this surface walks WHO/WHAT is connected to whom, and WHEN.
5
- * The engine already runs inside the mosadd backend as a set of Postgres functions built from the
6
- * SAME per-user embeddings mRAG_search reads (metadata only — sender/recipient/thread — NEVER the
7
- * message body, so it does not weaken the E2EE posture). Until now those functions had no MCP door,
8
- * so an agent could search the corpus but not traverse it. These four tools are that door.
9
- *
10
- * ⚠ TRANSPORT: unlike the other mRAG tools (which call Edge Functions via invokeFunction), the
11
- * graph lives in Postgres RPCs (kg_*), so these call `getSupabase().rpc(...)` directly. The RPCs
12
- * are `grant execute … to authenticated`, and the graph-building one is SECURITY DEFINER keyed on
13
- * `auth.uid()`, so under the caller's hub-session JWT every result is scoped to the caller's own
14
- * account — there is no cross-tenant path.
15
- *
16
- * Typical flow for an agent: mRAG_graph_refresh (build/update from the latest ingested data) →
17
- * mRAG_graph_overview (see the top parties + their ids) → mRAG_graph_neighbors / _timeline on a
18
- * party id from the overview.
19
- *
20
- * Plan note: gated by plan at the hub (the knowledge graph is a paid capability — matches the
21
- * app's `knowledgeGraph` flag). BYOK/self-host runs it against the user's own backend.
22
- */
23
-
24
- import { z } from "zod";
25
- import type { MosaddTool, MosaddToolContext } from "../types.js";
26
- import { getSupabase, readSupabaseEnv } from "../providers/supabase.js";
27
-
28
- /** One authenticated RPC round-trip with normalized errors an agent can reason about. */
29
- async function callRpc<T>(fn: string, args: Record<string, unknown>, ctx: MosaddToolContext): Promise<T> {
30
- readSupabaseEnv();
31
- ctx.log("debug", `mRAG_graph via ${fn}`, args);
32
- const { data, error } = await getSupabase().rpc(fn, args);
33
- if (error) {
34
- // PostgREST surfaces RLS denials, auth failures and function errors here; hand the agent the
35
- // real message + code rather than a generic sentence, so it can self-correct.
36
- throw new Error(`${fn} failed: ${error.message}${error.code ? ` (${error.code})` : ""}`);
37
- }
38
- return data as T;
39
- }
40
-
41
- // ── mRAG_graph_refresh ───────────────────────────────────────────────────────
42
- const mRAG_graph_refresh_input = z.object({
43
- max_docs: z
44
- .number()
45
- .int()
46
- .min(1)
47
- .max(20_000)
48
- .optional()
49
- .describe("Cap on source documents scanned when (re)building the graph. Default 20000 (the max)."),
50
- });
51
-
52
- async function mRAG_graph_refresh(
53
- input: z.infer<typeof mRAG_graph_refresh_input>,
54
- ctx: MosaddToolContext,
55
- ): Promise<unknown> {
56
- // kg_refresh_me rebuilds parties/mentions/edges from the caller's embeddings METADATA only
57
- // (sender/recipient/thread), never content_text. Returns counts {parties, mentions, edges, …}.
58
- return await callRpc("kg_refresh_me", { p_max_docs: input.max_docs ?? 20_000 }, ctx);
59
- }
60
-
61
- // ── mRAG_graph_overview ──────────────────────────────────────────────────────
62
- const mRAG_graph_overview_input = z.object({
63
- limit: z.number().int().min(1).max(200).optional().describe("Max parties to return (busiest first). Default 40, max 200."),
64
- });
65
-
66
- interface GraphParty {
67
- party_id: string;
68
- display_name: string;
69
- kind: string;
70
- aliases: string[];
71
- appearances: number;
72
- connections: number;
73
- first_seen_at: string | null;
74
- last_seen_at: string | null;
75
- }
76
-
77
- async function mRAG_graph_overview(
78
- input: z.infer<typeof mRAG_graph_overview_input>,
79
- ctx: MosaddToolContext,
80
- ): Promise<{ parties: GraphParty[]; count: number }> {
81
- const rows = await callRpc<GraphParty[]>("kg_overview", { p_limit: input.limit ?? 40 }, ctx);
82
- const parties = rows ?? [];
83
- return { parties, count: parties.length };
84
- }
85
-
86
- // ── mRAG_graph_neighbors ─────────────────────────────────────────────────────
87
- const mRAG_graph_neighbors_input = z.object({
88
- party_id: z.string().uuid().describe("The party whose connections to walk (a party_id from mRAG_graph_overview)."),
89
- depth: z.number().int().min(1).max(2).optional().describe("Hops to walk. Hard-clamped to 2 server-side. Default 1."),
90
- limit: z.number().int().min(1).max(200).optional().describe("Max neighbours to return. Clamped to 200. Default 50."),
91
- });
92
-
93
- interface GraphNeighbor {
94
- party_id: string;
95
- display_name: string;
96
- kind: string;
97
- depth: number;
98
- edge_type: string;
99
- observations: number;
100
- valid_from: string | null;
101
- last_seen_at: string | null;
102
- }
103
-
104
- async function mRAG_graph_neighbors(
105
- input: z.infer<typeof mRAG_graph_neighbors_input>,
106
- ctx: MosaddToolContext,
107
- ): Promise<{ neighbors: GraphNeighbor[]; count: number }> {
108
- const rows = await callRpc<GraphNeighbor[]>(
109
- "kg_neighbors",
110
- { p_party_id: input.party_id, p_depth: input.depth ?? 1, p_limit: input.limit ?? 50 },
111
- ctx,
112
- );
113
- const neighbors = rows ?? [];
114
- return { neighbors, count: neighbors.length };
115
- }
116
-
117
- // ── mRAG_graph_timeline ──────────────────────────────────────────────────────
118
- const mRAG_graph_timeline_input = z.object({
119
- party_id: z.string().uuid().describe("The party whose dated appearance timeline to return (a party_id from mRAG_graph_overview)."),
120
- limit: z.number().int().min(1).max(200).optional().describe("Max timeline entries (newest first). Clamped to 200. Default 50."),
121
- });
122
-
123
- interface GraphTimelineEntry {
124
- source_type: string;
125
- source_id: string;
126
- thread_id: string | null;
127
- role: string | null;
128
- occurred_at: string | null;
129
- evidence_chunk_id: string | null;
130
- }
131
-
132
- async function mRAG_graph_timeline(
133
- input: z.infer<typeof mRAG_graph_timeline_input>,
134
- ctx: MosaddToolContext,
135
- ): Promise<{ timeline: GraphTimelineEntry[]; count: number }> {
136
- const rows = await callRpc<GraphTimelineEntry[]>(
137
- "kg_party_timeline",
138
- { p_party_id: input.party_id, p_limit: input.limit ?? 50 },
139
- ctx,
140
- );
141
- const timeline = rows ?? [];
142
- return { timeline, count: timeline.length };
143
- }
144
-
145
- export const knowledgeGraphTools: MosaddTool[] = [
146
- {
147
- name: "mRAG_graph_refresh",
148
- title: "Rebuild knowledge graph",
149
- annotations: { readOnlyHint: false },
150
- requires: "network",
151
- description:
152
- "(Re)build the USER'S OWN knowledge graph from their indexed data, then return what it found (counts of parties/mentions/edges). Run this first, or after new data has been ingested, so mRAG_graph_overview/neighbors/timeline reflect the latest. Built from METADATA only (who-sent-to-whom, thread membership) — never message bodies, so it does not weaken E2EE. Owner-scoped.",
153
- inputSchema: mRAG_graph_refresh_input,
154
- handler: mRAG_graph_refresh as MosaddTool["handler"],
155
- },
156
- {
157
- name: "mRAG_graph_overview",
158
- title: "Knowledge graph overview",
159
- annotations: { readOnlyHint: true },
160
- requires: "network",
161
- description:
162
- "List the parties (people / companies / services) in the user's knowledge graph, busiest first, each with its party_id, kind, aliases, appearance count, connection count and first/last-seen dates. This is the entry point: use a returned party_id with mRAG_graph_neighbors or mRAG_graph_timeline. Owner-scoped.",
163
- inputSchema: mRAG_graph_overview_input,
164
- handler: mRAG_graph_overview as MosaddTool["handler"],
165
- },
166
- {
167
- name: "mRAG_graph_neighbors",
168
- title: "Explore graph neighbors",
169
- annotations: { readOnlyHint: true },
170
- requires: "network",
171
- description:
172
- "Walk the connections of one party (from mRAG_graph_overview) — who/what it is linked to, with the edge type, how many times observed, and when. Answers 'who is connected to X, and how'. Depth is hard-clamped to 2 hops and breadth to 200 server-side. Owner-scoped.",
173
- inputSchema: mRAG_graph_neighbors_input,
174
- handler: mRAG_graph_neighbors as MosaddTool["handler"],
175
- },
176
- {
177
- name: "mRAG_graph_timeline",
178
- title: "Knowledge graph timeline",
179
- annotations: { readOnlyHint: true },
180
- requires: "network",
181
- description:
182
- "Return the dated appearance timeline of one party (from mRAG_graph_overview) — each source (email/message/call/…), its thread, the party's role, and when it occurred, newest first. Answers 'when and where did X show up'. Owner-scoped.",
183
- inputSchema: mRAG_graph_timeline_input,
184
- handler: mRAG_graph_timeline as MosaddTool["handler"],
185
- },
186
- ];
1
+ /**
2
+ * mRAG_graph — the KNOWLEDGE GRAPH over the user's own mosadd data.
3
+ *
4
+ * mRAG_search recalls WHAT was said; this surface walks WHO/WHAT is connected to whom, and WHEN.
5
+ * The engine already runs inside the mosadd backend as a set of Postgres functions built from the
6
+ * SAME per-user embeddings mRAG_search reads (metadata only — sender/recipient/thread — NEVER the
7
+ * message body, so it does not weaken the E2EE posture). Until now those functions had no MCP door,
8
+ * so an agent could search the corpus but not traverse it. These four tools are that door.
9
+ *
10
+ * ⚠ TRANSPORT: unlike the other mRAG tools (which call Edge Functions via invokeFunction), the
11
+ * graph lives in Postgres RPCs (kg_*), so these call `getSupabase().rpc(...)` directly. The RPCs
12
+ * are `grant execute … to authenticated`, and the graph-building one is SECURITY DEFINER keyed on
13
+ * `auth.uid()`, so under the caller's hub-session JWT every result is scoped to the caller's own
14
+ * account — there is no cross-tenant path.
15
+ *
16
+ * Typical flow for an agent: mRAG_graph_refresh (build/update from the latest ingested data) →
17
+ * mRAG_graph_overview (see the top parties + their ids) → mRAG_graph_neighbors / _timeline on a
18
+ * party id from the overview.
19
+ *
20
+ * Plan note: gated by plan at the hub (the knowledge graph is a paid capability — matches the
21
+ * app's `knowledgeGraph` flag). BYOK/self-host runs it against the user's own backend.
22
+ */
23
+
24
+ import { z } from "zod";
25
+ import type { MosaddTool, MosaddToolContext } from "../types.js";
26
+ import { getSupabase, readSupabaseEnv } from "../providers/supabase.js";
27
+
28
+ /** One authenticated RPC round-trip with normalized errors an agent can reason about. */
29
+ async function callRpc<T>(fn: string, args: Record<string, unknown>, ctx: MosaddToolContext): Promise<T> {
30
+ readSupabaseEnv();
31
+ ctx.log("debug", `mRAG_graph via ${fn}`, args);
32
+ const { data, error } = await getSupabase().rpc(fn, args);
33
+ if (error) {
34
+ // PostgREST surfaces RLS denials, auth failures and function errors here; hand the agent the
35
+ // real message + code rather than a generic sentence, so it can self-correct.
36
+ throw new Error(`${fn} failed: ${error.message}${error.code ? ` (${error.code})` : ""}`);
37
+ }
38
+ return data as T;
39
+ }
40
+
41
+ // ── mRAG_graph_refresh ───────────────────────────────────────────────────────
42
+ const mRAG_graph_refresh_input = z.object({
43
+ max_docs: z
44
+ .number()
45
+ .int()
46
+ .min(1)
47
+ .max(20_000)
48
+ .optional()
49
+ .describe("Cap on source documents scanned when (re)building the graph. Default 20000 (the max)."),
50
+ });
51
+
52
+ async function mRAG_graph_refresh(
53
+ input: z.infer<typeof mRAG_graph_refresh_input>,
54
+ ctx: MosaddToolContext,
55
+ ): Promise<unknown> {
56
+ // kg_refresh_me rebuilds parties/mentions/edges from the caller's embeddings METADATA only
57
+ // (sender/recipient/thread), never content_text. Returns counts {parties, mentions, edges, …}.
58
+ return await callRpc("kg_refresh_me", { p_max_docs: input.max_docs ?? 20_000 }, ctx);
59
+ }
60
+
61
+ // ── mRAG_graph_overview ──────────────────────────────────────────────────────
62
+ const mRAG_graph_overview_input = z.object({
63
+ limit: z.number().int().min(1).max(200).optional().describe("Max parties to return (busiest first). Default 40, max 200."),
64
+ });
65
+
66
+ interface GraphParty {
67
+ party_id: string;
68
+ display_name: string;
69
+ kind: string;
70
+ aliases: string[];
71
+ appearances: number;
72
+ connections: number;
73
+ first_seen_at: string | null;
74
+ last_seen_at: string | null;
75
+ }
76
+
77
+ async function mRAG_graph_overview(
78
+ input: z.infer<typeof mRAG_graph_overview_input>,
79
+ ctx: MosaddToolContext,
80
+ ): Promise<{ parties: GraphParty[]; count: number }> {
81
+ const rows = await callRpc<GraphParty[]>("kg_overview", { p_limit: input.limit ?? 40 }, ctx);
82
+ const parties = rows ?? [];
83
+ return { parties, count: parties.length };
84
+ }
85
+
86
+ // ── mRAG_graph_neighbors ─────────────────────────────────────────────────────
87
+ const mRAG_graph_neighbors_input = z.object({
88
+ party_id: z.string().uuid().describe("The party whose connections to walk (a party_id from mRAG_graph_overview)."),
89
+ depth: z.number().int().min(1).max(2).optional().describe("Hops to walk. Hard-clamped to 2 server-side. Default 1."),
90
+ limit: z.number().int().min(1).max(200).optional().describe("Max neighbours to return. Clamped to 200. Default 50."),
91
+ });
92
+
93
+ interface GraphNeighbor {
94
+ party_id: string;
95
+ display_name: string;
96
+ kind: string;
97
+ depth: number;
98
+ edge_type: string;
99
+ observations: number;
100
+ valid_from: string | null;
101
+ last_seen_at: string | null;
102
+ }
103
+
104
+ async function mRAG_graph_neighbors(
105
+ input: z.infer<typeof mRAG_graph_neighbors_input>,
106
+ ctx: MosaddToolContext,
107
+ ): Promise<{ neighbors: GraphNeighbor[]; count: number }> {
108
+ const rows = await callRpc<GraphNeighbor[]>(
109
+ "kg_neighbors",
110
+ { p_party_id: input.party_id, p_depth: input.depth ?? 1, p_limit: input.limit ?? 50 },
111
+ ctx,
112
+ );
113
+ const neighbors = rows ?? [];
114
+ return { neighbors, count: neighbors.length };
115
+ }
116
+
117
+ // ── mRAG_graph_timeline ──────────────────────────────────────────────────────
118
+ const mRAG_graph_timeline_input = z.object({
119
+ party_id: z.string().uuid().describe("The party whose dated appearance timeline to return (a party_id from mRAG_graph_overview)."),
120
+ limit: z.number().int().min(1).max(200).optional().describe("Max timeline entries (newest first). Clamped to 200. Default 50."),
121
+ });
122
+
123
+ interface GraphTimelineEntry {
124
+ source_type: string;
125
+ source_id: string;
126
+ thread_id: string | null;
127
+ role: string | null;
128
+ occurred_at: string | null;
129
+ evidence_chunk_id: string | null;
130
+ }
131
+
132
+ async function mRAG_graph_timeline(
133
+ input: z.infer<typeof mRAG_graph_timeline_input>,
134
+ ctx: MosaddToolContext,
135
+ ): Promise<{ timeline: GraphTimelineEntry[]; count: number }> {
136
+ const rows = await callRpc<GraphTimelineEntry[]>(
137
+ "kg_party_timeline",
138
+ { p_party_id: input.party_id, p_limit: input.limit ?? 50 },
139
+ ctx,
140
+ );
141
+ const timeline = rows ?? [];
142
+ return { timeline, count: timeline.length };
143
+ }
144
+
145
+ export const knowledgeGraphTools: MosaddTool[] = [
146
+ {
147
+ name: "mRAG_graph_refresh",
148
+ title: "Rebuild knowledge graph",
149
+ annotations: { readOnlyHint: false },
150
+ requires: "network",
151
+ description:
152
+ "(Re)build the USER'S OWN knowledge graph from their indexed data, then return what it found (counts of parties/mentions/edges). Run this first, or after new data has been ingested, so mRAG_graph_overview/neighbors/timeline reflect the latest. Built from METADATA only (who-sent-to-whom, thread membership) — never message bodies, so it does not weaken E2EE. Owner-scoped.",
153
+ inputSchema: mRAG_graph_refresh_input,
154
+ handler: mRAG_graph_refresh as MosaddTool["handler"],
155
+ },
156
+ {
157
+ name: "mRAG_graph_overview",
158
+ title: "Knowledge graph overview",
159
+ annotations: { readOnlyHint: true },
160
+ requires: "network",
161
+ description:
162
+ "List the parties (people / companies / services) in the user's knowledge graph, busiest first, each with its party_id, kind, aliases, appearance count, connection count and first/last-seen dates. This is the entry point: use a returned party_id with mRAG_graph_neighbors or mRAG_graph_timeline. Owner-scoped.",
163
+ inputSchema: mRAG_graph_overview_input,
164
+ handler: mRAG_graph_overview as MosaddTool["handler"],
165
+ },
166
+ {
167
+ name: "mRAG_graph_neighbors",
168
+ title: "Explore graph neighbors",
169
+ annotations: { readOnlyHint: true },
170
+ requires: "network",
171
+ description:
172
+ "Walk the connections of one party (from mRAG_graph_overview) — who/what it is linked to, with the edge type, how many times observed, and when. Answers 'who is connected to X, and how'. Depth is hard-clamped to 2 hops and breadth to 200 server-side. Owner-scoped.",
173
+ inputSchema: mRAG_graph_neighbors_input,
174
+ handler: mRAG_graph_neighbors as MosaddTool["handler"],
175
+ },
176
+ {
177
+ name: "mRAG_graph_timeline",
178
+ title: "Knowledge graph timeline",
179
+ annotations: { readOnlyHint: true },
180
+ requires: "network",
181
+ description:
182
+ "Return the dated appearance timeline of one party (from mRAG_graph_overview) — each source (email/message/call/…), its thread, the party's role, and when it occurred, newest first. Answers 'when and where did X show up'. Owner-scoped.",
183
+ inputSchema: mRAG_graph_timeline_input,
184
+ handler: mRAG_graph_timeline as MosaddTool["handler"],
185
+ },
186
+ ];