@mosadd/mcp 3.0.0-alpha.17 → 3.0.0-alpha.19
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.
- package/CHANGELOG.md +37 -0
- package/README.md +12 -12
- package/dist/bin/mcp.js +1 -1
- package/dist/{chunk-5ZMJB5YU.js → chunk-QUJGZUTE.js} +295 -483
- package/dist/index.d.ts +4 -1
- package/dist/index.js +1 -1
- package/package.json +4 -3
- package/src/__tests__/integration.test.ts +3 -3
- package/src/__tests__/server.test.ts +11 -7
- package/src/tools/actions.ts +2 -2
- package/src/tools/attachments.ts +1 -61
- package/src/tools/embed.ts +108 -0
- package/src/tools/index.ts +12 -5
- package/src/tools/mail-provenance.ts +15 -15
- package/src/tools/mail.ts +84 -84
- package/src/tools/threat.ts +92 -0
package/src/tools/mail.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
|
22
|
+
const MessageId = z.string().min(1).describe("Message id (UUID) from mp0st_send or inbox.");
|
|
23
23
|
|
|
24
|
-
const
|
|
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
|
),
|
|
@@ -53,15 +53,15 @@ const mAIL_send_input = z.object({
|
|
|
53
53
|
.describe("Self-destruct timer: the secure-reader link expires after this window."),
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
const
|
|
56
|
+
const mp0st_view_input = z.object({
|
|
57
57
|
message_id: MessageId,
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
const
|
|
60
|
+
const mp0st_delete_input = z.object({
|
|
61
61
|
message_id: MessageId,
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
const
|
|
64
|
+
const mp0st_list_input = z.object({
|
|
65
65
|
direction: z
|
|
66
66
|
.enum(["inbound", "outbound"])
|
|
67
67
|
.optional()
|
|
@@ -73,17 +73,17 @@ const mAIL_list_input = z.object({
|
|
|
73
73
|
.describe("Pagination cursor: pass the previous response's next_cursor to get the next (older) page."),
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
-
const
|
|
76
|
+
const mp0st_stats_input = z.object({
|
|
77
77
|
message_id: MessageId,
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
-
const
|
|
80
|
+
const mp0st_events_input = z.object({
|
|
81
81
|
message_id: MessageId,
|
|
82
82
|
});
|
|
83
83
|
|
|
84
|
-
const
|
|
84
|
+
const mp0st_metrics_input = z.object({});
|
|
85
85
|
|
|
86
|
-
const
|
|
86
|
+
const mp0st_revoke_input = z.object({
|
|
87
87
|
message_id: MessageId,
|
|
88
88
|
restore: z
|
|
89
89
|
.boolean()
|
|
@@ -91,18 +91,18 @@ const mAIL_revoke_input = z.object({
|
|
|
91
91
|
.describe("Set true to UN-revoke (restore access). Default false = revoke."),
|
|
92
92
|
});
|
|
93
93
|
|
|
94
|
-
const
|
|
94
|
+
const mp0st_audit_export_input = z.object({
|
|
95
95
|
message_id: MessageId,
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
-
const
|
|
98
|
+
const mp0st_consent_input = z.object({
|
|
99
99
|
action: z
|
|
100
100
|
.enum(["list", "check", "optin"])
|
|
101
101
|
.describe("'list' = recipients who opted out of your tracking; 'check' = is one recipient opted out; 'optin' = re-enable tracking for a recipient."),
|
|
102
102
|
recipient: EmailAddress.optional().describe("Required for 'check' and 'optin'."),
|
|
103
103
|
});
|
|
104
104
|
|
|
105
|
-
const
|
|
105
|
+
const mp0st_notify_input = z.object({
|
|
106
106
|
since: z
|
|
107
107
|
.string()
|
|
108
108
|
.optional()
|
|
@@ -124,15 +124,15 @@ interface MailListItem {
|
|
|
124
124
|
|
|
125
125
|
// ---- Handlers ----
|
|
126
126
|
|
|
127
|
-
async function
|
|
128
|
-
input: z.infer<typeof
|
|
127
|
+
async function mp0st_send(
|
|
128
|
+
input: z.infer<typeof mp0st_send_input>,
|
|
129
129
|
ctx: MosaddToolContext,
|
|
130
130
|
): Promise<{ message_id: string; status: string; is_internal: boolean }> {
|
|
131
131
|
readSupabaseEnv();
|
|
132
132
|
if (!input.body_text && !input.body_html) {
|
|
133
|
-
throw new Error("
|
|
133
|
+
throw new Error("mp0st_send requires at least one of body_text or body_html.");
|
|
134
134
|
}
|
|
135
|
-
ctx.log("debug", "
|
|
135
|
+
ctx.log("debug", "mp0st_send invoking mp0st-send", { to: input.to });
|
|
136
136
|
// mp0st-send returns { ok, email_id, status, is_internal } — remap email_id to the
|
|
137
137
|
// tool's message_id contract (email_id IS the message id). Surface backend errors.
|
|
138
138
|
const res = await invokeFunction<{ ok?: boolean; email_id?: string; status?: string; is_internal?: boolean; error?: string }>("mp0st-send", input);
|
|
@@ -140,8 +140,8 @@ async function mAIL_send(
|
|
|
140
140
|
return { message_id: res.email_id ?? "", status: res.status ?? "sent", is_internal: res.is_internal ?? false };
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
async function
|
|
144
|
-
input: z.infer<typeof
|
|
143
|
+
async function mp0st_view(
|
|
144
|
+
input: z.infer<typeof mp0st_view_input>,
|
|
145
145
|
ctx: MosaddToolContext,
|
|
146
146
|
): Promise<{
|
|
147
147
|
message_id: string;
|
|
@@ -156,16 +156,16 @@ async function mAIL_view(
|
|
|
156
156
|
// mp0st-get (NOT mp0st-view): mp0st-view is the open-tracking pixel endpoint
|
|
157
157
|
// keyed on ?t=<trackingId> and always 400s "Missing tracking ID" on a JSON POST.
|
|
158
158
|
// mp0st-get reads the owner-scoped email by id and returns the full body.
|
|
159
|
-
ctx.log("debug", "
|
|
159
|
+
ctx.log("debug", "mp0st_view invoking mp0st-get", { message_id: input.message_id });
|
|
160
160
|
return await invokeFunction("mp0st-get", { message_id: input.message_id });
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
async function
|
|
164
|
-
input: z.infer<typeof
|
|
163
|
+
async function mp0st_list(
|
|
164
|
+
input: z.infer<typeof mp0st_list_input>,
|
|
165
165
|
ctx: MosaddToolContext,
|
|
166
166
|
): Promise<{ emails: MailListItem[]; next_cursor: string | null }> {
|
|
167
167
|
readSupabaseEnv();
|
|
168
|
-
ctx.log("debug", "
|
|
168
|
+
ctx.log("debug", "mp0st_list invoking mp0st-list", { direction: input.direction });
|
|
169
169
|
return await invokeFunction<{ emails: MailListItem[]; next_cursor: string | null }>("mp0st-list", {
|
|
170
170
|
direction: input.direction ?? null,
|
|
171
171
|
limit: input.limit ?? 50,
|
|
@@ -173,12 +173,12 @@ async function mAIL_list(
|
|
|
173
173
|
});
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
async function
|
|
177
|
-
input: z.infer<typeof
|
|
176
|
+
async function mp0st_delete(
|
|
177
|
+
input: z.infer<typeof mp0st_delete_input>,
|
|
178
178
|
ctx: MosaddToolContext,
|
|
179
179
|
): Promise<{ ok: true; message_id: string; deleted: true }> {
|
|
180
180
|
readSupabaseEnv();
|
|
181
|
-
ctx.log("debug", "
|
|
181
|
+
ctx.log("debug", "mp0st_delete invoking mp0st-delete", { message_id: input.message_id });
|
|
182
182
|
return await invokeFunction<{ ok: true; message_id: string; deleted: true }>("mp0st-delete", {
|
|
183
183
|
message_id: input.message_id,
|
|
184
184
|
});
|
|
@@ -201,31 +201,31 @@ interface MailEngagement {
|
|
|
201
201
|
total_events: number;
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
-
async function
|
|
205
|
-
input: z.infer<typeof
|
|
204
|
+
async function mp0st_stats(
|
|
205
|
+
input: z.infer<typeof mp0st_stats_input>,
|
|
206
206
|
ctx: MosaddToolContext,
|
|
207
207
|
): Promise<{ summary: MailEngagement }> {
|
|
208
208
|
readSupabaseEnv();
|
|
209
|
-
ctx.log("debug", "
|
|
209
|
+
ctx.log("debug", "mp0st_stats invoking mp0st-stats", { message_id: input.message_id });
|
|
210
210
|
return await invokeFunction<{ summary: MailEngagement }>("mp0st-stats", {
|
|
211
211
|
message_id: input.message_id,
|
|
212
212
|
});
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
async function
|
|
216
|
-
input: z.infer<typeof
|
|
215
|
+
async function mp0st_events(
|
|
216
|
+
input: z.infer<typeof mp0st_events_input>,
|
|
217
217
|
ctx: MosaddToolContext,
|
|
218
218
|
): Promise<{
|
|
219
219
|
summary: MailEngagement;
|
|
220
220
|
events: Array<{ event_type: string; at: string; device: string | null; ip_hash: string | null; link_url: string | null }>;
|
|
221
221
|
}> {
|
|
222
222
|
readSupabaseEnv();
|
|
223
|
-
ctx.log("debug", "
|
|
223
|
+
ctx.log("debug", "mp0st_events invoking mp0st-stats", { message_id: input.message_id });
|
|
224
224
|
return await invokeFunction("mp0st-stats", { message_id: input.message_id, events: true });
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
-
async function
|
|
228
|
-
_input: z.infer<typeof
|
|
227
|
+
async function mp0st_metrics(
|
|
228
|
+
_input: z.infer<typeof mp0st_metrics_input>,
|
|
229
229
|
ctx: MosaddToolContext,
|
|
230
230
|
): Promise<{
|
|
231
231
|
mailbox: {
|
|
@@ -238,42 +238,42 @@ async function mAIL_metrics(
|
|
|
238
238
|
};
|
|
239
239
|
}> {
|
|
240
240
|
readSupabaseEnv();
|
|
241
|
-
ctx.log("debug", "
|
|
241
|
+
ctx.log("debug", "mp0st_metrics invoking mp0st-stats");
|
|
242
242
|
return await invokeFunction("mp0st-stats", {});
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
-
async function
|
|
246
|
-
input: z.infer<typeof
|
|
245
|
+
async function mp0st_revoke(
|
|
246
|
+
input: z.infer<typeof mp0st_revoke_input>,
|
|
247
247
|
ctx: MosaddToolContext,
|
|
248
248
|
): Promise<{ ok: true; message_id: string; revoked: boolean; expires_at: string | null }> {
|
|
249
249
|
readSupabaseEnv();
|
|
250
|
-
ctx.log("debug", "
|
|
250
|
+
ctx.log("debug", "mp0st_revoke invoking mp0st-revoke", { message_id: input.message_id, restore: !!input.restore });
|
|
251
251
|
return await invokeFunction("mp0st-revoke", {
|
|
252
252
|
message_id: input.message_id,
|
|
253
253
|
restore: input.restore ?? false,
|
|
254
254
|
});
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
-
async function
|
|
258
|
-
input: z.infer<typeof
|
|
257
|
+
async function mp0st_audit_export(
|
|
258
|
+
input: z.infer<typeof mp0st_audit_export_input>,
|
|
259
259
|
ctx: MosaddToolContext,
|
|
260
260
|
): Promise<{ audit: Record<string, unknown>; signature: string; algo: string; note: string }> {
|
|
261
261
|
readSupabaseEnv();
|
|
262
|
-
ctx.log("debug", "
|
|
262
|
+
ctx.log("debug", "mp0st_audit_export invoking mp0st-audit", { message_id: input.message_id });
|
|
263
263
|
return await invokeFunction("mp0st-audit", { message_id: input.message_id });
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
-
async function
|
|
267
|
-
input: z.infer<typeof
|
|
266
|
+
async function mp0st_consent(
|
|
267
|
+
input: z.infer<typeof mp0st_consent_input>,
|
|
268
268
|
ctx: MosaddToolContext,
|
|
269
269
|
): Promise<Record<string, unknown>> {
|
|
270
270
|
readSupabaseEnv();
|
|
271
|
-
ctx.log("debug", "
|
|
271
|
+
ctx.log("debug", "mp0st_consent invoking mp0st-consent", { action: input.action });
|
|
272
272
|
return await invokeFunction("mp0st-consent", { action: input.action, recipient: input.recipient ?? null });
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
-
async function
|
|
276
|
-
input: z.infer<typeof
|
|
275
|
+
async function mp0st_notify(
|
|
276
|
+
input: z.infer<typeof mp0st_notify_input>,
|
|
277
277
|
ctx: MosaddToolContext,
|
|
278
278
|
): Promise<{
|
|
279
279
|
events: Array<{ message_id: string; subject: string | null; to: string | null; event_type: string; device: string | null; link_url: string | null; at: string }>;
|
|
@@ -281,7 +281,7 @@ async function mAIL_notify(
|
|
|
281
281
|
count: number;
|
|
282
282
|
}> {
|
|
283
283
|
readSupabaseEnv();
|
|
284
|
-
ctx.log("debug", "
|
|
284
|
+
ctx.log("debug", "mp0st_notify invoking mp0st-notify", { since: input.since });
|
|
285
285
|
return await invokeFunction("mp0st-notify", { action: "feed", since: input.since ?? null, limit: input.limit ?? 50 });
|
|
286
286
|
}
|
|
287
287
|
|
|
@@ -289,90 +289,90 @@ async function mAIL_notify(
|
|
|
289
289
|
|
|
290
290
|
export const mailTools: MosaddTool[] = [
|
|
291
291
|
{
|
|
292
|
-
name: "
|
|
292
|
+
name: "mp0st_list",
|
|
293
293
|
requires: "network",
|
|
294
294
|
description:
|
|
295
|
-
"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
|
|
296
|
-
inputSchema:
|
|
297
|
-
handler:
|
|
295
|
+
"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 mp0st_view to read a full message body.",
|
|
296
|
+
inputSchema: mp0st_list_input,
|
|
297
|
+
handler: mp0st_list as MosaddTool["handler"],
|
|
298
298
|
},
|
|
299
299
|
{
|
|
300
|
-
name: "
|
|
300
|
+
name: "mp0st_send",
|
|
301
301
|
requires: "network",
|
|
302
302
|
description:
|
|
303
303
|
"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').",
|
|
304
|
-
inputSchema:
|
|
305
|
-
handler:
|
|
304
|
+
inputSchema: mp0st_send_input,
|
|
305
|
+
handler: mp0st_send as MosaddTool["handler"],
|
|
306
306
|
},
|
|
307
307
|
{
|
|
308
|
-
name: "
|
|
308
|
+
name: "mp0st_view",
|
|
309
309
|
requires: "network",
|
|
310
310
|
description: "Read the full body and metadata of an email by message_id.",
|
|
311
|
-
inputSchema:
|
|
312
|
-
handler:
|
|
311
|
+
inputSchema: mp0st_view_input,
|
|
312
|
+
handler: mp0st_view as MosaddTool["handler"],
|
|
313
313
|
},
|
|
314
314
|
{
|
|
315
|
-
name: "
|
|
315
|
+
name: "mp0st_delete",
|
|
316
316
|
requires: "network",
|
|
317
317
|
description:
|
|
318
|
-
"Delete one of the user's emails by message_id (from
|
|
319
|
-
inputSchema:
|
|
320
|
-
handler:
|
|
318
|
+
"Delete one of the user's emails by message_id (from mp0st_list). Soft-delete — it stops showing in mp0st_list. Owner-scoped: only your own mail.",
|
|
319
|
+
inputSchema: mp0st_delete_input,
|
|
320
|
+
handler: mp0st_delete as MosaddTool["handler"],
|
|
321
321
|
},
|
|
322
322
|
{
|
|
323
|
-
name: "
|
|
323
|
+
name: "mp0st_stats",
|
|
324
324
|
requires: "network",
|
|
325
325
|
description:
|
|
326
326
|
"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.",
|
|
327
|
-
inputSchema:
|
|
328
|
-
handler:
|
|
327
|
+
inputSchema: mp0st_stats_input,
|
|
328
|
+
handler: mp0st_stats as MosaddTool["handler"],
|
|
329
329
|
},
|
|
330
330
|
{
|
|
331
|
-
name: "
|
|
331
|
+
name: "mp0st_events",
|
|
332
332
|
requires: "network",
|
|
333
333
|
description:
|
|
334
|
-
"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
|
|
335
|
-
inputSchema:
|
|
336
|
-
handler:
|
|
334
|
+
"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 mp0st_stats for the rollup; use this for the per-event detail. Owner-scoped.",
|
|
335
|
+
inputSchema: mp0st_events_input,
|
|
336
|
+
handler: mp0st_events as MosaddTool["handler"],
|
|
337
337
|
},
|
|
338
338
|
{
|
|
339
|
-
name: "
|
|
339
|
+
name: "mp0st_metrics",
|
|
340
340
|
requires: "network",
|
|
341
341
|
description:
|
|
342
342
|
"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.",
|
|
343
|
-
inputSchema:
|
|
344
|
-
handler:
|
|
343
|
+
inputSchema: mp0st_metrics_input,
|
|
344
|
+
handler: mp0st_metrics as MosaddTool["handler"],
|
|
345
345
|
},
|
|
346
346
|
{
|
|
347
|
-
name: "
|
|
347
|
+
name: "mp0st_revoke",
|
|
348
348
|
requires: "network",
|
|
349
349
|
description:
|
|
350
350
|
"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.",
|
|
351
|
-
inputSchema:
|
|
352
|
-
handler:
|
|
351
|
+
inputSchema: mp0st_revoke_input,
|
|
352
|
+
handler: mp0st_revoke as MosaddTool["handler"],
|
|
353
353
|
},
|
|
354
354
|
{
|
|
355
|
-
name: "
|
|
355
|
+
name: "mp0st_audit_export",
|
|
356
356
|
requires: "network",
|
|
357
357
|
description:
|
|
358
358
|
"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.",
|
|
359
|
-
inputSchema:
|
|
360
|
-
handler:
|
|
359
|
+
inputSchema: mp0st_audit_export_input,
|
|
360
|
+
handler: mp0st_audit_export as MosaddTool["handler"],
|
|
361
361
|
},
|
|
362
362
|
{
|
|
363
|
-
name: "
|
|
363
|
+
name: "mp0st_consent",
|
|
364
364
|
requires: "network",
|
|
365
365
|
description:
|
|
366
|
-
"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;
|
|
367
|
-
inputSchema:
|
|
368
|
-
handler:
|
|
366
|
+
"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; mp0st_send then automatically sends them with NO pixel/link-wrap. Owner-scoped.",
|
|
367
|
+
inputSchema: mp0st_consent_input,
|
|
368
|
+
handler: mp0st_consent as MosaddTool["handler"],
|
|
369
369
|
},
|
|
370
370
|
{
|
|
371
|
-
name: "
|
|
371
|
+
name: "mp0st_notify",
|
|
372
372
|
requires: "network",
|
|
373
373
|
description:
|
|
374
374
|
"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.",
|
|
375
|
-
inputSchema:
|
|
376
|
-
handler:
|
|
375
|
+
inputSchema: mp0st_notify_input,
|
|
376
|
+
handler: mp0st_notify as MosaddTool["handler"],
|
|
377
377
|
},
|
|
378
378
|
];
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* threat_* — defensive threat-event classification, exposed as MCP tools.
|
|
3
|
+
*
|
|
4
|
+
* Wraps `@mosadd/threat-engine` — the canonical mosadd threat-event taxonomy
|
|
5
|
+
* (`THREAT_EVENTS`, the full 160+ event catalog the radar scores against) plus
|
|
6
|
+
* the pure decision engine `evaluateEvent(event) → {action, severity, reason}`.
|
|
7
|
+
*
|
|
8
|
+
* These tools are PURE: deterministic, side-effect-free, no backend, no network.
|
|
9
|
+
* `requires: "any"` — they run anywhere (hosted hub, BYOK, fully offline). The
|
|
10
|
+
* engine DECIDES; the caller carries out any recommended action against its own
|
|
11
|
+
* backend. There is no surveillance, no data collection — it classifies an event
|
|
12
|
+
* the caller already has and returns a defensive recommendation.
|
|
13
|
+
*
|
|
14
|
+
* Founder decision (LINEAR-3498): the catalog is real and must be a real MCP
|
|
15
|
+
* tool, not detoxed away. (The AUDIT-B detox concerns the dead "anti-Pegasus"
|
|
16
|
+
* MARKETING framing, not this classification engine.)
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { z } from "zod";
|
|
20
|
+
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
21
|
+
import {
|
|
22
|
+
THREAT_EVENTS,
|
|
23
|
+
THREAT_EVENT_COUNT,
|
|
24
|
+
evaluateEvent,
|
|
25
|
+
type ThreatEventDef,
|
|
26
|
+
} from "@mosadd/threat-engine";
|
|
27
|
+
|
|
28
|
+
// ── threat_catalog ──
|
|
29
|
+
|
|
30
|
+
const threat_catalog_input = z.object({
|
|
31
|
+
category: z
|
|
32
|
+
.enum(["COMINT", "ELINT", "MASINT", "CYBER", "BEHAVIORAL", "PRIVACY", "SIGINT", "OSINT", "MPOST"])
|
|
33
|
+
.optional()
|
|
34
|
+
.describe("Filter the catalog to one intelligence-discipline category. Omit for the full catalog."),
|
|
35
|
+
platform: z
|
|
36
|
+
.enum(["apk", "ios", "pwa", "harmony"])
|
|
37
|
+
.optional()
|
|
38
|
+
.describe("Filter to events detectable on this platform. Omit for all platforms."),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
async function threat_catalog(
|
|
42
|
+
input: z.infer<typeof threat_catalog_input>,
|
|
43
|
+
_ctx: MosaddToolContext,
|
|
44
|
+
): Promise<{ count: number; total: number; events: ThreatEventDef[] }> {
|
|
45
|
+
let events = THREAT_EVENTS;
|
|
46
|
+
if (input.category) events = events.filter((e) => e.category === input.category);
|
|
47
|
+
if (input.platform) events = events.filter((e) => e.platforms.includes(input.platform!));
|
|
48
|
+
return { count: events.length, total: THREAT_EVENT_COUNT, events };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// ── threat_classify ──
|
|
52
|
+
|
|
53
|
+
const threat_classify_input = z.object({
|
|
54
|
+
event_type: z
|
|
55
|
+
.string()
|
|
56
|
+
.min(1)
|
|
57
|
+
.max(120)
|
|
58
|
+
.describe("Event type to classify, e.g. \"SIM_SWAP\", \"AUTH_BRUTEFORCE\", \"TOLL_FRAUD\". Case-insensitive."),
|
|
59
|
+
severity: z
|
|
60
|
+
.string()
|
|
61
|
+
.optional()
|
|
62
|
+
.describe("Optional producer severity hint. \"killswitch\" → lock_account; \"critical\" → revoke_sessions; anything else is informational."),
|
|
63
|
+
details: z.string().max(2_000).optional().describe("Optional free-text context (informational only)."),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
async function threat_classify(
|
|
67
|
+
input: z.infer<typeof threat_classify_input>,
|
|
68
|
+
_ctx: MosaddToolContext,
|
|
69
|
+
): Promise<{ action: string; severity: string; reason: string }> {
|
|
70
|
+
return evaluateEvent({ eventType: input.event_type, severity: input.severity, details: input.details });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// ── Registration ──
|
|
74
|
+
|
|
75
|
+
export const threatTools: MosaddTool[] = [
|
|
76
|
+
{
|
|
77
|
+
name: "threat_catalog",
|
|
78
|
+
requires: "any",
|
|
79
|
+
description:
|
|
80
|
+
"List the canonical mosadd threat-event taxonomy (the full radar catalog: id, category, default severity, auto-actions, per-platform availability). Filter by category or platform. Pure/offline — returns { count, total, events }. Use to discover what the defensive engine recognises.",
|
|
81
|
+
inputSchema: threat_catalog_input,
|
|
82
|
+
handler: threat_catalog as MosaddTool["handler"],
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: "threat_classify",
|
|
86
|
+
requires: "any",
|
|
87
|
+
description:
|
|
88
|
+
"Classify a single telemetry event with the pure mosadd DECK decision engine and get a defensive recommendation: { action (log_only|revoke_sessions|lock_account|suspend_did), severity, reason }. Deterministic, side-effect-free, no backend — the engine DECIDES; the caller carries out the action. Use to evaluate a threat event you already observed.",
|
|
89
|
+
inputSchema: threat_classify_input,
|
|
90
|
+
handler: threat_classify as MosaddTool["handler"],
|
|
91
|
+
},
|
|
92
|
+
];
|