@mosadd/mcp 3.0.0-alpha.6 → 3.0.0

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 (66) hide show
  1. package/CHANGELOG.md +410 -0
  2. package/README.md +79 -40
  3. package/dist/bin/mcp.js +132 -8
  4. package/dist/chunk-VMMJJYXF.js +4233 -0
  5. package/dist/index.d.ts +110 -6
  6. package/dist/index.js +3 -1
  7. package/package.json +19 -16
  8. package/src/__tests__/blob-upload.test.ts +93 -0
  9. package/src/__tests__/channel-e2ee.test.ts +62 -0
  10. package/src/__tests__/cli.test.ts +47 -0
  11. package/src/__tests__/flota-jawnie.test.ts +244 -0
  12. package/src/__tests__/golden-path.test.ts +4 -2
  13. package/src/__tests__/integration.test.ts +50 -11
  14. package/src/__tests__/knowledge-ingest.test.ts +114 -0
  15. package/src/__tests__/label-room-owner.test.ts +22 -0
  16. package/src/__tests__/mdm-e2ee.test.ts +35 -1
  17. package/src/__tests__/mdm-mcp-readable.test.ts +390 -0
  18. package/src/__tests__/mirc-invite.test.ts +112 -0
  19. package/src/__tests__/mrag-search-answer.test.ts +42 -0
  20. package/src/__tests__/no-dead-host.test.ts +37 -0
  21. package/src/__tests__/presence.test.ts +199 -0
  22. package/src/__tests__/server.test.ts +11 -7
  23. package/src/__tests__/serverJsonVersion.test.ts +45 -0
  24. package/src/__tests__/tool-count-consistency.test.ts +259 -0
  25. package/src/__tests__/voice-fields.test.ts +24 -0
  26. package/src/bin/mcp.ts +71 -6
  27. package/src/cli.ts +100 -0
  28. package/src/crypto/channel-e2ee.ts +288 -0
  29. package/src/crypto/mdm-session.ts +476 -37
  30. package/src/index.ts +2 -2
  31. package/src/providers/blob-upload.ts +162 -0
  32. package/src/providers/supabase-dm.ts +102 -7
  33. package/src/providers/supabase-voice.ts +13 -1
  34. package/src/providers/supabase.ts +121 -10
  35. package/src/server.ts +102 -12
  36. package/src/tools/__tests__/ragDeleteFoldsSourceId.test.ts +67 -0
  37. package/src/tools/actions.ts +166 -0
  38. package/src/tools/attachments.ts +276 -0
  39. package/src/tools/capabilities.ts +2 -0
  40. package/src/tools/channel-payload.ts +69 -0
  41. package/src/tools/embed.ts +110 -0
  42. package/src/tools/index.ts +136 -6
  43. package/src/tools/knowledge-graph.ts +186 -0
  44. package/src/tools/knowledge.ts +351 -132
  45. package/src/tools/mail-agentbox.ts +155 -0
  46. package/src/tools/mail-aliases.ts +25 -0
  47. package/src/tools/mail-provenance.ts +137 -0
  48. package/src/tools/mail.ts +284 -38
  49. package/src/tools/mdm-as-agent.ts +138 -0
  50. package/src/tools/mdm-voice.ts +17 -3
  51. package/src/tools/mdm.ts +303 -57
  52. package/src/tools/mirc-edge.ts +8 -2
  53. package/src/tools/mirc-members.ts +130 -20
  54. package/src/tools/mirc-messages.ts +80 -35
  55. package/src/tools/mirc.ts +149 -11
  56. package/src/tools/mroom-messages.ts +4 -12
  57. package/src/tools/mtalk.ts +11 -1
  58. package/src/tools/murl.ts +314 -0
  59. package/src/tools/presence.ts +442 -0
  60. package/src/tools/ptt-ingest.ts +99 -0
  61. package/src/tools/threat.ts +123 -0
  62. package/src/tools/voice-format.ts +43 -0
  63. package/src/types.ts +36 -0
  64. package/src/version.ts +8 -0
  65. package/LICENSE +0 -201
  66. package/dist/chunk-KAPG5FBN.js +0 -1844
