@mosadd/mcp 3.0.0-alpha.1 → 3.0.0-alpha.11

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 (41) hide show
  1. package/README.md +127 -116
  2. package/dist/bin/login.js +4 -4
  3. package/dist/bin/mcp.js +29 -1
  4. package/dist/chunk-NQ624SIP.js +2121 -0
  5. package/dist/index.d.ts +46 -4
  6. package/dist/index.js +5 -3
  7. package/package.json +8 -5
  8. package/src/__tests__/golden-path.test.ts +137 -132
  9. package/src/__tests__/integration.test.ts +178 -175
  10. package/src/__tests__/mdm-e2ee.test.ts +178 -149
  11. package/src/__tests__/mtalk.test.ts +122 -0
  12. package/src/__tests__/server.test.ts +67 -67
  13. package/src/bin/login.ts +138 -127
  14. package/src/bin/mcp.ts +97 -55
  15. package/src/config.ts +66 -66
  16. package/src/crypto/mdm-session.ts +403 -378
  17. package/src/index.ts +19 -17
  18. package/src/observability/sentry.ts +79 -79
  19. package/src/providers/memory-voice.ts +79 -0
  20. package/src/providers/supabase-dm.ts +117 -117
  21. package/src/providers/supabase-voice.ts +91 -0
  22. package/src/providers/supabase.ts +120 -89
  23. package/src/server.ts +105 -103
  24. package/src/tools/capabilities.ts +68 -68
  25. package/src/tools/index.ts +53 -37
  26. package/src/tools/knowledge.ts +191 -0
  27. package/src/tools/mail.ts +371 -89
  28. package/src/tools/mcall.ts +216 -0
  29. package/src/tools/mdm-voice.ts +206 -0
  30. package/src/tools/mdm.ts +448 -379
  31. package/src/tools/mirc-edge.ts +190 -0
  32. package/src/tools/mirc-members.ts +177 -177
  33. package/src/tools/mirc-messages.ts +156 -0
  34. package/src/tools/mirc.ts +170 -170
  35. package/src/tools/mroom-messages.ts +142 -142
  36. package/src/tools/mroom.ts +221 -189
  37. package/src/tools/mtalk.ts +121 -0
  38. package/src/tools/murl.ts +195 -0
  39. package/src/types.ts +85 -79
  40. package/src/voice/floor.ts +132 -0
  41. package/dist/chunk-6IA4QVAJ.js +0 -1191
