@mosadd/mcp 3.0.0-alpha.3 → 3.0.0-alpha.30
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 +212 -0
- package/README.md +150 -116
- package/dist/bin/mcp.js +42 -3
- package/dist/chunk-6PGDNIKR.js +2556 -0
- package/dist/index.d.ts +99 -7
- package/dist/index.js +7 -3
- package/package.json +10 -7
- package/src/__tests__/golden-path.test.ts +137 -132
- package/src/__tests__/integration.test.ts +179 -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 -97
- 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 +148 -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 +104 -37
- package/src/tools/knowledge.ts +191 -0
- package/src/tools/mail-aliases.ts +25 -0
- package/src/tools/mail-provenance.ts +135 -0
- package/src/tools/mail.ts +381 -89
- package/src/tools/mcall.ts +216 -0
- package/src/tools/mdm-voice.ts +212 -0
- package/src/tools/mdm.ts +479 -379
- package/src/tools/mirc-edge.ts +190 -0
- package/src/tools/mirc-members.ts +198 -177
- package/src/tools/mirc-messages.ts +155 -0
- package/src/tools/mirc.ts +190 -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 +298 -0
- package/src/tools/ptt-ingest.ts +97 -0
- package/src/tools/threat.ts +119 -0
- package/src/types.ts +94 -79
- package/src/voice/floor.ts +132 -0
- package/dist/chunk-HD5RLE5K.js +0 -1193
|
@@ -1,149 +1,212 @@
|
|
|
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
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
};
|
|
96
|
-
expect(
|
|
97
|
-
|
|
98
|
-
//
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
expect(
|
|
103
|
-
|
|
104
|
-
//
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
//
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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 { createMosaddServer } from "../server.js";
|
|
25
|
+
import type { MosaddToolContext } from "../types.js";
|
|
26
|
+
|
|
27
|
+
/** Shared store: message log + key directory, both keyed in one place. */
|
|
28
|
+
class SharedBackend {
|
|
29
|
+
readonly messages: Array<{ id: string; senderId: string; payload: Uint8Array; threadId: string }> = [];
|
|
30
|
+
readonly bundles = new Map<string, Uint8Array>();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** One participant's view onto the shared backend. */
|
|
34
|
+
class ClientProvider implements DmProvider {
|
|
35
|
+
constructor(
|
|
36
|
+
private readonly backend: SharedBackend,
|
|
37
|
+
private readonly myId: string,
|
|
38
|
+
) {}
|
|
39
|
+
async selfId(): Promise<string> {
|
|
40
|
+
return this.myId;
|
|
41
|
+
}
|
|
42
|
+
async send(args: DmSendArgs): Promise<DmSendResult> {
|
|
43
|
+
const id = `m${this.backend.messages.length + 1}`;
|
|
44
|
+
this.backend.messages.push({ id, senderId: this.myId, payload: args.payload, threadId: args.threadId });
|
|
45
|
+
return { id, deliveredAt: new Date(0).toISOString() };
|
|
46
|
+
}
|
|
47
|
+
async list(args: DmListArgs): Promise<DmListResult> {
|
|
48
|
+
return {
|
|
49
|
+
messages: this.backend.messages
|
|
50
|
+
.filter((m) => m.threadId === args.threadId)
|
|
51
|
+
.map((m) => ({
|
|
52
|
+
id: m.id,
|
|
53
|
+
senderId: m.senderId,
|
|
54
|
+
payload: m.payload,
|
|
55
|
+
timestamp: new Date(0).toISOString(),
|
|
56
|
+
threadId: m.threadId,
|
|
57
|
+
})),
|
|
58
|
+
nextCursor: null,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
async publishPrekeyBundle(bundle: Uint8Array): Promise<void> {
|
|
62
|
+
this.backend.bundles.set(this.myId, bundle);
|
|
63
|
+
}
|
|
64
|
+
async fetchPrekeyBundle(peerId: string): Promise<Uint8Array | null> {
|
|
65
|
+
return this.backend.bundles.get(peerId) ?? null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const tool = (name: string) => {
|
|
70
|
+
const t = mdmTools.find((x) => x.name === name);
|
|
71
|
+
if (!t) throw new Error(`tool ${name} not found`);
|
|
72
|
+
return t.handler;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
function ctxFor(backend: SharedBackend, id: string): MosaddToolContext {
|
|
76
|
+
return {
|
|
77
|
+
options: { mode: "local", hubUrl: "https://mcp.mosadd.com" },
|
|
78
|
+
providers: {
|
|
79
|
+
dm: new ClientProvider(backend, id),
|
|
80
|
+
keys: new InMemoryMdmKeyStore(),
|
|
81
|
+
voice: new InMemoryVoiceProvider(id),
|
|
82
|
+
},
|
|
83
|
+
log: () => {},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
describe("mDM E2EE golden path — X3DH handshake + ratchet, both directions", () => {
|
|
88
|
+
it("delivers an encrypted message alice→bob and a reply bob→alice", async () => {
|
|
89
|
+
const backend = new SharedBackend();
|
|
90
|
+
const alice = ctxFor(backend, "alice");
|
|
91
|
+
const bob = ctxFor(backend, "bob");
|
|
92
|
+
|
|
93
|
+
// 1. Both publish their prekey bundles (so first contact is possible).
|
|
94
|
+
await tool("mDM_publish_keys")({}, alice);
|
|
95
|
+
const bobPub = (await tool("mDM_publish_keys")({}, bob)) as { one_time_prekeys: number };
|
|
96
|
+
expect(bobPub.one_time_prekeys).toBeGreaterThan(0);
|
|
97
|
+
|
|
98
|
+
// 2. Alice sends an encrypted DM to Bob (first contact → X3DH handshake).
|
|
99
|
+
const sent = (await tool("mDM_send")({ to: "bob", text: "first contact" }, alice)) as {
|
|
100
|
+
encrypted: boolean;
|
|
101
|
+
};
|
|
102
|
+
expect(sent.encrypted).toBe(true);
|
|
103
|
+
|
|
104
|
+
// 3. The wire bytes must be CIPHERTEXT — the plaintext must NOT appear.
|
|
105
|
+
const wire = backend.messages[0]!.payload;
|
|
106
|
+
const wireStr = Buffer.from(wire).toString("utf8");
|
|
107
|
+
expect(wireStr).not.toContain("first contact");
|
|
108
|
+
expect(wireStr).toContain("mosadd.e2ee.v2"); // DH-ratchet sealed envelope (PCS — LINEAR-3409)
|
|
109
|
+
|
|
110
|
+
// 4. Bob lists the thread and decrypts Alice's message.
|
|
111
|
+
const bobView = (await tool("mDM_list")({ contact_id: "alice" }, bob)) as {
|
|
112
|
+
messages: Array<{ text: string; sender_identity_id: string; encrypted: boolean }>;
|
|
113
|
+
};
|
|
114
|
+
const fromAlice = bobView.messages.find((m) => m.sender_identity_id === "alice");
|
|
115
|
+
expect(fromAlice?.text).toBe("first contact");
|
|
116
|
+
expect(fromAlice?.encrypted).toBe(true);
|
|
117
|
+
|
|
118
|
+
// 5. Bob replies on the now-established session (no new handshake).
|
|
119
|
+
await tool("mDM_send")({ to: "alice", text: "copy that" }, bob);
|
|
120
|
+
|
|
121
|
+
// 6. Alice decrypts Bob's reply AND reads back her OWN sent message
|
|
122
|
+
// (sent-items cache — the ratchet can't re-derive own plaintext on read).
|
|
123
|
+
const aliceView = (await tool("mDM_list")({ contact_id: "bob" }, alice)) as {
|
|
124
|
+
messages: Array<{ text: string; sender_identity_id: string; encrypted: boolean }>;
|
|
125
|
+
};
|
|
126
|
+
const fromBob = aliceView.messages.find((m) => m.sender_identity_id === "bob");
|
|
127
|
+
expect(fromBob?.text).toBe("copy that");
|
|
128
|
+
const ownByAlice = aliceView.messages.find((m) => m.sender_identity_id === "alice");
|
|
129
|
+
expect(ownByAlice?.text).toBe("first contact"); // not "<encrypted · sent by you>"
|
|
130
|
+
expect(ownByAlice?.encrypted).toBe(true);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("falls back to a marker for own messages when no sent-items cache exists", async () => {
|
|
134
|
+
// A keystore WITHOUT the optional sent-items cache must not crash; the
|
|
135
|
+
// sender simply sees the marker for their own outgoing messages.
|
|
136
|
+
const backend = new SharedBackend();
|
|
137
|
+
const alice = ctxFor(backend, "alice");
|
|
138
|
+
const bob = ctxFor(backend, "bob");
|
|
139
|
+
// Strip the optional cache methods from alice's keystore.
|
|
140
|
+
(alice.providers.keys as { putSentMessage?: unknown }).putSentMessage = undefined;
|
|
141
|
+
(alice.providers.keys as { getSentMessage?: unknown }).getSentMessage = undefined;
|
|
142
|
+
|
|
143
|
+
await tool("mDM_publish_keys")({}, bob);
|
|
144
|
+
await tool("mDM_send")({ to: "bob", text: "no cache here" }, alice);
|
|
145
|
+
|
|
146
|
+
const aliceView = (await tool("mDM_list")({ contact_id: "bob" }, alice)) as {
|
|
147
|
+
messages: Array<{ text: string; sender_identity_id: string }>;
|
|
148
|
+
};
|
|
149
|
+
const own = aliceView.messages.find((m) => m.sender_identity_id === "alice");
|
|
150
|
+
expect(own?.text).toBe("<encrypted · sent by you>");
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("mDM_send fails with an actionable error when the peer has no published keys", async () => {
|
|
154
|
+
const backend = new SharedBackend();
|
|
155
|
+
const alice = ctxFor(backend, "alice");
|
|
156
|
+
// Bob never published — no bundle to fetch.
|
|
157
|
+
await expect(tool("mDM_send")({ to: "bob", text: "hi" }, alice)).rejects.toThrow(
|
|
158
|
+
/has not published a prekey bundle/i,
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("rejects a tampered (MITM) prekey bundle instead of starting a session", async () => {
|
|
163
|
+
const backend = new SharedBackend();
|
|
164
|
+
const alice = ctxFor(backend, "alice");
|
|
165
|
+
const bob = ctxFor(backend, "bob");
|
|
166
|
+
|
|
167
|
+
await tool("mDM_publish_keys")({}, bob);
|
|
168
|
+
|
|
169
|
+
// MITM swaps Bob's DH identity key (a SIGNED field) in the directory entry,
|
|
170
|
+
// keeping it valid base64 so it parses — only the signature should catch it.
|
|
171
|
+
const obj = JSON.parse(Buffer.from(backend.bundles.get("bob")!).toString("utf8"));
|
|
172
|
+
obj.ik = (obj.ik[0] === "A" ? "B" : "A") + obj.ik.slice(1);
|
|
173
|
+
backend.bundles.set("bob", new Uint8Array(Buffer.from(JSON.stringify(obj), "utf8")));
|
|
174
|
+
|
|
175
|
+
await expect(tool("mDM_send")({ to: "bob", text: "intercept me" }, alice)).rejects.toThrow(
|
|
176
|
+
/signature verification|man-in-the-middle/i,
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe("auto-publish prekeys on startup (LINEAR-3104 cold-start fix)", () => {
|
|
182
|
+
it("publishes the local prekey bundle when autoPublishKeys is set", async () => {
|
|
183
|
+
const backend = new SharedBackend();
|
|
184
|
+
createMosaddServer({
|
|
185
|
+
mode: "local",
|
|
186
|
+
autoPublishKeys: true,
|
|
187
|
+
providers: {
|
|
188
|
+
dm: new ClientProvider(backend, "self-agent"),
|
|
189
|
+
keys: new InMemoryMdmKeyStore(),
|
|
190
|
+
voice: new InMemoryVoiceProvider("self-agent"),
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
// fire-and-forget; getOwnMaterial() does async key generation, so flush.
|
|
194
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
195
|
+
expect(backend.bundles.has("self-agent")).toBe(true);
|
|
196
|
+
expect(backend.bundles.get("self-agent")!.byteLength).toBeGreaterThan(0);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("does NOT publish when autoPublishKeys is unset (hosted/default)", async () => {
|
|
200
|
+
const backend = new SharedBackend();
|
|
201
|
+
createMosaddServer({
|
|
202
|
+
mode: "local",
|
|
203
|
+
providers: {
|
|
204
|
+
dm: new ClientProvider(backend, "quiet-agent"),
|
|
205
|
+
keys: new InMemoryMdmKeyStore(),
|
|
206
|
+
voice: new InMemoryVoiceProvider("quiet-agent"),
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
210
|
+
expect(backend.bundles.has("quiet-agent")).toBe(false);
|
|
211
|
+
});
|
|
212
|
+
});
|
|
@@ -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,71 @@
|
|
|
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
|
-
//
|
|
19
|
-
|
|
20
|
-
expect(names).toContain("
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
expect(names).
|
|
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
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
expect(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
+
// mURL (revived module) + mAYL (email 3.0, was mp0st) — threat_* re-registered (LINEAR-3498)
|
|
19
|
+
// (surveillance-era direction killed 2026-06-27; on-device security pillar, not an MCP tool)
|
|
20
|
+
expect(names).toContain("mURL_post");
|
|
21
|
+
expect(names).toContain("mAYL_send");
|
|
22
|
+
// mp0st_* aliases RETIRED 2026-07-15 — mAYL is the one name (mp0st is backend-internal only)
|
|
23
|
+
expect(names.some((n) => n.startsWith("mp0st_"))).toBe(false);
|
|
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 mailName = /^mp0st_[a-z][a-z0-9_]*$/; // mail module codename (LINEAR-3464)
|
|
29
|
+
const metaName = /^comms_[a-z][a-z0-9_]*$/; // discovery/meta namespace
|
|
30
|
+
const threatName = /^threat_[a-z][a-z0-9_]*$/; // defensive threat engine (LINEAR-3498)
|
|
31
|
+
for (const tool of allTools) {
|
|
32
|
+
expect(tool.name).toMatch(
|
|
33
|
+
new RegExp(`${channelName.source}|${mailName.source}|${metaName.source}|${threatName.source}`),
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("every tool declares a transport requirement (any | radio | network)", () => {
|
|
39
|
+
for (const tool of allTools) {
|
|
40
|
+
expect(["any", "radio", "network"]).toContain(tool.requires);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("every tool ships a description and a Zod schema", () => {
|
|
45
|
+
for (const tool of allTools) {
|
|
46
|
+
expect(typeof tool.description).toBe("string");
|
|
47
|
+
expect(tool.description.length).toBeGreaterThan(20);
|
|
48
|
+
expect(tool.inputSchema).toBeDefined();
|
|
49
|
+
// Zod schemas have _def
|
|
50
|
+
expect((tool.inputSchema as { _def?: unknown })._def).toBeDefined();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe("createMosaddServer", () => {
|
|
56
|
+
it("constructs without throwing in local mode", () => {
|
|
57
|
+
const server = createMosaddServer({ mode: "local", logLevel: "error" });
|
|
58
|
+
expect(server).toBeDefined();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("defaults to local mode when no apiKey", () => {
|
|
62
|
+
const server = createMosaddServer({ logLevel: "error" });
|
|
63
|
+
expect(server).toBeDefined();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("accepts cloud mode with apiKey", () => {
|
|
67
|
+
const server = createMosaddServer({ apiKey: "test", logLevel: "error" });
|
|
68
|
+
expect(server).toBeDefined();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|