@@ -0,0 +1,25 @@
1
+ // =============================================================================
2
+ // mail-aliases.ts — back-compat mp0st_* aliases for mAYL_* tools
3
+ // =============================================================================
4
+ // The mosADD re-arch (2026-06-27) renamed the email module from `mp0st` to
5
+ // `mAYL` (LINEAR-3938 / 3985). The canonical tool names are mAYL_* — see
6
+ // `tools/mail.ts`. THIS module exposes back-compat aliases so any agent already
7
+ // wired to mp0st_send / mp0st_view / etc. KEEPS WORKING in this release.
8
+ //
9
+ // Rule: never drop an alias in the release that adds its replacement — live
10
+ // agents would 404. mp0st_* aliases stay through alpha.25 and the next minor;
11
+ // flag for removal goes into the a later release's notes.
12
+ // =============================================================================
13
+
14
+ import type { MosaddTool } from "../types.js";
15
+ import { mailTools } from "./mail.js";
16
+
17
+ /** Same handlers/schemas as `mailTools`, but registered under the legacy mp0st_* names. */
18
+ export const mailAliasTools: MosaddTool[] = mailTools.map((tool) => ({
19
+ ...tool,
20
+ name: tool.name.replace(/^mAYL_/, "mp0st_"),
21
+ description:
22
+ `[DEPRECATED — use ${tool.name} instead. mp0st_* aliases stay through alpha.25 ` +
23
+ `for back-compat; will be removed in a later alpha.] ` +
24
+ tool.description,
25
+ }));
@@ -0,0 +1,137 @@
1
+ /**
2
+ * mp0st provenance — agent-attributed email send.
3
+ *
4
+ * The plain `mp0st_send` (mail.ts) sends as the USER. When an AGENT sends mail on
5
+ * the user's behalf, the recipient (and the audit trail) should be able to tell
6
+ * it was agent-originated. Per the Lane A contract, `mp0st-send`, when called
7
+ * with a HUB-CLAIM JWT, stamps the row with:
8
+ * sent_by = 'agent', sent_by_agent_id, sent_by_task_id
9
+ *
10
+ * This tool mints/forwards that hub-claim JWT and sets the provenance fields.
11
+ *
12
+ * AUTH MODEL (differs from the rest of mp0st):
13
+ * - mp0st_send uses the user's Supabase session JWT (via invokeFunction).
14
+ * - mp0st_send_as_agent presents a HUB-CLAIM JWT (hub key → claim exchange) so
15
+ * mp0st-send can attribute the send to the agent/task.
16
+ *
17
+ * STATUS: scaffold. The hub-claim exchange endpoint is assumed (TODO Lane A —
18
+ * confirm the exact route + claim shape). Falls back to the user session JWT if
19
+ * no hub key is configured, with provenance fields passed through for the EF to
20
+ * honor once deployed.
21
+ */
22
+
23
+ import { z } from "zod";
24
+ import type { MosaddTool, MosaddToolContext } from "../types.js";
25
+
26
+ const DEFAULT_SUPABASE_URL = "https://api.mosadd.com";
27
+
28
+ function supabaseUrl(): string {
29
+ return (
30
+ process.env.MOSADD_SUPABASE_URL?.replace(/\/$/, "") ??
31
+ process.env.SUPABASE_URL?.replace(/\/$/, "") ??
32
+ DEFAULT_SUPABASE_URL
33
+ );
34
+ }
35
+
36
+ function hubKey(): string | null {
37
+ return process.env.MOSADD_API_KEY ?? process.env.MOSADD_HUB_KEY ?? null;
38
+ }
39
+
40
+ const EmailAddress = z.string().email().max(254);
41
+
42
+ const mp0st_send_as_agent_input = z.object({
43
+ to: z.union([EmailAddress, z.array(EmailAddress).min(1).max(50)]),
44
+ subject: z.string().min(1).max(998),
45
+ body_text: z.string().max(1_048_576).optional(),
46
+ body_html: z.string().max(1_048_576).optional(),
47
+ cc: z.array(EmailAddress).max(50).optional(),
48
+ bcc: z.array(EmailAddress).max(50).optional(),
49
+ reply_to: EmailAddress.optional(),
50
+ tracking: z.boolean().optional(),
51
+ agent_id: z
52
+ .string()
53
+ .min(1)
54
+ .max(120)
55
+ .describe("Stable id of the agent doing the send. Stamped as sent_by_agent_id for provenance."),
56
+ task_id: z
57
+ .string()
58
+ .min(1)
59
+ .max(120)
60
+ .optional()
61
+ .describe("Optional id of the task/run this send belongs to. Stamped as sent_by_task_id."),
62
+ });
63
+
64
+ /**
65
+ * Exchange the hub key for an HS256 hub-claim JWT that authorizes agent-attributed
66
+ * mail sends. The `mp0st-send` EF verifies this token with HUB_JWT_SECRET and reads
67
+ * `agent_id` + `task_id` from its claims authoritatively (body fields are NOT trusted
68
+ * for provenance). LINEAR-3991.
69
+ */
70
+ async function mintHubClaim(agentId: string, taskId?: string): Promise<string> {
71
+ const key = hubKey();
72
+ if (!key) {
73
+ throw new Error("mAYL_send_as_agent needs MOSADD_API_KEY (hub key) to mint a provenance claim.");
74
+ }
75
+ const r = await fetch(`${supabaseUrl()}/functions/v1/hub-claim-mint`, {
76
+ method: "POST",
77
+ headers: { "Content-Type": "application/json", Authorization: `Bearer ${key}` },
78
+ body: JSON.stringify({ agent_id: agentId, task_id: taskId ?? null }),
79
+ });
80
+ if (!r.ok) {
81
+ const b = await r.text().catch(() => "");
82
+ throw new Error(`hub-claim-mint ${r.status}: ${b.slice(0, 200)}`);
83
+ }
84
+ const data = (await r.json()) as { access_token?: string };
85
+ if (!data?.access_token) throw new Error("hub-claim-mint: no access_token in response");
86
+ return data.access_token;
87
+ }
88
+
89
+ async function mAYL_send_as_agent(
90
+ input: z.infer<typeof mp0st_send_as_agent_input>,
91
+ ctx: MosaddToolContext,
92
+ ): Promise<{ message_id: string; status: string; is_internal: boolean; sent_by: "agent" }> {
93
+ if (!input.body_text && !input.body_html) {
94
+ throw new Error("mAYL_send_as_agent requires at least one of body_text or body_html.");
95
+ }
96
+
97
+ // Mint the hub-claim JWT and present it directly to mp0st-send (NOT the user
98
+ // session client) so the EF attributes the row to the agent. mp0st-send verifies
99
+ // the HS256 signature with HUB_JWT_SECRET and stamps sent_by_agent_id /
100
+ // sent_by_task_id from the verified claims — body fields are NOT trusted for
101
+ // provenance.
102
+ const claim = await mintHubClaim(input.agent_id, input.task_id);
103
+ ctx.log("debug", "mAYL_send_as_agent invoking mp0st-send with hub-claim", { agent_id: input.agent_id });
104
+
105
+ const { agent_id: _ai, task_id: _ti, ...mailFields } = input;
106
+ const r = await fetch(`${supabaseUrl()}/functions/v1/mp0st-send`, {
107
+ method: "POST",
108
+ headers: { "Content-Type": "application/json", Authorization: `Bearer ${claim}` },
109
+ body: JSON.stringify(mailFields),
110
+ });
111
+ if (!r.ok) {
112
+ const b = await r.text().catch(() => "");
113
+ throw new Error(`mp0st-send ${r.status}: ${b.slice(0, 200)}`);
114
+ }
115
+ const res = (await r.json()) as { email_id?: string; status?: string; is_internal?: boolean; error?: string };
116
+ if (res.error) throw new Error(res.error);
117
+
118
+ return {
119
+ message_id: res.email_id ?? "",
120
+ status: res.status ?? "sent",
121
+ is_internal: res.is_internal ?? false,
122
+ sent_by: "agent",
123
+ };
124
+ }
125
+
126
+ export const mailProvenanceTools: MosaddTool[] = [
127
+ {
128
+ name: "mAYL_send_as_agent",
129
+ title: "Send email as your agent",
130
+ annotations: { readOnlyHint: false },
131
+ requires: "network",
132
+ description:
133
+ "Send an email ATTRIBUTED TO THE AGENT (provenance-stamped). Unlike mAYL_send (sends as the user), this stamps sent_by='agent' plus your agent_id and optional task_id onto the email record and audit trail — so recipients and compliance can see the mail was agent-originated. Auth: presents a hub-claim JWT (needs MOSADD_API_KEY). The mp0st-send EF verifies the claim with HUB_JWT_SECRET; body trust is never granted for provenance.",
134
+ inputSchema: mp0st_send_as_agent_input,
135
+ handler: mAYL_send_as_agent as MosaddTool["handler"],
136
+ },
137
+ ];
package/src/tools/mail.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * mAIL — Email.
2
+ * mp0st — Email.
3
3
  *