@@ -1,149 +1,178 @@
1
- /**
2
- * mDM E2EE golden path (LINEAR-2357) — the "done" bar.
3
- *
4
- * Two parties (alice, bob) sharing ONE backend that acts as both the message
5
- * store AND the key directory (decision "1a": prekey bundles ride the same
6
- * DmProvider as messages). Proves:
7
- * 1. both publish prekey bundles via the provider,
8
- * 2. alice mDM_send → X3DH handshake + ratchet → bob mDM_list decrypts it,
9
- * 3. the bytes on the wire are CIPHERTEXT, not plaintext (no test-theater),
10
- * 4. bob replies on the established session → alice mDM_list decrypts it.
11
- */
12
-
13
- import { describe, expect, it } from "vitest";
14
- import type {
15
- DmProvider,
16
- DmSendArgs,
17
- DmListArgs,
18
- DmSendResult,
19
- DmListResult,
20
- } from "@mosadd/providers";
21
- import { mdmTools } from "../tools/mdm.js";
22
- import { InMemoryMdmKeyStore } from "../crypto/mdm-session.js";
23
- import type { MosaddToolContext } from "../types.js";
24
-
25
- /** Shared store: message log + key directory, both keyed in one place. */
26
- class SharedBackend {
27
- readonly messages: Array<{ id: string; senderId: string; payload: Uint8Array; threadId: string }> = [];
28
- readonly bundles = new Map<string, Uint8Array>();
29
- }
30
-
31
- /** One participant's view onto the shared backend. */
32
- class ClientProvider implements DmProvider {
33
- constructor(
34
- private readonly backend: SharedBackend,
35
- private readonly myId: string,
36
- ) {}
37
- async selfId(): Promise<string> {
38
- return this.myId;
39
- }
40
- async send(args: DmSendArgs): Promise<DmSendResult> {
41
- const id = `m${this.backend.messages.length + 1}`;
42
- this.backend.messages.push({ id, senderId: this.myId, payload: args.payload, threadId: args.threadId });
43
- return { id, deliveredAt: new Date(0).toISOString() };
44
- }
45
- async list(args: DmListArgs): Promise<DmListResult> {
46
- return {
47
- messages: this.backend.messages
48
- .filter((m) => m.threadId === args.threadId)
49
- .map((m) => ({
50
- id: m.id,
51
- senderId: m.senderId,
52
- payload: m.payload,
53
- timestamp: new Date(0).toISOString(),
54
- threadId: m.threadId,
55
- })),
56
- nextCursor: null,
57
- };
58
- }
59
- async publishPrekeyBundle(bundle: Uint8Array): Promise<void> {
60
- this.backend.bundles.set(this.myId, bundle);
61
- }
62
- async fetchPrekeyBundle(peerId: string): Promise<Uint8Array | null> {
63
- return this.backend.bundles.get(peerId) ?? null;
64
- }
65
- }
66
-
67
- const tool = (name: string) => {
68
- const t = mdmTools.find((x) => x.name === name);
69
- if (!t) throw new Error(`tool ${name} not found`);
70
- return t.handler;
71
- };
72
-
73
- function ctxFor(backend: SharedBackend, id: string): MosaddToolContext {
74
- return {
75
- options: { mode: "local", hubUrl: "https://mcp.mosadd.com" },
76
- providers: { dm: new ClientProvider(backend, id), keys: new InMemoryMdmKeyStore() },
77
- log: () => {},
78
- };
79
- }
80
-
81
- describe("mDM E2EE golden path — X3DH handshake + ratchet, both directions", () => {
82
- it("delivers an encrypted message alice→bob and a reply bob→alice", async () => {
83
- const backend = new SharedBackend();
84
- const alice = ctxFor(backend, "alice");
85
- const bob = ctxFor(backend, "bob");
86
-
87
- // 1. Both publish their prekey bundles (so first contact is possible).
88
- await tool("mDM_publish_keys")({}, alice);
89
- const bobPub = (await tool("mDM_publish_keys")({}, bob)) as { one_time_prekeys: number };
90
- expect(bobPub.one_time_prekeys).toBeGreaterThan(0);
91
-
92
- // 2. Alice sends an encrypted DM to Bob (first contact → X3DH handshake).
93
- const sent = (await tool("mDM_send")({ to: "bob", text: "first contact" }, alice)) as {
94
- encrypted: boolean;
95
- };
96
- expect(sent.encrypted).toBe(true);
97
-
98
- // 3. The wire bytes must be CIPHERTEXT — the plaintext must NOT appear.
99
- const wire = backend.messages[0]!.payload;
100
- const wireStr = Buffer.from(wire).toString("utf8");
101
- expect(wireStr).not.toContain("first contact");
102
- expect(wireStr).toContain("mosadd.e2ee.v1"); // it IS our sealed envelope
103
-
104
- // 4. Bob lists the thread and decrypts Alice's message.
105
- const bobView = (await tool("mDM_list")({ contact_id: "alice" }, bob)) as {
106
- messages: Array<{ text: string; sender_identity_id: string; encrypted: boolean }>;
107
- };
108
- const fromAlice = bobView.messages.find((m) => m.sender_identity_id === "alice");
109
- expect(fromAlice?.text).toBe("first contact");
110
- expect(fromAlice?.encrypted).toBe(true);
111
-
112
- // 5. Bob replies on the now-established session (no new handshake).
113
- await tool("mDM_send")({ to: "alice", text: "copy that" }, bob);
114
-
115
- // 6. Alice decrypts Bob's reply.
116
- const aliceView = (await tool("mDM_list")({ contact_id: "bob" }, alice)) as {
117
- messages: Array<{ text: string; sender_identity_id: string }>;
118
- };
119
- const fromBob = aliceView.messages.find((m) => m.sender_identity_id === "bob");
120
- expect(fromBob?.text).toBe("copy that");
121
- });
122
-
123
- it("mDM_send fails with an actionable error when the peer has no published keys", async () => {
124
- const backend = new SharedBackend();
125
- const alice = ctxFor(backend, "alice");
126
- // Bob never published — no bundle to fetch.
127
- await expect(tool("mDM_send")({ to: "bob", text: "hi" }, alice)).rejects.toThrow(
128
- /has not published a prekey bundle/i,
129
- );
130
- });
131
-
132
- it("rejects a tampered (MITM) prekey bundle instead of starting a session", async () => {
133
- const backend = new SharedBackend();
134
- const alice = ctxFor(backend, "alice");
135
- const bob = ctxFor(backend, "bob");
136
-
137
- await tool("mDM_publish_keys")({}, bob);
138
-
139
- // MITM swaps Bob's DH identity key (a SIGNED field) in the directory entry,
140
- // keeping it valid base64 so it parses — only the signature should catch it.
141
- const obj = JSON.parse(Buffer.from(backend.bundles.get("bob")!).toString("utf8"));
142
- obj.ik = (obj.ik[0] === "A" ? "B" : "A") + obj.ik.slice(1);
143
- backend.bundles.set("bob", new Uint8Array(Buffer.from(JSON.stringify(obj), "utf8")));
144
-
145
- await expect(tool("mDM_send")({ to: "bob", text: "intercept me" }, alice)).rejects.toThrow(
146
- /signature verification|man-in-the-middle/i,
147
- );
148
- });
149
- });
1
+ /**
2
+ * mDM E2EE golden path (LINEAR-2357) — the "done" bar.
3
+ *
4
+ * Two parties (alice, bob) sharing ONE backend that acts as both the message
5
+ * store AND the key directory (decision "1a": prekey bundles ride the same
6
+ * DmProvider as messages). Proves:
7
+ * 1. both publish prekey bundles via the provider,
8
+ * 2. alice mDM_send → X3DH handshake + ratchet → bob mDM_list decrypts it,
9
+ * 3. the bytes on the wire are CIPHERTEXT, not plaintext (no test-theater),
10
+ * 4. bob replies on the established session → alice mDM_list decrypts it.
11
+ */
12
+
13
+ import { describe, expect, it } from "vitest";
14
+ import type {
15
+ DmProvider,
16
+ DmSendArgs,
17
+ DmListArgs,
18
+ DmSendResult,
19
+ DmListResult,
20
+ } from "@mosadd/providers";
21
+ import { mdmTools } from "../tools/mdm.js";
22
+ import { InMemoryMdmKeyStore } from "../crypto/mdm-session.js";
23
+ import { InMemoryVoiceProvider } from "../providers/memory-voice.js";
24
+ import type { MosaddToolContext } from "../types.js";
25
+
26
+ /** Shared store: message log + key directory, both keyed in one place. */
27
+ class SharedBackend {
28
+ readonly messages: Array<{ id: string; senderId: string; payload: Uint8Array; threadId: string }> = [];
29
+ readonly bundles = new Map<string, Uint8Array>();
30
+ }
31
+
32
+ /** One participant's view onto the shared backend. */
33
+ class ClientProvider implements DmProvider {
34
+ constructor(
35
+ private readonly backend: SharedBackend,
36
+ private readonly myId: string,
37
+ ) {}
38
+ async selfId(): Promise<string> {
39
+ return this.myId;
40
+ }
41
+ async send(args: DmSendArgs): Promise<DmSendResult> {
42
+ const id = `m${this.backend.messages.length + 1}`;
43
+ this.backend.messages.push({ id, senderId: this.myId, payload: args.payload, threadId: args.threadId });
44
+ return { id, deliveredAt: new Date(0).toISOString() };
45
+ }
46
+ async list(args: DmListArgs): Promise<DmListResult> {
47
+ return {
48
+ messages: this.backend.messages
49
+ .filter((m) => m.threadId === args.threadId)
50
+ .map((m) => ({
51
+ id: m.id,
52
+ senderId: m.senderId,
53
+ payload: m.payload,
54
+ timestamp: new Date(0).toISOString(),
55
+ threadId: m.threadId,
56
+ })),
57
+ nextCursor: null,
58
+ };
59
+ }
60
+ async publishPrekeyBundle(bundle: Uint8Array): Promise<void> {
61
+ this.backend.bundles.set(this.myId, bundle);
62
+ }
63
+ async fetchPrekeyBundle(peerId: string): Promise<Uint8Array | null> {
64
+ return this.backend.bundles.get(peerId) ?? null;
65
+ }
66
+ }
67
+
68
+ const tool = (name: string) => {
69
+ const t = mdmTools.find((x) => x.name === name);
70
+ if (!t) throw new Error(`tool ${name} not found`);
71
+ return t.handler;
72
+ };
73
+
74
+ function ctxFor(backend: SharedBackend, id: string): MosaddToolContext {
75
+ return {
76
+ options: { mode: "local", hubUrl: "https://mcp.mosadd.com" },
77
+ providers: {
78
+ dm: new ClientProvider(backend, id),
79
+ keys: new InMemoryMdmKeyStore(),
80
+ voice: new InMemoryVoiceProvider(id),
81
+ },
82
+ log: () => {},
83
+ };
84
+ }
85
+
86
+ describe("mDM E2EE golden path — X3DH handshake + ratchet, both directions", () => {
87
+ it("delivers an encrypted message alice→bob and a reply bob→alice", async () => {
88
+ const backend = new SharedBackend();
89
+ const alice = ctxFor(backend, "alice");
90
+ const bob = ctxFor(backend, "bob");
91
+
92
+ // 1. Both publish their prekey bundles (so first contact is possible).
93
+ await tool("mDM_publish_keys")({}, alice);
94
+ const bobPub = (await tool("mDM_publish_keys")({}, bob)) as { one_time_prekeys: number };
95
+ expect(bobPub.one_time_prekeys).toBeGreaterThan(0);
96
+
97
+ // 2. Alice sends an encrypted DM to Bob (first contact → X3DH handshake).
98
+ const sent = (await tool("mDM_send")({ to: "bob", text: "first contact" }, alice)) as {
99
+ encrypted: boolean;
100
+ };
101
+ expect(sent.encrypted).toBe(true);
102
+
103
+ // 3. The wire bytes must be CIPHERTEXT — the plaintext must NOT appear.
104
+ const wire = backend.messages[0]!.payload;
105
+ const wireStr = Buffer.from(wire).toString("utf8");
106
+ expect(wireStr).not.toContain("first contact");
107
+ expect(wireStr).toContain("mosadd.e2ee.v1"); // it IS our sealed envelope
108
+
109
+ // 4. Bob lists the thread and decrypts Alice's message.
110
+ const bobView = (await tool("mDM_list")({ contact_id: "alice" }, bob)) as {
111
+ messages: Array<{ text: string; sender_identity_id: string; encrypted: boolean }>;
112
+ };
113
+ const fromAlice = bobView.messages.find((m) => m.sender_identity_id === "alice");
114
+ expect(fromAlice?.text).toBe("first contact");
115
+ expect(fromAlice?.encrypted).toBe(true);
116
+
117
+ // 5. Bob replies on the now-established session (no new handshake).
118
+ await tool("mDM_send")({ to: "alice", text: "copy that" }, bob);
119
+
120
+ // 6. Alice decrypts Bob's reply AND reads back her OWN sent message
121
+ // (sent-items cache — the ratchet can't re-derive own plaintext on read).
122
+ const aliceView = (await tool("mDM_list")({ contact_id: "bob" }, alice)) as {
123
+ messages: Array<{ text: string; sender_identity_id: string; encrypted: boolean }>;
124
+ };
125
+ const fromBob = aliceView.messages.find((m) => m.sender_identity_id === "bob");
126
+ expect(fromBob?.text).toBe("copy that");
127
+ const ownByAlice = aliceView.messages.find((m) => m.sender_identity_id === "alice");
128
+ expect(ownByAlice?.text).toBe("first contact"); // not "<encrypted · sent by you>"
129
+ expect(ownByAlice?.encrypted).toBe(true);
130
+ });
131
+
132
+ it("falls back to a marker for own messages when no sent-items cache exists", async () => {
133
+ // A keystore WITHOUT the optional sent-items cache must not crash; the
134
+ // sender simply sees the marker for their own outgoing messages.
135
+ const backend = new SharedBackend();
136
+ const alice = ctxFor(backend, "alice");
137
+ const bob = ctxFor(backend, "bob");
138
+ // Strip the optional cache methods from alice's keystore.
139
+ (alice.providers.keys as { putSentMessage?: unknown }).putSentMessage = undefined;
140
+ (alice.providers.keys as { getSentMessage?: unknown }).getSentMessage = undefined;
141
+
142
+ await tool("mDM_publish_keys")({}, bob);
143
+ await tool("mDM_send")({ to: "bob", text: "no cache here" }, alice);
144
+
145
+ const aliceView = (await tool("mDM_list")({ contact_id: "bob" }, alice)) as {
146
+ messages: Array<{ text: string; sender_identity_id: string }>;
147
+ };
148
+ const own = aliceView.messages.find((m) => m.sender_identity_id === "alice");
149
+ expect(own?.text).toBe("<encrypted · sent by you>");
150
+ });
151
+
152
+ it("mDM_send fails with an actionable error when the peer has no published keys", async () => {
153
+ const backend = new SharedBackend();
154
+ const alice = ctxFor(backend, "alice");
155
+ // Bob never published — no bundle to fetch.
156
+ await expect(tool("mDM_send")({ to: "bob", text: "hi" }, alice)).rejects.toThrow(
157
+ /has not published a prekey bundle/i,
158
+ );
159
+ });
160
+
161
+ it("rejects a tampered (MITM) prekey bundle instead of starting a session", async () => {
162
+ const backend = new SharedBackend();
163
+ const alice = ctxFor(backend, "alice");
164
+ const bob = ctxFor(backend, "bob");
165
+
166
+ await tool("mDM_publish_keys")({}, bob);
167
+
168
+ // MITM swaps Bob's DH identity key (a SIGNED field) in the directory entry,
169
+ // keeping it valid base64 so it parses — only the signature should catch it.
170
+ const obj = JSON.parse(Buffer.from(backend.bundles.get("bob")!).toString("utf8"));
171
+ obj.ik = (obj.ik[0] === "A" ? "B" : "A") + obj.ik.slice(1);
172
+ backend.bundles.set("bob", new Uint8Array(Buffer.from(JSON.stringify(obj), "utf8")));
173
+
174
+ await expect(tool("mDM_send")({ to: "bob", text: "intercept me" }, alice)).rejects.toThrow(
175
+ /signature verification|man-in-the-middle/i,
176
+ );
177
+ });
178
+ });
@@ -0,0 +1,122 @@
1
+ /**
2
+ * mTALK PTT golden path — the half-duplex floor discipline (the kill feature).
3
+ *
4
+ * Two participants (alice, bob) share ONE room (one floor). Proves through the
5
+ * actual mTALK tools:
6
+ * 1. first to press PTT is GRANTED the floor,
7
+ * 2. a second presser is DENIED and QUEUED (half-duplex — one talker),
8
+ * 3. releasing the floor PROMOTES the next in the queue automatically,
9
+ * 4. the anti-hog timeout auto-bumps a holder who never releases,
10
+ * 5. join credentials are issued for the media transport.
11
+ *
12
+ * Deterministic: the in-memory voice provider takes an injected clock, so the
13
+ * anti-hog timeout is tested without real time passing.
14
+ */
15
+
16
+ import { describe, expect, it } from "vitest";
17
+ import { mtalkTools } from "../tools/mtalk.js";
18
+ import { InMemoryVoiceProvider } from "../providers/memory-voice.js";
19
+ import { InMemoryMdmKeyStore } from "../crypto/mdm-session.js";
20
+ import type { DmProvider } from "@mosadd/providers";
21
+ import type { MosaddToolContext } from "../types.js";
22
+
23
+ const tool = (name: string) => {
24
+ const t = mtalkTools.find((x) => x.name === name);
25
+ if (!t) throw new Error(`tool ${name} not found`);
26
+ return t.handler;
27
+ };
28
+
29
+ // mTALK tools never touch dm/keys; a minimal stub satisfies the type.
30
+ const dmStub = {} as unknown as DmProvider;
31
+
32
+ function ctxFor(voice: InMemoryVoiceProvider): MosaddToolContext {
33
+ return {
34
+ options: { mode: "local", hubUrl: "https://mcp.mosadd.com" },
35
+ providers: { dm: dmStub, keys: new InMemoryMdmKeyStore(), voice },
36
+ log: () => {},
37
+ };
38
+ }
39
+
40
+ describe("mTALK PTT floor discipline — half-duplex, queue, promotion, anti-hog", () => {
41
+ it("grants one speaker, queues the next, promotes on release", async () => {
42
+ let now = 1_000;
43
+ const clock = () => now;
44
+ const aliceVoice = new InMemoryVoiceProvider("alice", clock);
45
+ const bobVoice = new InMemoryVoiceProvider("bob", clock);
46
+ aliceVoice.shareRoomsWith(bobVoice); // one shared room/floor
47
+ const alice = ctxFor(aliceVoice);
48
+ const bob = ctxFor(bobVoice);
49
+
50
+ // Open a shared room.
51
+ const { room_id } = (await tool("mTALK_open")({ label: "ops" }, alice)) as { room_id: string };
52
+ expect(room_id).toContain("ops");
53
+
54
+ // 1. Alice presses PTT first → granted.
55
+ const aPress = (await tool("mTALK_press")({ room_id }, alice)) as {
56
+ granted: boolean;
57
+ position: number;
58
+ holder: string | null;
59
+ };
60
+ expect(aPress.granted).toBe(true);
61
+ expect(aPress.holder).toBe("alice");
62
+
63
+ // 2. Bob presses while Alice holds → denied + queued at position 1.
64
+ const bPress = (await tool("mTALK_press")({ room_id }, bob)) as {
65
+ granted: boolean;
66
+ position: number;
67
+ holder: string | null;
68
+ queue: string[];
69
+ };
70
+ expect(bPress.granted).toBe(false);
71
+ expect(bPress.position).toBe(1);
72
+ expect(bPress.holder).toBe("alice");
73
+ expect(bPress.queue).toEqual(["bob"]);
74
+
75
+ // 3. Alice releases → Bob is promoted to holder automatically.
76
+ const released = (await tool("mTALK_release")({ room_id }, alice)) as {
77
+ holder: string | null;
78
+ queue: string[];
79
+ };
80
+ expect(released.holder).toBe("bob");
81
+ expect(released.queue).toEqual([]);
82
+
83
+ // State reads consistently from Bob's side too.
84
+ const state = (await tool("mTALK_state")({ room_id }, bob)) as { holder: string | null };
85
+ expect(state.holder).toBe("bob");
86
+ });
87
+
88
+ it("auto-bumps a holder who exceeds the anti-hog timeout", async () => {
89
+ let now = 0;
90
+ const clock = () => now;
91
+ const aliceVoice = new InMemoryVoiceProvider("alice", clock);
92
+ const bobVoice = new InMemoryVoiceProvider("bob", clock);
93
+ aliceVoice.shareRoomsWith(bobVoice);
94
+ const alice = ctxFor(aliceVoice);
95
+ const bob = ctxFor(bobVoice);
96
+
97
+ const { room_id } = (await tool("mTALK_open")({ label: "ops" }, alice)) as { room_id: string };
98
+
99
+ await tool("mTALK_press")({ room_id }, alice); // alice holds at t=0
100
+ const bPress = (await tool("mTALK_press")({ room_id }, bob)) as { granted: boolean };
101
+ expect(bPress.granted).toBe(false); // queued behind alice
102
+
103
+ // Advance past the 30s anti-hog ceiling; next floor read auto-promotes bob.
104
+ now = 31_000;
105
+ const state = (await tool("mTALK_state")({ room_id }, bob)) as { holder: string | null };
106
+ expect(state.holder).toBe("bob"); // alice was bumped, bob promoted
107
+ });
108
+
109
+ it("issues join credentials for the media transport", async () => {
110
+ const voice = new InMemoryVoiceProvider("alice");
111
+ const alice = ctxFor(voice);
112
+ const { room_id } = (await tool("mTALK_open")({}, alice)) as { room_id: string };
113
+ const join = (await tool("mTALK_join")({ room_id }, alice)) as {
114
+ token: string;
115
+ url: string;
116
+ identity: string;
117
+ };
118
+ expect(join.identity).toBe("alice");
119
+ expect(join.token).toBeTruthy();
120
+ expect(join.url).toBeTruthy();
121
+ });
122
+ });
@@ -1,67 +1,67 @@
1
- import { describe, expect, it } from "vitest";
2
- import { allTools, createMosaddServer } from "../index.js";
3
-
4
- describe("@mosadd/mcp", () => {
5
- describe("allTools registry", () => {
6
- it("exposes at least the 4 alpha channels", () => {
7
- const names = allTools.map((t) => t.name);
8
- // mDM (6 tools)
9
- expect(names).toContain("mDM_list_contacts");
10
- expect(names).toContain("mDM_publish_keys");
11
- expect(names).toContain("mDM_send");
12
- expect(names).toContain("mDM_send_unencrypted");
13
- expect(names).toContain("mDM_list");
14
- expect(names).toContain("mDM_respond_request");
15
- // mIRC (5 tools)
16
- expect(names).toContain("mIRC_create");
17
- expect(names).toContain("mIRC_delete");
18
- // mROOM (6 tools, including the USP guest-link)
19
- expect(names).toContain("mROOM_create");
20
- expect(names).toContain("mROOM_create_guest_link");
21
- // mAIL (2 tools)
22
- expect(names).toContain("mAIL_send");
23
- expect(names).toContain("mAIL_view");
24
- });
25
-
26
- it("follows RFC 0001 naming — channel tools m<MODULE>_<operation>, meta tools comms_<op>", () => {
27
- const channelName = /^m[A-Z][A-Z0-9_]*_[a-z][a-z0-9_]*$/;
28
- const metaName = /^comms_[a-z][a-z0-9_]*$/; // discovery/meta namespace
29
- for (const tool of allTools) {
30
- expect(tool.name).toMatch(new RegExp(`${channelName.source}|${metaName.source}`));
31
- }
32
- });
33
-
34
- it("every tool declares a transport requirement (any | radio | network)", () => {
35
- for (const tool of allTools) {
36
- expect(["any", "radio", "network"]).toContain(tool.requires);
37
- }
38
- });
39
-
40
- it("every tool ships a description and a Zod schema", () => {
41
- for (const tool of allTools) {
42
- expect(typeof tool.description).toBe("string");
43
- expect(tool.description.length).toBeGreaterThan(20);
44
- expect(tool.inputSchema).toBeDefined();
45
- // Zod schemas have _def
46
- expect((tool.inputSchema as { _def?: unknown })._def).toBeDefined();
47
- }
48
- });
49
- });
50
-
51
- describe("createMosaddServer", () => {
52
- it("constructs without throwing in local mode", () => {
53
- const server = createMosaddServer({ mode: "local", logLevel: "error" });
54
- expect(server).toBeDefined();
55
- });
56
-
57
- it("defaults to local mode when no apiKey", () => {
58
- const server = createMosaddServer({ logLevel: "error" });
59
- expect(server).toBeDefined();
60
- });
61
-
62
- it("accepts cloud mode with apiKey", () => {
63
- const server = createMosaddServer({ apiKey: "test", logLevel: "error" });
64
- expect(server).toBeDefined();
65
- });
66
- });
67
- });
1
+ import { describe, expect, it } from "vitest";
2
+ import { allTools, createMosaddServer } from "../index.js";
3
+
4
+ describe("@mosadd/mcp", () => {
5
+ describe("allTools registry", () => {
6
+ it("exposes at least the 4 alpha channels", () => {
7
+ const names = allTools.map((t) => t.name);
8
+ // mDM (6 tools)
9
+ expect(names).toContain("mDM_list_contacts");
10
+ expect(names).toContain("mDM_publish_keys");
11
+ expect(names).toContain("mDM_send");
12
+ expect(names).toContain("mDM_send_unencrypted");
13
+ expect(names).toContain("mDM_list");
14
+ expect(names).toContain("mDM_respond_request");
15
+ // mIRC (5 tools)
16
+ expect(names).toContain("mIRC_create");
17
+ expect(names).toContain("mIRC_delete");
18
+ // mROOM (6 tools, including the USP guest-link)
19
+ expect(names).toContain("mROOM_create");
20
+ expect(names).toContain("mROOM_create_guest_link");
21
+ // mAIL (2 tools)
22
+ expect(names).toContain("mAIL_send");
23
+ expect(names).toContain("mAIL_view");
24
+ });
25
+
26
+ it("follows RFC 0001 naming — channel tools m<MODULE>_<operation>, meta tools comms_<op>", () => {
27
+ const channelName = /^m[A-Z][A-Z0-9_]*_[a-z][a-z0-9_]*$/;
28
+ const metaName = /^comms_[a-z][a-z0-9_]*$/; // discovery/meta namespace
29
+ for (const tool of allTools) {
30
+ expect(tool.name).toMatch(new RegExp(`${channelName.source}|${metaName.source}`));
31
+ }
32
+ });
33
+
34
+ it("every tool declares a transport requirement (any | radio | network)", () => {
35
+ for (const tool of allTools) {
36
+ expect(["any", "radio", "network"]).toContain(tool.requires);
37
+ }
38
+ });
39
+
40
+ it("every tool ships a description and a Zod schema", () => {
41
+ for (const tool of allTools) {
42
+ expect(typeof tool.description).toBe("string");
43
+ expect(tool.description.length).toBeGreaterThan(20);
44
+ expect(tool.inputSchema).toBeDefined();
45
+ // Zod schemas have _def
46
+ expect((tool.inputSchema as { _def?: unknown })._def).toBeDefined();
47
+ }
48
+ });
49
+ });
50
+
51
+ describe("createMosaddServer", () => {
52
+ it("constructs without throwing in local mode", () => {
53
+ const server = createMosaddServer({ mode: "local", logLevel: "error" });
54
+ expect(server).toBeDefined();
55
+ });
56
+
57
+ it("defaults to local mode when no apiKey", () => {
58
+ const server = createMosaddServer({ logLevel: "error" });
59
+ expect(server).toBeDefined();
60
+ });
61
+
62
+ it("accepts cloud mode with apiKey", () => {
63
+ const server = createMosaddServer({ apiKey: "test", logLevel: "error" });
64
+ expect(server).toBeDefined();
65
+ });
66
+ });
67
+ });