@mosadd/mcp 3.0.0-alpha.3 → 3.0.0-alpha.31

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 (49) hide show
  1. package/CHANGELOG.md +224 -0
  2. package/README.md +150 -116
  3. package/dist/bin/mcp.js +42 -3
  4. package/dist/chunk-P4ENU5MW.js +2556 -0
  5. package/dist/index.d.ts +99 -7
  6. package/dist/index.js +7 -3
  7. package/package.json +10 -7
  8. package/src/__tests__/golden-path.test.ts +137 -132
  9. package/src/__tests__/integration.test.ts +179 -175
  10. package/src/__tests__/mdm-e2ee.test.ts +212 -149
  11. package/src/__tests__/mtalk.test.ts +122 -0
  12. package/src/__tests__/server.test.ts +71 -67
  13. package/src/bin/login.ts +138 -138
  14. package/src/bin/mcp.ts +145 -97
  15. package/src/config.ts +66 -66
  16. package/src/crypto/mdm-session.ts +502 -378
  17. package/src/index.ts +19 -17
  18. package/src/observability/sentry.ts +79 -79
  19. package/src/providers/blob-upload.ts +116 -0
  20. package/src/providers/memory-voice.ts +79 -0
  21. package/src/providers/supabase-dm.ts +122 -117
  22. package/src/providers/supabase-voice.ts +91 -0
  23. package/src/providers/supabase.ts +148 -96
  24. package/src/server.ts +123 -103
  25. package/src/tools/actions.ts +162 -0
  26. package/src/tools/attachments.ts +268 -0
  27. package/src/tools/capabilities.ts +68 -68
  28. package/src/tools/embed.ts +108 -0
  29. package/src/tools/index.ts +104 -37
  30. package/src/tools/knowledge.ts +191 -0
  31. package/src/tools/mail-aliases.ts +25 -0
  32. package/src/tools/mail-provenance.ts +135 -0
  33. package/src/tools/mail.ts +381 -89
  34. package/src/tools/mcall.ts +216 -0
  35. package/src/tools/mdm-voice.ts +212 -0
  36. package/src/tools/mdm.ts +479 -379
  37. package/src/tools/mirc-edge.ts +190 -0
  38. package/src/tools/mirc-members.ts +198 -177
  39. package/src/tools/mirc-messages.ts +155 -0
  40. package/src/tools/mirc.ts +190 -170
  41. package/src/tools/mroom-messages.ts +142 -142
  42. package/src/tools/mroom.ts +221 -189
  43. package/src/tools/mtalk.ts +121 -0
  44. package/src/tools/murl.ts +298 -0
  45. package/src/tools/ptt-ingest.ts +97 -0
  46. package/src/tools/threat.ts +119 -0
  47. package/src/types.ts +94 -79
  48. package/src/voice/floor.ts +132 -0
  49. package/dist/chunk-HD5RLE5K.js +0 -1193
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import { z } from 'zod';
3
- import { DmProvider } from '@mosadd/providers';
4
- import { RatchetState, SessionRole } from '@mosadd/crypto';
3
+ import { DmProvider, VoiceProvider } from '@mosadd/providers';
4
+ import { RatchetState, DhRatchetState, SessionRole } from '@mosadd/crypto';
5
5
 