4
4
  * Every mosadd user gets `<userId>@mosadd.com` for free — incoming mail lands
5
5
  * in their app, outgoing mail flows through the mosadd mp0st pipeline.
@@ -19,9 +19,9 @@ const EmailAddress = z
19
19
  .max(254)
20
20
  .describe("RFC 5321 email address.");
21
21
 
22
- const MessageId = z.string().min(1).describe("Message id (UUID) from mAIL_send or inbox.");
22
+ const MessageId = z.string().min(1).describe("Message id (UUID) from mAYL_send or inbox.");
23
23
 
24
- const mAIL_send_input = z.object({
24
+ const mp0st_send_input = z.object({
25
25
  to: z.union([EmailAddress, z.array(EmailAddress).min(1).max(50)]).describe(
26
26
  "Recipient(s). Single address or array of up to 50.",
27
27
  ),
@@ -31,17 +31,37 @@ const mAIL_send_input = z.object({
31
31
  cc: z.array(EmailAddress).max(50).optional(),
32
32
  bcc: z.array(EmailAddress).max(50).optional(),
33
33
  reply_to: EmailAddress.optional(),
34
+ tracking: z
35
+ .boolean()
36
+ .optional()
37
+ .describe("Open-pixel + link-click tracking. Default true. Set false to send with NO tracking (privacy / GDPR-friendly)."),
38
+ force_reader: z
39
+ .boolean()
40
+ .optional()
41
+ .describe("Default false. If true, the email body is a stub only and the recipient must open it in mosadd's secure reader — maximizes tracking (print/copy/time-on-read become observable). Best for confidential / legal mail."),
42
+ disclose_tracking: z
43
+ .boolean()
44
+ .optional()
45
+ .describe("Default false. If true (and tracking on), append a tracking-disclosure footer to the email — recommended for GDPR/ePrivacy compliance."),
46
+ watermark: z
47
+ .union([z.boolean(), z.string().max(120)])
48
+ .optional()
49
+ .describe("Inject a faint recipient watermark into the secure reader (shows in screenshots/prints). Pass true to watermark with the recipient address, or a custom string."),
50
+ auto_destruct: z
51
+ .enum(["1h", "24h", "7d"])
52
+ .optional()
53
+ .describe("Self-destruct timer: the secure-reader link expires after this window."),
34
54
  });
35
55
 
36
- const mAIL_view_input = z.object({
56
+ const mp0st_view_input = z.object({
37
57
  message_id: MessageId,
38
58
  });
39
59
 
40
- const mAIL_delete_input = z.object({
60
+ const mp0st_delete_input = z.object({
41
61
  message_id: MessageId,
42
62
  });
43
63
 
44
- const mAIL_list_input = z.object({
64
+ const mp0st_list_input = z.object({
45
65
  direction: z
46
66
  .enum(["inbound", "outbound"])
47
67
  .optional()
@@ -53,6 +73,43 @@ const mAIL_list_input = z.object({
53
73
  .describe("Pagination cursor: pass the previous response's next_cursor to get the next (older) page."),
54
74
  });
55
75
 
76
+ const mp0st_stats_input = z.object({
77
+ message_id: MessageId,
78
+ });
79
+
80
+ const mp0st_events_input = z.object({
81
+ message_id: MessageId,
82
+ });
83
+
84
+ const mp0st_metrics_input = z.object({});
85
+
86
+ const mp0st_revoke_input = z.object({
87
+ message_id: MessageId,
88
+ restore: z
89
+ .boolean()
90
+ .optional()
91
+ .describe("Set true to UN-revoke (restore access). Default false = revoke."),
92
+ });
93
+
94
+ const mp0st_audit_export_input = z.object({
95
+ message_id: MessageId,
96
+ });
97
+
98
+ const mp0st_consent_input = z.object({
99
+ action: z
100
+ .enum(["list", "check", "optin"])
101
+ .describe("'list' = recipients who opted out of your tracking; 'check' = is one recipient opted out; 'optin' = re-enable tracking for a recipient."),
102
+ recipient: EmailAddress.optional().describe("Required for 'check' and 'optin'."),
103
+ });
104
+
105
+ const mp0st_notify_input = z.object({
106
+ since: z
107
+ .string()
108
+ .optional()
109
+ .describe("ISO-8601 cursor — return only events newer than this. Pass the previous response's `cursor` to poll for new activity."),
110
+ limit: z.number().int().min(1).max(200).optional().describe("Max events. Default 50."),
111
+ });
112
+
56
113
  interface MailListItem {
57
114
  message_id: string;
58
115
  direction: "inbound" | "outbound";
@@ -67,20 +124,24 @@ interface MailListItem {
67
124
 
68
125
  // ---- Handlers ----
69
126
 
70
- async function mAIL_send(
71
- input: z.infer<typeof mAIL_send_input>,
127
+ async function mp0st_send(
128
+ input: z.infer<typeof mp0st_send_input>,
72
129
  ctx: MosaddToolContext,
73
- ): Promise<{ message_id: string; queued_at: string }> {
130
+ ): Promise<{ message_id: string; status: string; is_internal: boolean }> {
74
131
  readSupabaseEnv();
75
132
  if (!input.body_text && !input.body_html) {
76
- throw new Error("mAIL_send requires at least one of body_text or body_html.");
133
+ throw new Error("mp0st_send requires at least one of body_text or body_html.");
77
134
  }
78
- ctx.log("debug", "mAIL_send invoking mp0st-send", { to: input.to });
79
- return await invokeFunction<{ message_id: string; queued_at: string }>("mp0st-send", input);
135
+ ctx.log("debug", "mp0st_send invoking mp0st-send", { to: input.to });
136
+ // mp0st-send returns { ok, email_id, status, is_internal } — remap email_id to the
137
+ // tool's message_id contract (email_id IS the message id). Surface backend errors.
138
+ const res = await invokeFunction<{ ok?: boolean; email_id?: string; status?: string; is_internal?: boolean; error?: string }>("mp0st-send", input);
139
+ if (res.error) throw new Error(res.error);
140
+ return { message_id: res.email_id ?? "", status: res.status ?? "sent", is_internal: res.is_internal ?? false };
80
141
  }
81
142
 
82
- async function mAIL_view(
83
- input: z.infer<typeof mAIL_view_input>,
143
+ async function mp0st_view(
144
+ input: z.infer<typeof mp0st_view_input>,
84
145
  ctx: MosaddToolContext,
85
146
  ): Promise<{
86
147
  message_id: string;
@@ -89,19 +150,22 @@ async function mAIL_view(
89
150
  subject: string;
90
151
  body_text: string | null;
91
152
  body_html: string | null;
92
- received_at: string;
153
+ sent_at: string;
93
154
  }> {
94
155
  readSupabaseEnv();
95
- ctx.log("debug", "mAIL_view invoking mp0st-view", { message_id: input.message_id });
96
- return await invokeFunction("mp0st-view", { message_id: input.message_id });
156
+ // mp0st-get (NOT mp0st-view): mp0st-view is the open-tracking pixel endpoint
157
+ // keyed on ?t=<trackingId> and always 400s "Missing tracking ID" on a JSON POST.
158
+ // mp0st-get reads the owner-scoped email by id and returns the full body.
159
+ ctx.log("debug", "mp0st_view invoking mp0st-get", { message_id: input.message_id });
160
+ return await invokeFunction("mp0st-get", { message_id: input.message_id });
97
161
  }
98
162
 
99
- async function mAIL_list(
100
- input: z.infer<typeof mAIL_list_input>,
163
+ async function mp0st_list(
164
+ input: z.infer<typeof mp0st_list_input>,
101
165
  ctx: MosaddToolContext,
102
166
  ): Promise<{ emails: MailListItem[]; next_cursor: string | null }> {
103
167
  readSupabaseEnv();
104
- ctx.log("debug", "mAIL_list invoking mp0st-list", { direction: input.direction });
168
+ ctx.log("debug", "mp0st_list invoking mp0st-list", { direction: input.direction });
105
169
  return await invokeFunction<{ emails: MailListItem[]; next_cursor: string | null }>("mp0st-list", {
106
170
  direction: input.direction ?? null,
107
171
  limit: input.limit ?? 50,
@@ -109,49 +173,231 @@ async function mAIL_list(
109
173
  });
110
174
  }
111
175
 
112
- async function mAIL_delete(
113
- input: z.infer<typeof mAIL_delete_input>,
176
+ async function mp0st_delete(
177
+ input: z.infer<typeof mp0st_delete_input>,
114
178
  ctx: MosaddToolContext,
115
179
  ): Promise<{ ok: true; message_id: string; deleted: true }> {
116
180
  readSupabaseEnv();
117
- ctx.log("debug", "mAIL_delete invoking mp0st-delete", { message_id: input.message_id });
181
+ ctx.log("debug", "mp0st_delete invoking mp0st-delete", { message_id: input.message_id });
118
182
  return await invokeFunction<{ ok: true; message_id: string; deleted: true }>("mp0st-delete", {
119
183
  message_id: input.message_id,
120
184
  });
121
185
  }
122
186
 
187
+ interface MailEngagement {
188
+ message_id: string;
189
+ subject: string;
190
+ to: string;
191
+ direction: string;
192
+ status: string;
193
+ sent_at: string;
194
+ open_count: number;
195
+ unique_opens: number;
196
+ click_count: number;
197
+ forwarded: boolean;
198
+ first_opened_at: string | null;
199
+ last_opened_at: string | null;
200
+ events_by_type: Record<string, number>;
201
+ total_events: number;
202
+ }
203
+
204
+ async function mp0st_stats(
205
+ input: z.infer<typeof mp0st_stats_input>,
206
+ ctx: MosaddToolContext,
207
+ ): Promise<{ summary: MailEngagement }> {
208
+ readSupabaseEnv();
209
+ ctx.log("debug", "mp0st_stats invoking mp0st-stats", { message_id: input.message_id });
210
+ return await invokeFunction<{ summary: MailEngagement }>("mp0st-stats", {
211
+ message_id: input.message_id,
212
+ });
213
+ }
214
+
215
+ async function mp0st_events(
216
+ input: z.infer<typeof mp0st_events_input>,
217
+ ctx: MosaddToolContext,
218
+ ): Promise<{
219
+ summary: MailEngagement;
220
+ events: Array<{ event_type: string; at: string; device: string | null; ip_hash: string | null; link_url: string | null }>;
221
+ }> {
222
+ readSupabaseEnv();
223
+ ctx.log("debug", "mp0st_events invoking mp0st-stats", { message_id: input.message_id });
224
+ return await invokeFunction("mp0st-stats", { message_id: input.message_id, events: true });
225
+ }
226
+
227
+ async function mp0st_metrics(
228
+ _input: z.infer<typeof mp0st_metrics_input>,
229
+ ctx: MosaddToolContext,
230
+ ): Promise<{
231
+ mailbox: {
232
+ total_sent: number;
233
+ opened_emails: number;
234
+ open_rate_pct: number;
235
+ total_opens: number;
236
+ total_clicks: number;
237
+ forwarded_emails: number;
238
+ };
239
+ }> {
240
+ readSupabaseEnv();
241
+ ctx.log("debug", "mp0st_metrics invoking mp0st-stats");
242
+ return await invokeFunction("mp0st-stats", {});
243
+ }
244
+
245
+ async function mp0st_revoke(
246
+ input: z.infer<typeof mp0st_revoke_input>,
247
+ ctx: MosaddToolContext,
248
+ ): Promise<{ ok: true; message_id: string; revoked: boolean; expires_at: string | null }> {
249
+ readSupabaseEnv();
250
+ ctx.log("debug", "mp0st_revoke invoking mp0st-revoke", { message_id: input.message_id, restore: !!input.restore });
251
+ return await invokeFunction("mp0st-revoke", {
252
+ message_id: input.message_id,
253
+ restore: input.restore ?? false,
254
+ });
255
+ }
256
+
257
+ async function mp0st_audit_export(
258
+ input: z.infer<typeof mp0st_audit_export_input>,
259
+ ctx: MosaddToolContext,
260
+ ): Promise<{ audit: Record<string, unknown>; signature: string; algo: string; note: string }> {
261
+ readSupabaseEnv();
262
+ ctx.log("debug", "mp0st_audit_export invoking mp0st-audit", { message_id: input.message_id });
263
+ return await invokeFunction("mp0st-audit", { message_id: input.message_id });
264
+ }
265
+
266
+ async function mp0st_consent(
267
+ input: z.infer<typeof mp0st_consent_input>,
268
+ ctx: MosaddToolContext,
269
+ ): Promise<Record<string, unknown>> {
270
+ readSupabaseEnv();
271
+ if ((input.action === "check" || input.action === "optin") && !input.recipient) {
272
+ throw new Error(`mp0st_consent action '${input.action}' requires a 'recipient' email address.`);
273
+ }
274
+ ctx.log("debug", "mp0st_consent invoking mp0st-consent", { action: input.action });
275
+ return await invokeFunction("mp0st-consent", { action: input.action, recipient: input.recipient ?? null });
276
+ }
277
+
278
+ async function mp0st_notify(
279
+ input: z.infer<typeof mp0st_notify_input>,
280
+ ctx: MosaddToolContext,
281
+ ): Promise<{
282
+ events: Array<{ message_id: string; subject: string | null; to: string | null; event_type: string; device: string | null; link_url: string | null; at: string }>;
283
+ cursor: string | null;
284
+ count: number;
285
+ }> {
286
+ readSupabaseEnv();
287
+ ctx.log("debug", "mp0st_notify invoking mp0st-notify", { since: input.since });
288
+ return await invokeFunction("mp0st-notify", { action: "feed", since: input.since ?? null, limit: input.limit ?? 50 });
289
+ }
290
+
123
291
  // ---- Registration ----
124
292
 
125
293
  export const mailTools: MosaddTool[] = [
126
294
  {
127
- name: "mAIL_list",
295
+ name: "mAYL_list",
296
+ title: "List emails",
297
+ annotations: { readOnlyHint: true },
128
298
  requires: "network",
129
299
  description:
130
- "List the user's mailbox (their <userId>@mosadd.com inbox/outbox) newest-first, with sender, subject, status and a short snippet. Filter by direction ('inbound' = received, 'outbound' = sent). Use the returned next_cursor with `before` to page through older mail. Call mAIL_view to read a full message body.",
131
- inputSchema: mAIL_list_input,
132
- handler: mAIL_list as MosaddTool["handler"],
300
+ "List the user's mailbox (their <userId>@mosadd.com inbox/outbox) newest-first, with sender, subject, status and a short snippet. Filter by direction ('inbound' = received, 'outbound' = sent). Use the returned next_cursor with `before` to page through older mail. Call mAYL_view to read a full message body.",
301
+ inputSchema: mp0st_list_input,
302
+ handler: mp0st_list as MosaddTool["handler"],
133
303
  },
134
304
  {
135
- name: "mAIL_send",
305
+ name: "mAYL_send",
306
+ title: "Send email",
307
+ annotations: { readOnlyHint: false },
136
308
  requires: "network",
137
309
  description:
138
- "Send an email from the user's mosadd address (<userId>@mosadd.com). Pass body_text or body_html (or both). Supports cc, bcc, reply_to.",
139
- inputSchema: mAIL_send_input,
140
- handler: mAIL_send as MosaddTool["handler"],
310
+ "Send an email from the user's mosadd address (<userId>@mosadd.com). Pass body_text or body_html (or both). Supports cc, bcc, reply_to. Monitoring/legal options: tracking (open+click, default on; set false for no tracking), force_reader (stub email → recipient opens in mosadd's secure reader, unlocking print/copy/time-on-read tracking + revoke), watermark (recipient watermark visible in screenshots/prints), disclose_tracking (GDPR footer), auto_destruct ('1h'|'24h'|'7d').",
311
+ inputSchema: mp0st_send_input,
312
+ handler: mp0st_send as MosaddTool["handler"],
141
313
  },
142
314
  {
143
- name: "mAIL_view",
315
+ name: "mAYL_view",
316
+ title: "Read an email",
317
+ annotations: { readOnlyHint: true },
144
318
  requires: "network",
145
319
  description: "Read the full body and metadata of an email by message_id.",
146
- inputSchema: mAIL_view_input,
147
- handler: mAIL_view as MosaddTool["handler"],
320
+ inputSchema: mp0st_view_input,
321
+ handler: mp0st_view as MosaddTool["handler"],
322
+ },
323
+ {
324
+ name: "mAYL_delete",
325
+ title: "Delete email",
326
+ annotations: { destructiveHint: true },
327
+ requires: "network",
328
+ description:
329
+ "Delete one of the user's emails by message_id (from mAYL_list). Soft-delete — it stops showing in mAYL_list. Owner-scoped: only your own mail.",
330
+ inputSchema: mp0st_delete_input,
331
+ handler: mp0st_delete as MosaddTool["handler"],
332
+ },
333
+ {
334
+ name: "mAYL_stats",
335
+ title: "Email delivery stats",
336
+ annotations: { readOnlyHint: true },
337
+ requires: "network",
338
+ description:
339
+ "Engagement summary for one sent email (by message_id): open_count, unique_opens, click_count, whether it was likely forwarded, first/last opened time, and a breakdown of tracked event types. Opens/clicks are real (tracking pixel + link-wrap); forward detection is best-effort (IP-subnet diversity). Owner-scoped.",
340
+ inputSchema: mp0st_stats_input,
341
+ handler: mp0st_stats as MosaddTool["handler"],
342
+ },
343
+ {
344
+ name: "mAYL_events",
345
+ title: "Email event trail",
346
+ annotations: { readOnlyHint: true },
347
+ requires: "network",
348
+ description:
349
+ "Raw engagement timeline for one email (by message_id): every tracked event (pixel_open, link_click, forwarded, page_view, copy/print/focus signals) with timestamp, device type and link URL. Use mAYL_stats for the rollup; use this for the per-event detail. Owner-scoped.",
350
+ inputSchema: mp0st_events_input,
351
+ handler: mp0st_events as MosaddTool["handler"],
352
+ },
353
+ {
354
+ name: "mAYL_metrics",
355
+ title: "Email engagement metrics",
356
+ annotations: { readOnlyHint: true },
357
+ requires: "network",
358
+ description:
359
+ "Mailbox-wide engagement aggregate across the user's sent mail: total_sent, opened_emails, open_rate_pct, total_opens, total_clicks, forwarded_emails. Owner-scoped.",
360
+ inputSchema: mp0st_metrics_input,
361
+ handler: mp0st_metrics as MosaddTool["handler"],
362
+ },
363
+ {
364
+ name: "mAYL_revoke",
365
+ title: "Revoke a sent email",
366
+ annotations: { destructiveHint: true },
367
+ requires: "network",
368
+ description:
369
+ "Revoke (recall) a sent email's secure-reader access by message_id — the recipient can no longer open the full message via the mosadd reader link (Virtru-style recall, immediate). Pass restore:true to re-enable. HONEST LIMIT: cannot un-send or claw back content the recipient already read, copied, or screenshotted — only disables future reader access. Owner-scoped.",
370
+ inputSchema: mp0st_revoke_input,
371
+ handler: mp0st_revoke as MosaddTool["handler"],
372
+ },
373
+ {
374
+ name: "mAYL_audit_export",
375
+ title: "Export signed audit report",
376
+ annotations: { readOnlyHint: true },
377
+ requires: "network",
378
+ description:
379
+ "Export a tamper-evident engagement audit report for one sent email (RMail-style): full event trail (opens, clicks, reader print/copy/forward signals) + totals, plus an HMAC-SHA256 signature over the canonical JSON so the report can be proven unaltered. For legal/compliance use. HONEST LIMIT: proves what mosadd observed; it is not a qualified delivery receipt (ERDS). Owner-scoped.",
380
+ inputSchema: mp0st_audit_export_input,
381
+ handler: mp0st_audit_export as MosaddTool["handler"],
382
+ },
383
+ {
384
+ name: "mAYL_consent",
385
+ title: "Manage tracking opt-outs",
386
+ annotations: { readOnlyHint: false },
387
+ requires: "network",
388
+ description:
389
+ "Manage recipient tracking opt-outs (GDPR/ePrivacy). action 'list' = recipients who opted out of your tracking; 'check' {recipient} = whether one opted out; 'optin' {recipient} = re-enable. Recipients self-opt-out via the footer link in your tracked emails; mAYL_send then automatically sends them with NO pixel/link-wrap. Owner-scoped.",
390
+ inputSchema: mp0st_consent_input,
391
+ handler: mp0st_consent as MosaddTool["handler"],
148
392
  },
149
393
  {
150
- name: "mAIL_delete",
394
+ name: "mAYL_notify",
395
+ title: "Engagement notifications feed",
396
+ annotations: { readOnlyHint: true },
151
397
  requires: "network",
152
398
  description:
153
- "Delete one of the user's emails by message_id (from mAIL_list). Soft-delete — it stops showing in mAIL_list. Owner-scoped: only your own mail.",
154
- inputSchema: mAIL_delete_input,
155
- handler: mAIL_delete as MosaddTool["handler"],
399
+ "Recent engagement feed across ALL your sent mail — the 'who just opened/clicked my mail' notifications stream (opens, clicks, forwards, reader print/copy signals), newest first, each with the email subject + recipient. Poll: pass the returned `cursor` back as `since` to get only new activity. Owner-scoped.",
400
+ inputSchema: mp0st_notify_input,
401
+ handler: mp0st_notify as MosaddTool["handler"],
156
402
  },
157
403
  ];