@mosadd/mcp 3.0.0-alpha.2 → 3.0.0-alpha.21
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 +131 -0
- package/README.md +141 -116
- package/dist/bin/mcp.js +70 -3
- package/dist/chunk-TNWL6GPV.js +2299 -0
- package/dist/index.d.ts +70 -7
- package/dist/index.js +5 -3
- package/package.json +13 -7
- package/src/__tests__/golden-path.test.ts +137 -132
- package/src/__tests__/integration.test.ts +178 -175
- package/src/__tests__/mdm-e2ee.test.ts +212 -149
- package/src/__tests__/mtalk.test.ts +122 -0
- package/src/__tests__/server.test.ts +71 -67
- package/src/bin/login.ts +138 -138
- package/src/bin/mcp.ts +145 -55
- package/src/config.ts +66 -66
- package/src/crypto/mdm-session.ts +502 -378
- package/src/index.ts +19 -17
- package/src/observability/sentry.ts +79 -79
- package/src/providers/blob-upload.ts +116 -0
- package/src/providers/memory-voice.ts +79 -0
- package/src/providers/supabase-dm.ts +122 -117
- package/src/providers/supabase-voice.ts +91 -0
- package/src/providers/supabase.ts +120 -96
- package/src/server.ts +123 -103
- package/src/tools/actions.ts +162 -0
- package/src/tools/attachments.ts +268 -0
- package/src/tools/capabilities.ts +68 -68
- package/src/tools/embed.ts +108 -0
- package/src/tools/index.ts +76 -37
- package/src/tools/knowledge.ts +191 -0
- package/src/tools/mail-provenance.ts +137 -0
- package/src/tools/mail.ts +378 -89
- package/src/tools/mcall.ts +216 -0
- package/src/tools/mdm-voice.ts +206 -0
- package/src/tools/mdm.ts +451 -379
- package/src/tools/mirc-edge.ts +190 -0
- package/src/tools/mirc-members.ts +188 -177
- package/src/tools/mirc-messages.ts +155 -0
- package/src/tools/mirc.ts +176 -170
- package/src/tools/mroom-messages.ts +142 -142
- package/src/tools/mroom.ts +221 -189
- package/src/tools/mtalk.ts +121 -0
- package/src/tools/murl.ts +195 -0
- package/src/tools/ptt-ingest.ts +92 -0
- package/src/tools/threat.ts +92 -0
- package/src/types.ts +94 -79
- package/src/voice/floor.ts +132 -0
- package/dist/chunk-HD5RLE5K.js +0 -1193
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mURL — IRC-for-URLs: real-time chat attached to any web DOMAIN, AGENT-NATIVE.
|
|
3
|
+
*
|
|
4
|
+
* Same mosadd-edge Cloudflare Worker / Durable Object backend as mIRC edge, but the
|
|
5
|
+
* channel id is the DOMAIN SLUG (domain lowercased, "." → "-"). A domain channel is
|
|
6
|
+
* auto-created on first activity (status "open"); a domain owner can later verify/claim it.
|
|
7
|
+
*
|
|
8
|
+
* THE WEDGE: every prior "chat on a web page" (Google Sidewiki, Genius, Hypothes.is,
|
|
9
|
+
* HERE.fm) died on the empty-room cold-start because they were HUMAN-ONLY — you arrive,
|
|
10
|
+
* nobody's there, you leave. mURL is agent-native: an AI agent researching a domain can
|
|
11
|
+
* READ the channel (human + agent context — "is this a scam?", "promo code here") and
|
|
12
|
+
* WRITE findings back, so the room is never empty. First per-domain chat where agents are
|
|
13
|
+
* first-class citizens.
|
|
14
|
+
*
|
|
15
|
+
* Auth: MOSADD_API_KEY (hub key) for read/post; presence is public.
|
|
16
|
+
*/
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
19
|
+
import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
|
|
20
|
+
|
|
21
|
+
const DEFAULT_EDGE_URL = "https://mosadd-edge.mr-brics-33.workers.dev";
|
|
22
|
+
function edgeUrl(): string {
|
|
23
|
+
return process.env.MOSADD_EDGE_URL?.replace(/\/$/, "") ?? DEFAULT_EDGE_URL;
|
|
24
|
+
}
|
|
25
|
+
function hubKey(): string {
|
|
26
|
+
const key = process.env.MOSADD_API_KEY ?? process.env.MOSADD_HUB_KEY ?? "";
|
|
27
|
+
if (!key) throw new Error("MOSADD_API_KEY required for mURL tools (see `mosadd login` / hub-keys).");
|
|
28
|
+
return key;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A domain OR full URL → { domain, slug }. slug = host lowercased, "." → "-". */
|
|
32
|
+
function domainToSlug(input: string): { domain: string; slug: string } {
|
|
33
|
+
let host = String(input).trim().toLowerCase();
|
|
34
|
+
host = host.replace(/^[a-z]+:\/\//, "").replace(/[/?#].*$/, "").replace(/:\d+$/, "");
|
|
35
|
+
if (host.startsWith("www.")) host = host.slice(4);
|
|
36
|
+
if (!host || !/^[a-z0-9-]+(\.[a-z0-9-]+)+$/.test(host)) {
|
|
37
|
+
throw new Error(`Invalid domain: "${input}" — pass a domain like "example.com" or a URL.`);
|
|
38
|
+
}
|
|
39
|
+
return { domain: host, slug: host.replace(/\./g, "-") };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const DomainArg = z
|
|
43
|
+
.string()
|
|
44
|
+
.min(3)
|
|
45
|
+
.max(255)
|
|
46
|
+
.describe("A domain (e.g. 'example.com') or a full URL — the channel is keyed to the domain.");
|
|
47
|
+
|
|
48
|
+
// ── read ──────────────────────────────────────────────────────────────────────
|
|
49
|
+
const mURL_read_channel_input = z.object({
|
|
50
|
+
domain: DomainArg,
|
|
51
|
+
limit: z.number().int().min(1).max(100).optional().describe("Recent messages to return (max 100). Default 50."),
|
|
52
|
+
});
|
|
53
|
+
async function mURL_read_channel(
|
|
54
|
+
input: z.infer<typeof mURL_read_channel_input>,
|
|
55
|
+
ctx: MosaddToolContext,
|
|
56
|
+
): Promise<{ domain: string; messages: Array<{ id: string; from: string | null; text: string; timestamp: number }> }> {
|
|
57
|
+
const { domain, slug } = domainToSlug(input.domain);
|
|
58
|
+
const limit = input.limit ?? 50;
|
|
59
|
+
ctx.log("debug", "mURL_read_channel", { domain });
|
|
60
|
+
const r = await fetch(`${edgeUrl()}/c/${slug}/history?limit=${limit}`, {
|
|
61
|
+
headers: { Authorization: `Bearer ${hubKey()}` },
|
|
62
|
+
});
|
|
63
|
+
if (!r.ok) {
|
|
64
|
+
const e = await r.text().catch(() => "");
|
|
65
|
+
throw new Error(`mosadd-edge ${r.status}: ${e.slice(0, 200)}`);
|
|
66
|
+
}
|
|
67
|
+
const data = (await r.json()) as { messages?: Array<{ id: string; ts: number; from?: string | null; text: string }> };
|
|
68
|
+
return {
|
|
69
|
+
domain,
|
|
70
|
+
messages: (data.messages ?? []).map((m) => ({ id: m.id, from: m.from ?? null, text: m.text, timestamp: m.ts })),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ── post ──────────────────────────────────────────────────────────────────────
|
|
75
|
+
const mURL_post_input = z.object({
|
|
76
|
+
domain: DomainArg,
|
|
77
|
+
text: z.string().min(1).max(2000).describe("Message body (max 2000 chars, up to 3 lines — Worker-enforced)."),
|
|
78
|
+
from: z.string().max(120).optional().describe("Sender hint shown to others (defaults to the hub-key owner / your agent name)."),
|
|
79
|
+
});
|
|
80
|
+
async function mURL_post(
|
|
81
|
+
input: z.infer<typeof mURL_post_input>,
|
|
82
|
+
ctx: MosaddToolContext,
|
|
83
|
+
): Promise<{ domain: string; message_id: string; posted_at: number }> {
|
|
84
|
+
const { domain, slug } = domainToSlug(input.domain);
|
|
85
|
+
ctx.log("debug", "mURL_post", { domain });
|
|
86
|
+
const r = await fetch(`${edgeUrl()}/c/${slug}/send`, {
|
|
87
|
+
method: "POST",
|
|
88
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${hubKey()}` },
|
|
89
|
+
body: JSON.stringify({ text: input.text, from: input.from }),
|
|
90
|
+
});
|
|
91
|
+
if (!r.ok) {
|
|
92
|
+
const e = await r.text().catch(() => "");
|
|
93
|
+
throw new Error(`mosadd-edge ${r.status}: ${e.slice(0, 200)}`);
|
|
94
|
+
}
|
|
95
|
+
const data = (await r.json()) as { id?: string; ts?: number };
|
|
96
|
+
if (!data?.id) throw new Error("mosadd-edge: send returned no id");
|
|
97
|
+
return { domain, message_id: data.id, posted_at: data.ts ?? Date.now() };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ── list_channels (discovery) ────────────────────────────────────────────────
|
|
101
|
+
const mURL_list_channels_input = z.object({
|
|
102
|
+
action: z
|
|
103
|
+
.enum(["trending", "list", "mine"])
|
|
104
|
+
.optional()
|
|
105
|
+
.describe("'trending' (default) = most active domain channels in the last N hours; 'list' = paginated catalogue filtered by status; 'mine' = channels you own (DNS-verified)."),
|
|
106
|
+
limit: z.number().int().min(1).max(100).optional().describe("Max channels to return. Default 20."),
|
|
107
|
+
hours: z.number().int().min(1).max(168).optional().describe("Trending window in hours. Default 24, max 168 (7d)."),
|
|
108
|
+
status: z.enum(["open", "claimed", "blocked"]).optional().describe("For action='list': filter (default 'open')."),
|
|
109
|
+
cursor: z.string().optional().describe("For action='list': pagination — pass previous response's next_cursor (created_at ISO)."),
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
interface MurlChannel {
|
|
113
|
+
domain: string;
|
|
114
|
+
slug: string;
|
|
115
|
+
status: string;
|
|
116
|
+
branding?: unknown;
|
|
117
|
+
verified_at?: string | null;
|
|
118
|
+
created_at?: string;
|
|
119
|
+
updated_at?: string;
|
|
120
|
+
messages_in_window?: number;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function mURL_list_channels(
|
|
124
|
+
input: z.infer<typeof mURL_list_channels_input>,
|
|
125
|
+
ctx: MosaddToolContext,
|
|
126
|
+
): Promise<{
|
|
127
|
+
channels: MurlChannel[];
|
|
128
|
+
count: number;
|
|
129
|
+
next_cursor?: string | null;
|
|
130
|
+
hours?: number;
|
|
131
|
+
since?: string;
|
|
132
|
+
}> {
|
|
133
|
+
readSupabaseEnv();
|
|
134
|
+
const action = input.action ?? "trending";
|
|
135
|
+
ctx.log("debug", "mURL_list_channels invoking murl-channels", { action });
|
|
136
|
+
return await invokeFunction("murl-channels", {
|
|
137
|
+
action,
|
|
138
|
+
limit: input.limit ?? null,
|
|
139
|
+
hours: input.hours ?? null,
|
|
140
|
+
status: input.status ?? null,
|
|
141
|
+
cursor: input.cursor ?? null,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ── presence ────────────────────────────────────────────────────────────────────
|
|
146
|
+
const mURL_presence_input = z.object({ domain: DomainArg });
|
|
147
|
+
async function mURL_presence(
|
|
148
|
+
input: z.infer<typeof mURL_presence_input>,
|
|
149
|
+
ctx: MosaddToolContext,
|
|
150
|
+
): Promise<{ domain: string; count: number; roster: string[]; status: string }> {
|
|
151
|
+
const { domain, slug } = domainToSlug(input.domain);
|
|
152
|
+
ctx.log("debug", "mURL_presence", { domain });
|
|
153
|
+
const r = await fetch(`${edgeUrl()}/c/${slug}/presence`);
|
|
154
|
+
if (!r.ok) {
|
|
155
|
+
const e = await r.text().catch(() => "");
|
|
156
|
+
throw new Error(`mosadd-edge ${r.status}: ${e.slice(0, 200)}`);
|
|
157
|
+
}
|
|
158
|
+
const data = (await r.json()) as { count?: number; roster?: string[]; status?: string };
|
|
159
|
+
return { domain, count: data.count ?? 0, roster: data.roster ?? [], status: data.status ?? "open" };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export const murlTools: MosaddTool[] = [
|
|
163
|
+
{
|
|
164
|
+
name: "mURL_read_channel",
|
|
165
|
+
requires: "network",
|
|
166
|
+
description:
|
|
167
|
+
"Read the live chat channel for a web DOMAIN (mURL — 'IRC for URLs'). Returns the most recent messages humans and agents have posted about that domain. Use it to get real-time, crowd-sourced context before acting on a site — e.g. scam warnings, promo codes, outage reports, 'is this legit?'. The channel auto-exists for any domain. Auth: MOSADD_API_KEY (hub key).",
|
|
168
|
+
inputSchema: mURL_read_channel_input,
|
|
169
|
+
handler: mURL_read_channel as MosaddTool["handler"],
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
name: "mURL_post",
|
|
173
|
+
requires: "network",
|
|
174
|
+
description:
|
|
175
|
+
"Post a message into a web DOMAIN's mURL chat channel — leave context for the humans and agents who visit that site next (a finding, warning, tip, or coordination note). Sub-100ms global fan-out to everyone currently on the channel. Auth: MOSADD_API_KEY (hub key).",
|
|
176
|
+
inputSchema: mURL_post_input,
|
|
177
|
+
handler: mURL_post as MosaddTool["handler"],
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
name: "mURL_presence",
|
|
181
|
+
requires: "network",
|
|
182
|
+
description:
|
|
183
|
+
"Who is on a domain's mURL channel right now: live participant count + roster nicknames + channel status (open/claimed/blocked). Public (no key needed). Use it to gauge whether a domain has an active audience before posting.",
|
|
184
|
+
inputSchema: mURL_presence_input,
|
|
185
|
+
handler: mURL_presence as MosaddTool["handler"],
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
name: "mURL_list_channels",
|
|
189
|
+
requires: "network",
|
|
190
|
+
description:
|
|
191
|
+
"Discovery for mURL domain channels: 'trending' (most active in the last N hours, default 24) / 'list' (paginated catalogue, status-filtered) / 'mine' (channels you DNS-verified). Returns domain, slug, status, branding, verified_at + (for trending) messages_in_window. For who's-on-now, follow up with mURL_presence on the slug.",
|
|
192
|
+
inputSchema: mURL_list_channels_input,
|
|
193
|
+
handler: mURL_list_channels as MosaddTool["handler"],
|
|
194
|
+
},
|
|
195
|
+
];
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PTT capture → ingest → RAG transcription.
|
|
3
|
+
*
|
|
4
|
+
* mTALK (mtalk.ts) drives the live half-duplex FLOOR (who may transmit). What it
|
|
5
|
+
* does NOT do is capture a finished PTT transmission as a durable, queued message
|
|
6
|
+
* — i.e. a recorded "over" that lands in a channel's queued-PTT log AND (opt-in)
|
|
7
|
+
* gets transcribed into RAG. That's this module.
|
|
8
|
+
*
|
|
9
|
+
* Flow (per the Lane A contract):
|
|
10
|
+
* 1. agent records/has a PTT clip → base64 → uploadBlob(kind:'ptt') to
|
|
11
|
+
* 'voice-blobs'.
|
|
12
|
+
* 2. call `ptt-ingest` EF with the attachment descriptor + routing (which
|
|
13
|
+
* channel/room the "over" belongs to). The EF persists a queued-PTT message.
|
|
14
|
+
* 3. if the user has opted in to RAG, `rag-transcribe` runs and the transcript
|
|
15
|
+
* lands in user_embeddings(source_type='ptt').
|
|
16
|
+
*
|
|
17
|
+
* STATUS: scaffold — `ptt-ingest` is not yet deployed. Upload is real; the EF
|
|
18
|
+
* call shape is best-guess (TODO Lane A).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { z } from "zod";
|
|
22
|
+
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
23
|
+
import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
|
|
24
|
+
import { uploadBlob, decodeBase64Body } from "../providers/blob-upload.js";
|
|
25
|
+
|
|
26
|
+
const mTALK_ingest_ptt_input = z.object({
|
|
27
|
+
audio_base64: z
|
|
28
|
+
.string()
|
|
29
|
+
.min(1)
|
|
30
|
+
.max(20_000_000)
|
|
31
|
+
.describe("Recorded PTT 'over' as base64 (or data: URL)."),
|
|
32
|
+
mime: z.string().min(1).max(120).default("audio/ogg"),
|
|
33
|
+
duration_ms: z.number().int().positive().optional(),
|
|
34
|
+
// Routing: exactly one of room_id / channel_id identifies where the over lands.
|
|
35
|
+
channel_id: z.string().optional().describe("mIRC channel id — route the queued PTT into the channel's PTT log."),
|
|
36
|
+
// room_id retained for the rare mTALK-only PTT room (no mIRC channel backing). mROOM is gone — do NOT pass an mROOM id (will 404). Prefer channel_id.
|
|
37
|
+
room_id: z.string().optional().describe("Optional mTALK-only PTT room id (no mIRC channel backing). For mIRC channels use channel_id."),
|
|
38
|
+
transcribe: z
|
|
39
|
+
.boolean()
|
|
40
|
+
.optional()
|
|
41
|
+
.describe("Request RAG transcription. Honored only if the user has opted in to rag ingest; ignored otherwise. Default true."),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
async function mTALK_ingest_ptt(
|
|
45
|
+
input: z.infer<typeof mTALK_ingest_ptt_input>,
|
|
46
|
+
ctx: MosaddToolContext,
|
|
47
|
+
): Promise<{ ptt_id: string; queued: true; transcription: "queued" | "skipped" | "opted_out" }> {
|
|
48
|
+
readSupabaseEnv();
|
|
49
|
+
if (!input.channel_id && !input.room_id) {
|
|
50
|
+
throw new Error("mTALK_ingest_ptt requires one of channel_id or room_id to route the queued PTT.");
|
|
51
|
+
}
|
|
52
|
+
const prefix = input.channel_id ? `chat:${input.channel_id}` : `room:${input.room_id}`;
|
|
53
|
+
const attachment = await uploadBlob({
|
|
54
|
+
kind: "ptt",
|
|
55
|
+
bytes: decodeBase64Body(input.audio_base64),
|
|
56
|
+
mime: input.mime,
|
|
57
|
+
prefix,
|
|
58
|
+
duration_ms: input.duration_ms,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
ctx.log("debug", "mTALK_ingest_ptt invoking ptt-ingest", { prefix, transcribe: input.transcribe ?? true });
|
|
62
|
+
|
|
63
|
+
// TODO(Lane A): `ptt-ingest` EF not yet deployed. Confirm request/response shape.
|
|
64
|
+
// Expected: persists a queued-PTT message_meta row (message_type:'ptt') with the
|
|
65
|
+
// attachment, then (if rag opt-in) enqueues rag-transcribe → user_embeddings(source_type='ptt').
|
|
66
|
+
const res = await invokeFunction<{
|
|
67
|
+
ptt_id?: string;
|
|
68
|
+
transcription?: "queued" | "skipped" | "opted_out";
|
|
69
|
+
}>("ptt-ingest", {
|
|
70
|
+
attachment,
|
|
71
|
+
channel_id: input.channel_id ?? null,
|
|
72
|
+
room_id: input.room_id ?? null,
|
|
73
|
+
transcribe: input.transcribe ?? true,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
ptt_id: res.ptt_id ?? "",
|
|
78
|
+
queued: true,
|
|
79
|
+
transcription: res.transcription ?? "queued",
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export const pttIngestTools: MosaddTool[] = [
|
|
84
|
+
{
|
|
85
|
+
name: "mTALK_ingest_ptt",
|
|
86
|
+
requires: "network",
|
|
87
|
+
description:
|
|
88
|
+
"Capture a finished PTT transmission (an 'over') as a durable, QUEUED PTT message in an mIRC channel, and — if the user has opted in to RAG — transcribe it into searchable knowledge. Pass the clip as base64 + a route (channel_id; or room_id for an mTALK-only PTT room without a channel backing). Complements mTALK_press/release (which only manage the live floor).",
|
|
89
|
+
inputSchema: mTALK_ingest_ptt_input,
|
|
90
|
+
handler: mTALK_ingest_ptt as MosaddTool["handler"],
|
|
91
|
+
},
|
|
92
|
+
];
|
|
@@ -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
|
+
];
|
package/src/types.ts
CHANGED
|
@@ -1,79 +1,94 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal types for the mosadd MCP server.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { z } from "zod";
|
|
6
|
-
import type { DmProvider } from "@mosadd/providers";
|
|
7
|
-
import type { MdmKeyStore } from "./crypto/mdm-session.js";
|
|
8
|
-
|
|
9
|
-
export type Mode = "cloud" | "local" | "self-host";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Transport backends per channel. The server fills any missing entry with its
|
|
13
|
-
* default network adapter; a host (e.g. cymru-os) injects alternatives —
|
|
14
|
-
* notably a radio DmProvider — via `MosaddServerOptions.providers`. This is
|
|
15
|
-
* the DI seam that keeps mosadd-os transport-agnostic.
|
|
16
|
-
*
|
|
17
|
-
* `keys` is LOCAL crypto custody (identity + prekeys + ratchet sessions) for
|
|
18
|
-
* mDM E2EE — distinct from transport. Defaults to an in-process keystore; a
|
|
19
|
-
* host may inject a file/keychain-backed one.
|
|
20
|
-
*/
|
|
21
|
-
export interface ProviderRegistry {
|
|
22
|
-
dm: DmProvider;
|
|
23
|
-
keys: MdmKeyStore;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
providers
|
|
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
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Internal types for the mosadd MCP server.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { z } from "zod";
|
|
6
|
+
import type { DmProvider, VoiceProvider } from "@mosadd/providers";
|
|
7
|
+
import type { MdmKeyStore } from "./crypto/mdm-session.js";
|
|
8
|
+
|
|
9
|
+
export type Mode = "cloud" | "local" | "self-host";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Transport backends per channel. The server fills any missing entry with its
|
|
13
|
+
* default network adapter; a host (e.g. cymru-os) injects alternatives —
|
|
14
|
+
* notably a radio DmProvider — via `MosaddServerOptions.providers`. This is
|
|
15
|
+
* the DI seam that keeps mosadd-os transport-agnostic.
|
|
16
|
+
*
|
|
17
|
+
* `keys` is LOCAL crypto custody (identity + prekeys + ratchet sessions) for
|
|
18
|
+
* mDM E2EE — distinct from transport. Defaults to an in-process keystore; a
|
|
19
|
+
* host may inject a file/keychain-backed one.
|
|
20
|
+
*/
|
|
21
|
+
export interface ProviderRegistry {
|
|
22
|
+
dm: DmProvider;
|
|
23
|
+
keys: MdmKeyStore;
|
|
24
|
+
/**
|
|
25
|
+
* mTALK push-to-talk transport. Defaults to the network provider (LiveKit
|
|
26
|
+
* media + authoritative floor state). A radio host injects a provider that
|
|
27
|
+
* maps the floor onto a physical RF channel.
|
|
28
|
+
*/
|
|
29
|
+
voice: VoiceProvider;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface MosaddServerOptions {
|
|
33
|
+
/** API key for hosted mode. Required if mode === "cloud". */
|
|
34
|
+
apiKey?: string;
|
|
35
|
+
/** Override the default hub URL (https://mcp.mosadd.com). */
|
|
36
|
+
hubUrl?: string;
|
|
37
|
+
/** Operating mode. Defaults to "cloud" if apiKey is present, else "local". */
|
|
38
|
+
mode?: Mode;
|
|
39
|
+
/** Log level. */
|
|
40
|
+
logLevel?: "debug" | "info" | "warn" | "error";
|
|
41
|
+
/**
|
|
42
|
+
* Host-injected channel providers. Any omitted channel uses the default
|
|
43
|
+
* network adapter. A carrier-aware host supplies e.g. a radio DmProvider here.
|
|
44
|
+
*/
|
|
45
|
+
providers?: Partial<ProviderRegistry>;
|
|
46
|
+
/**
|
|
47
|
+
* When true, publish this identity's mDM prekey bundle once on startup
|
|
48
|
+
* (best-effort, non-fatal) so peers can open an E2EE session without the user
|
|
49
|
+
* manually running mDM_publish_keys first. Fixes the cold-start where mDM_send
|
|
50
|
+
* fails for every recipient because nobody has published keys. Used by the
|
|
51
|
+
* stdio binary; the hosted per-request transport leaves this off (it publishes
|
|
52
|
+
* per authenticated session instead).
|
|
53
|
+
*/
|
|
54
|
+
autoPublishKeys?: boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface MosaddToolContext {
|
|
58
|
+
options: Required<Pick<MosaddServerOptions, "mode" | "hubUrl">> & MosaddServerOptions;
|
|
59
|
+
/** Resolved channel providers (defaults merged with host-injected ones). */
|
|
60
|
+
providers: ProviderRegistry;
|
|
61
|
+
/** Per-request logger. */
|
|
62
|
+
log: (level: "debug" | "info" | "warn" | "error", msg: string, extra?: unknown) => void;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Transport capability a tool requires to function. This is the ONE contract
|
|
67
|
+
* string shared with consuming hosts. e.g. cymru-os gates tools by carrier
|
|
68
|
+
* availability via this flag (cymru-os RFC 0002 D-Bus "Capability-flag bridge").
|
|
69
|
+
* The enum is FINAL and normalized with the cymru-os host; changing these
|
|
70
|
+
* values must be coordinated (Linear label `requires:cymru-input`).
|
|
71
|
+
*
|
|
72
|
+
* - "any" works over any transport, incl. off-grid radio (small,
|
|
73
|
+
* packet-friendly payloads). e.g. text DM.
|
|
74
|
+
* - "radio" radio-specific path (e.g. Codec2 audio frames). Off-grid OK.
|
|
75
|
+
* - "network" needs IP connectivity (server-hosted channels, email, public
|
|
76
|
+
* join links, bridges). NOT available off-grid.
|
|
77
|
+
*/
|
|
78
|
+
export type CapabilityRequirement = "any" | "radio" | "network";
|
|
79
|
+
|
|
80
|
+
export interface MosaddTool<TInput = unknown, TOutput = unknown> {
|
|
81
|
+
/** Tool name. MUST follow the m{MODULE}_{operation} convention. */
|
|
82
|
+
name: string;
|
|
83
|
+
/** Short human-readable description. Shown to the model. */
|
|
84
|
+
description: string;
|
|
85
|
+
/**
|
|
86
|
+
* Transport this tool requires. Consuming hosts read this to gate tools by
|
|
87
|
+
* available carriers. Every tool MUST declare it explicitly.
|
|
88
|
+
*/
|
|
89
|
+
requires: CapabilityRequirement;
|
|
90
|
+
/** Zod schema for input. */
|
|
91
|
+
inputSchema: z.ZodType<TInput>;
|
|
92
|
+
/** Tool handler. */
|
|
93
|
+
handler: (input: TInput, ctx: MosaddToolContext) => Promise<TOutput>;
|
|
94
|
+
}
|