6
6
  /**
7
7
  * mDM end-to-end encryption — session layer (LINEAR-2357).
@@ -53,9 +53,14 @@ interface OwnPrekeyMaterial {
53
53
  pair: X25519Pair;
54
54
  }>;
55
55
  }
56
- /** Persisted per-peer ratchet session. Plain data → trivially serializable. */
56
+ /**
57
+ * Persisted per-peer ratchet session. Plain data → trivially serializable.
58
+ * A session is either v1 (`ratchet`, symmetric) or v2 (`ratchet2`, DH ratchet /
59
+ * PCS). New sessions are v2; an existing v1 session keeps running v1.
60
+ */
57
61
  interface MdmSessionRecord {
58
- ratchet: RatchetState;
62
+ ratchet?: RatchetState;
63
+ ratchet2?: DhRatchetState;
59
64
  role: SessionRole;
60
65
  /** Handshake header still owed to the peer (initiator only, until first send). */
61
66
  pendingHandshake?: {
@@ -75,6 +80,21 @@ interface MdmKeyStore {
75
80
  takeOneTimePrekey(id: number): Promise<Uint8Array | undefined>;
76
81
  getSession(peerId: string): Promise<MdmSessionRecord | undefined>;
77
82
  putSession(peerId: string, record: MdmSessionRecord): Promise<void>;
83
+ /**
84
+ * OPTIONAL local "sent items" cache. The Double Ratchet is forward-secret and
85
+ * asymmetric: once we seal a message for a peer we cannot re-derive its
86
+ * plaintext from our own ratchet on read. So mDM_list cannot show the sender
87
+ * their OWN outgoing text unless we keep a local copy. These two methods are
88
+ * that copy — keyed by the provider-assigned message id.
89
+ *
90
+ * Honesty note: this is a LOCAL plaintext cache, not synced across devices.
91
+ * A second device (or a fresh process) won't have it and will fall back to a
92
+ * "<encrypted · sent by you>" marker. Cross-device sent-history sync is a
93
+ * tracked follow-up (would need an encrypt-to-self session). Optional so
94
+ * existing MdmKeyStore implementations keep compiling.
95
+ */
96
+ putSentMessage?(messageId: string, plaintext: Uint8Array): Promise<void>;
97
+ getSentMessage?(messageId: string): Promise<Uint8Array | undefined>;
78
98
  }
79
99
 
80
100
  /**
@@ -95,6 +115,12 @@ type Mode = "cloud" | "local" | "self-host";
95
115
  interface ProviderRegistry {
96
116
  dm: DmProvider;
97
117
  keys: MdmKeyStore;
118
+ /**
119
+ * mTALK push-to-talk transport. Defaults to the network provider (LiveKit
120
+ * media + authoritative floor state). A radio host injects a provider that
121
+ * maps the floor onto a physical RF channel.
122
+ */
123
+ voice: VoiceProvider;
98
124
  }
99
125
  interface MosaddServerOptions {
100
126
  /** API key for hosted mode. Required if mode === "cloud". */
@@ -110,6 +136,15 @@ interface MosaddServerOptions {
110
136
  * network adapter. A carrier-aware host supplies e.g. a radio DmProvider here.
111
137
  */
112
138
  providers?: Partial<ProviderRegistry>;
139
+ /**
140
+ * When true, publish this identity's mDM prekey bundle once on startup
141
+ * (best-effort, non-fatal) so peers can open an E2EE session without the user
142
+ * manually running mDM_publish_keys first. Fixes the cold-start where mDM_send
143
+ * fails for every recipient because nobody has published keys. Used by the
144
+ * stdio binary; the hosted per-request transport leaves this off (it publishes
145
+ * per authenticated session instead).
146
+ */
147
+ autoPublishKeys?: boolean;
113
148
  }
114
149
  interface MosaddToolContext {
115
150
  options: Required<Pick<MosaddServerOptions, "mode" | "hubUrl">> & MosaddServerOptions;
@@ -165,10 +200,67 @@ declare function createMosaddServer(options?: MosaddServerOptions): McpServer;
165
200
  /**
166
201
  * Tool registry. Each m* module contributes a set of tools.
167
202
  *
168
- * Phase 1 MVP (shipped): mDM, mIRC, mROOM, mAIL.
169
- * Phase 1 full: + mTALK, mCALL, mIRL, plus bridges (mMATRIX, mDISCORD, mTELEGRAM, mSLACK, mSIGNAL).
203
+ * User-facing modules (4): mDM, mIRC, mURL, mAYL — the re-arch (LINEAR-3938)
204
+ * mAYL replaces the old mp0st name (mp0st_* still registered as back-compat
205
+ * aliases via mail-aliases.ts; will be removed in a later alpha).
206
+ *
207
+ * Capabilities (not modules — cross-cutting agent tooling): mRAG, comms_.
208
+ * mTALK = voice tier inside mIRC, still its own tools for now; folding into
209
+ * mIRC_voice_* in a follow-up release. threat_* (threat_catalog + threat_classify)
210
+ * are REGISTERED (2026-07-15, founder directive + LINEAR-3498): pure/offline
211
+ * defensive classification over the threat taxonomy — the surveillance-era
212
+ * *marketing* was killed, the classification engine is real and wanted.
213
+ *
214
+ * 69 callable tools registered — the exact live count is exported as TOOL_COUNT
215
+ * (= allTools.length) below; ALWAYS reference that, never re-hard-code a number that drifts.
216
+ * Breakdown (2026-07-17): mDM 14 · mIRC 22 · mAYL 11 · mURL 7 · mTALK 5 · mRAG 4 ·
217
+ * comms 3 (action_create/frame_get/embed_create) · Irondome/threat 2 + comms_capabilities
218
+ * discovery 1 = 69. (mDM/mIRC each include their 2 attachment tools from attachments.ts.)
219
+ * Modules (4): mDM, mIRC, mURL, mAYL. Capabilities: mTALK (voice/PTT), mRAG, comms_, Irondome (threat_*).
220
+ * mp0st_* stay as DEPRECATED back-compat aliases for mAYL_* (removed in a later alpha).
221
+ * UNREGISTERED 2026-07-14 (broken scaffolds whose EFs 404/400 every call — re-register when
222
+ * live): mAYL_send_as_agent (mail-provenance), mTALK_ingest_ptt (ptt-ingest).
223
+ * comms_embed_create RE-REGISTERED 2026-07-17 (embed.mosadd.com/v1.js live — P3 of mURL→mIRC).
224
+ * mROOM was KILLED (LINEAR-3414, channel re-cut → ephemeral private mIRC): its tools
225
+ * live in tools/mroom.ts + mroom-messages.ts but are NOT registered here.
226
+ * Plus action links: comms_action_create (agent → user one-link browser action,
227
+ * incl. screen_share) + comms_action_frame_get (see the recipient's shared screen).
228
+ * mURL is a FULL registered dev module (revived, founder 2026-06-27) — IRC-for-URLs,
229
+ * agent-native; backends live (mosadd-edge + murl-channels EF). tools/murl.ts.
230
+ * mURL now has full lifecycle: read/post/presence/list_channels (hub-key) PLUS owner-side
231
+ * create/claim + update(branding/status) + delete (mURL_create/update/delete → murl-manage
232
+ * EF, owner-scoped via user JWT — same auth as mURL_list_channels action='mine').
233
+ * mCALL is carrier-pending (no telephony carrier live yet): its tools live in
234
+ * tools/mcall.ts but are NOT registered here, so an agent only ever discovers
235
+ * tools that actually work. Re-register the one line below when a carrier ships.
170
236
  */
171
237
 
172
238
  declare const allTools: MosaddTool[];
239
+ /**
240
+ * The exact, live number of callable tools this server registers. Reference THIS
241
+ * (import { TOOL_COUNT }) in any code/doc surface that shows a tool count, instead
242
+ * of hard-coding a number that silently drifts (the "70+/65/68" inconsistency that
243
+ * bit us). Mirrors @mosadd/threat-engine's THREAT_EVENT_COUNT pattern.
244
+ */
245
+ declare const TOOL_COUNT: number;
246
+
247
+ /**
248
+ * Supabase provider for the alpha MCP server.
249
+ *
250
+ * Local BYOK mode: user supplies their own Supabase URL + anon key + user JWT
251
+ * via env vars. The MCP server creates a per-request Supabase client and
252
+ * invokes the mosadd Edge Functions on the user's behalf.
253
+ *
254
+ * In Phase 2 this is replaced by the hosted gateway (mcp.mosadd.com) which
255
+ * holds keys server-side via the BYOK broker.
256
+ */
257
+
258
+ interface SupabaseEnv {
259
+ url: string;
260
+ anonKey: string;
261
+ userJwt?: string;
262
+ }
263
+ /** Run `fn` (and every tool call it triggers) with a per-request Supabase session. */
264
+ declare function runWithSupabaseEnv<T>(env: SupabaseEnv, fn: () => T): T;
173
265
 
174
- export { type MosaddServerOptions, type MosaddTool, type MosaddToolContext, type ProviderRegistry, allTools, createMosaddServer, defaultProviders };
266
+ export { type MosaddServerOptions, type MosaddTool, type MosaddToolContext, type ProviderRegistry, type SupabaseEnv, TOOL_COUNT, allTools, createMosaddServer, defaultProviders, runWithSupabaseEnv };
package/dist/index.js CHANGED
@@ -1,11 +1,15 @@
1
1
  import {
2
+ TOOL_COUNT,
2
3
  allTools,
3
4
  createMosaddServer,
4
- defaultProviders
5
- } from "./chunk-HD5RLE5K.js";
5
+ defaultProviders,
6
+ runWithSupabaseEnv
7
+ } from "./chunk-P4ENU5MW.js";
6
8
  import "./chunk-Z7WR52GE.js";
7
9
  export {
10
+ TOOL_COUNT,
8
11
  allTools,
9
12
  createMosaddServer,
10
- defaultProviders
13
+ defaultProviders,
14
+ runWithSupabaseEnv
11
15
  };
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@mosadd/mcp",
3
- "version": "3.0.0-alpha.3",
4
- "description": "Model Context Protocol server for mosadd. Exposes m* OS modules (mDM, mTALK, mAIL, mCALL, mIRC, mIRL, mROOM, and bridges) as MCP tools to any agent runtime (Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom).",
5
- "homepage": "https://github.com/Hei33enberg/mosadd-os/tree/main/packages/mcp",
3
+ "version": "3.0.0-alpha.31",
4
+ "mcpName": "io.github.hei33enberg/mosadd-mcp",
5
+ "description": "Model Context Protocol server for mosadd. Exposes 4 modules (mDM, mIRC, mURL, mAYL) and capabilities (mTALK, mRAG) plus comms agent-actions — 69 tools — to any agent runtime (Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom).",
6
+ "homepage": "https://github.com/Hei33enberg/mosADD-OS/tree/main/packages/mcp",
6
7
  "repository": {
7
8
  "type": "git",
8
- "url": "https://github.com/Hei33enberg/mosadd-os.git",
9
+ "url": "https://github.com/Hei33enberg/mosADD-OS.git",
9
10
  "directory": "packages/mcp"
10
11
  },
11
12
  "license": "Apache-2.0",
@@ -27,6 +28,7 @@
27
28
  "dist",
28
29
  "src",
29
30
  "README.md",
31
+ "CHANGELOG.md",
30
32
  "LICENSE"
31
33
  ],
32
34
  "publishConfig": {
@@ -36,9 +38,10 @@
36
38
  "@modelcontextprotocol/sdk": "^1.0.4",
37
39
  "@supabase/supabase-js": "^2.48.0",
38
40
  "zod": "^4.3.6",
39
- "@mosadd/crypto": "3.0.0-alpha.0",
40
- "@mosadd/providers": "3.0.0-alpha.0",
41
- "@mosadd/protocol": "3.0.0-alpha.0"
41
+ "@mosadd/crypto": "3.0.0-alpha.26",
42
+ "@mosadd/protocol": "3.0.0-alpha.26",
43
+ "@mosadd/threat-engine": "3.0.0-alpha.26",
44
+ "@mosadd/providers": "3.0.0-alpha.26"
42
45
  },
43
46
  "devDependencies": {
44
47
  "tsup": "^8.3.5",
@@ -1,132 +1,137 @@
1
- /**
2
- * Golden-path E2E: the day-1 "done" bar for the provider-abstraction seam.
3
- *
4
- * Proves a carrier-aware HOST (e.g. cymru-os) can inject its own transport
5
- * under mDM without mosadd-os knowing anything about that transport:
6
- * 1. host learns capabilities (comms_capabilities) and sees mDM_send = "any"
7
- * (usable off-grid over radio),
8
- * 2. host injects a fake RadioProvider,
9
- * 3. agent calls mDM_send,
10
- * 4. the opaque payload bytes actually arrive at the injected provider,
11
- * 5. they round-trip back out via mDM_list.
12
- *
13
- * This is the "is it sp, not just written" check the whole 2144 task hinges on.
14
- */
15
-
16
- import { describe, expect, it } from "vitest";
17
- import type {
18
- DmProvider,
19
- DmSendArgs,
20
- DmListArgs,
21
- DmSendResult,
22
- DmListResult,
23
- } from "@mosadd/providers";
24
- import { mdmTools } from "../tools/mdm.js";
25
- import { makeCapabilitiesTool } from "../tools/capabilities.js";
26
- import { allTools } from "../tools/index.js";
27
- import { createMosaddServer } from "../server.js";
28
- import { InMemoryMdmKeyStore } from "../crypto/mdm-session.js";
29
- import type { MosaddToolContext, ProviderRegistry } from "../types.js";
30
-
31
- /** Stand-in for a host-supplied radio transport: captures the bytes it's asked
32
- * to send, and replays them on list — i.e. "the message reached the link". */
33
- class FakeRadioDmProvider implements DmProvider {
34
- public readonly sent: DmSendArgs[] = [];
35
- private bundle: Uint8Array | null = null;
36
- async selfId(): Promise<string> {
37
- return "radio:self-callsign";
38
- }
39
- async send(args: DmSendArgs): Promise<DmSendResult> {
40
- this.sent.push(args);
41
- return { id: `radio-${this.sent.length}`, deliveredAt: new Date(0).toISOString() };
42
- }
43
- async list(args: DmListArgs): Promise<DmListResult> {
44
- return {
45
- messages: this.sent
46
- .filter((s) => s.threadId === args.threadId)
47
- .map((s, i) => ({
48
- id: `radio-${i + 1}`,
49
- senderId: "radio:self-callsign",
50
- payload: s.payload,
51
- timestamp: new Date(0).toISOString(),
52
- threadId: s.threadId,
53
- })),
54
- nextCursor: null,
55
- };
56
- }
57
- async publishPrekeyBundle(bundle: Uint8Array): Promise<void> {
58
- this.bundle = bundle;
59
- }
60
- async fetchPrekeyBundle(): Promise<Uint8Array | null> {
61
- return this.bundle;
62
- }
63
- }
64
-
65
- function makeCtx(providers: { dm: DmProvider; keys?: ProviderRegistry["keys"] }): MosaddToolContext {
66
- return {
67
- options: { mode: "local", hubUrl: "https://mcp.mosadd.com" },
68
- providers: { dm: providers.dm, keys: providers.keys ?? new InMemoryMdmKeyStore() },
69
- log: () => {},
70
- };
71
- }
72
-
73
- const getTool = (name: string) => {
74
- const t = mdmTools.find((x) => x.name === name);
75
- if (!t) throw new Error(`tool ${name} not found`);
76
- return t;
77
- };
78
-
79
- describe("golden path — host injects transport under mDM", () => {
80
- it("step 1: comms_capabilities reports mDM_send usable over any carrier", async () => {
81
- const capTool = makeCapabilitiesTool(allTools);
82
- const manifest = (await capTool.handler({}, makeCtx({ dm: new FakeRadioDmProvider() }))) as {
83
- by_requirement: Record<string, string[]>;
84
- };
85
- expect(manifest.by_requirement.any).toContain("mDM_send");
86
- });
87
-
88
- it("steps 2-4: the deprecated plaintext path delivers opaque bytes to the injected provider", async () => {
89
- // This proves the TRANSPORT seam (2144): mDM_send_unencrypted packs a
90
- // plaintext envelope and the bytes reach the injected provider verbatim.
91
- // (mDM_send is now E2EE — its own round-trip is covered in mdm-e2ee.test.ts.)
92
- const radio = new FakeRadioDmProvider();
93
- const ctx = makeCtx({ dm: radio });
94
-
95
- const send = getTool("mDM_send_unencrypted");
96
- const result = (await send.handler(
97
- { to: "bob-callsign", text: "rendezvous at grid 4471, 0600" },
98
- ctx,
99
- )) as { message_id: string; thread_id: string };
100
-
101
- // The bytes actually reached the transport.
102
- expect(radio.sent).toHaveLength(1);
103
- expect(radio.sent[0]!.to).toBe("bob-callsign");
104
- expect(radio.sent[0]!.payload).toBeInstanceOf(Uint8Array);
105
- expect(radio.sent[0]!.payload.byteLength).toBeGreaterThan(0);
106
- expect(result.message_id).toBe("radio-1");
107
-
108
- // The payload is opaque to the provider but carries our text under the hood.
109
- const decoded = JSON.parse(Buffer.from(radio.sent[0]!.payload).toString("utf8"));
110
- expect(decoded.text).toBe("rendezvous at grid 4471, 0600");
111
- });
112
-
113
- it("step 5: mDM_list round-trips the message back through the same provider", async () => {
114
- const radio = new FakeRadioDmProvider();
115
- const ctx = makeCtx({ dm: radio });
116
-
117
- await getTool("mDM_send_unencrypted").handler({ to: "bob-callsign", text: "ack" }, ctx);
118
- const listed = (await getTool("mDM_list").handler({ contact_id: "bob-callsign" }, ctx)) as {
119
- messages: Array<{ text: string }>;
120
- };
121
-
122
- expect(listed.messages).toHaveLength(1);
123
- expect(listed.messages[0]!.text).toBe("ack");
124
- });
125
-
126
- it("default server wires a DmProvider without a host override (no throw)", () => {
127
- // Network default path: constructing the server must not require a host to
128
- // inject anything (it falls back to the Supabase adapter).
129
- expect(() => createMosaddServer()).not.toThrow();
130
- expect(() => createMosaddServer({ providers: { dm: new FakeRadioDmProvider() } })).not.toThrow();
131
- });
132
- });
1
+ /**
2
+ * Golden-path E2E: the day-1 "done" bar for the provider-abstraction seam.
3
+ *
4
+ * Proves a carrier-aware HOST (e.g. cymru-os) can inject its own transport
5
+ * under mDM without mosadd-os knowing anything about that transport:
6
+ * 1. host learns capabilities (comms_capabilities) and sees mDM_send = "any"
7
+ * (usable off-grid over radio),
8
+ * 2. host injects a fake RadioProvider,
9
+ * 3. agent calls mDM_send,
10
+ * 4. the opaque payload bytes actually arrive at the injected provider,
11
+ * 5. they round-trip back out via mDM_list.
12
+ *
13
+ * This is the "is it sp, not just written" check the whole 2144 task hinges on.
14
+ */
15
+
16
+ import { describe, expect, it } from "vitest";
17
+ import type {
18
+ DmProvider,
19
+ DmSendArgs,
20
+ DmListArgs,
21
+ DmSendResult,
22
+ DmListResult,
23
+ } from "@mosadd/providers";
24
+ import { mdmTools } from "../tools/mdm.js";
25
+ import { makeCapabilitiesTool } from "../tools/capabilities.js";
26
+ import { allTools } from "../tools/index.js";
27
+ import { createMosaddServer } from "../server.js";
28
+ import { InMemoryMdmKeyStore } from "../crypto/mdm-session.js";
29
+ import { InMemoryVoiceProvider } from "../providers/memory-voice.js";
30
+ import type { MosaddToolContext, ProviderRegistry } from "../types.js";
31
+
32
+ /** Stand-in for a host-supplied radio transport: captures the bytes it's asked
33
+ * to send, and replays them on list — i.e. "the message reached the link". */
34
+ class FakeRadioDmProvider implements DmProvider {
35
+ public readonly sent: DmSendArgs[] = [];
36
+ private bundle: Uint8Array | null = null;
37
+ async selfId(): Promise<string> {
38
+ return "radio:self-callsign";
39
+ }
40
+ async send(args: DmSendArgs): Promise<DmSendResult> {
41
+ this.sent.push(args);
42
+ return { id: `radio-${this.sent.length}`, deliveredAt: new Date(0).toISOString() };
43
+ }
44
+ async list(args: DmListArgs): Promise<DmListResult> {
45
+ return {
46
+ messages: this.sent
47
+ .filter((s) => s.threadId === args.threadId)
48
+ .map((s, i) => ({
49
+ id: `radio-${i + 1}`,
50
+ senderId: "radio:self-callsign",
51
+ payload: s.payload,
52
+ timestamp: new Date(0).toISOString(),
53
+ threadId: s.threadId,
54
+ })),
55
+ nextCursor: null,
56
+ };
57
+ }
58
+ async publishPrekeyBundle(bundle: Uint8Array): Promise<void> {
59
+ this.bundle = bundle;
60
+ }
61
+ async fetchPrekeyBundle(): Promise<Uint8Array | null> {
62
+ return this.bundle;
63
+ }
64
+ }
65
+
66
+ function makeCtx(providers: { dm: DmProvider; keys?: ProviderRegistry["keys"] }): MosaddToolContext {
67
+ return {
68
+ options: { mode: "local", hubUrl: "https://mcp.mosadd.com" },
69
+ providers: {
70
+ dm: providers.dm,
71
+ keys: providers.keys ?? new InMemoryMdmKeyStore(),
72
+ voice: new InMemoryVoiceProvider("radio:self-callsign"),
73
+ },
74
+ log: () => {},
75
+ };
76
+ }
77
+
78
+ const getTool = (name: string) => {
79
+ const t = mdmTools.find((x) => x.name === name);
80
+ if (!t) throw new Error(`tool ${name} not found`);
81
+ return t;
82
+ };
83
+
84
+ describe("golden path — host injects transport under mDM", () => {
85
+ it("step 1: comms_capabilities reports mDM_send usable over any carrier", async () => {
86
+ const capTool = makeCapabilitiesTool(allTools);
87
+ const manifest = (await capTool.handler({}, makeCtx({ dm: new FakeRadioDmProvider() }))) as {
88
+ by_requirement: Record<string, string[]>;
89
+ };
90
+ expect(manifest.by_requirement.any).toContain("mDM_send");
91
+ });
92
+
93
+ it("steps 2-4: the deprecated plaintext path delivers opaque bytes to the injected provider", async () => {
94
+ // This proves the TRANSPORT seam (2144): mDM_send_unencrypted packs a
95
+ // plaintext envelope and the bytes reach the injected provider verbatim.
96
+ // (mDM_send is now E2EE — its own round-trip is covered in mdm-e2ee.test.ts.)
97
+ const radio = new FakeRadioDmProvider();
98
+ const ctx = makeCtx({ dm: radio });
99
+
100
+ const send = getTool("mDM_send_unencrypted");
101
+ const result = (await send.handler(
102
+ { to: "bob-callsign", text: "rendezvous at grid 4471, 0600" },
103
+ ctx,
104
+ )) as { message_id: string; thread_id: string };
105
+
106
+ // The bytes actually reached the transport.
107
+ expect(radio.sent).toHaveLength(1);
108
+ expect(radio.sent[0]!.to).toBe("bob-callsign");
109
+ expect(radio.sent[0]!.payload).toBeInstanceOf(Uint8Array);
110
+ expect(radio.sent[0]!.payload.byteLength).toBeGreaterThan(0);
111
+ expect(result.message_id).toBe("radio-1");
112
+
113
+ // The payload is opaque to the provider but carries our text under the hood.
114
+ const decoded = JSON.parse(Buffer.from(radio.sent[0]!.payload).toString("utf8"));
115
+ expect(decoded.text).toBe("rendezvous at grid 4471, 0600");
116
+ });
117
+
118
+ it("step 5: mDM_list round-trips the message back through the same provider", async () => {
119
+ const radio = new FakeRadioDmProvider();
120
+ const ctx = makeCtx({ dm: radio });
121
+
122
+ await getTool("mDM_send_unencrypted").handler({ to: "bob-callsign", text: "ack" }, ctx);
123
+ const listed = (await getTool("mDM_list").handler({ contact_id: "bob-callsign" }, ctx)) as {
124
+ messages: Array<{ text: string }>;
125
+ };
126
+
127
+ expect(listed.messages).toHaveLength(1);
128
+ expect(listed.messages[0]!.text).toBe("ack");
129
+ });
130
+
131
+ it("default server wires a DmProvider without a host override (no throw)", () => {
132
+ // Network default path: constructing the server must not require a host to
133
+ // inject anything (it falls back to the Supabase adapter).
134
+ expect(() => createMosaddServer()).not.toThrow();
135
+ expect(() => createMosaddServer({ providers: { dm: new FakeRadioDmProvider() } })).not.toThrow();
136
+ });
137
+ });