@mosadd/mcp 3.0.0-alpha.55 → 3.0.0-alpha.57

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 (54) hide show
  1. package/CHANGELOG.md +15 -11
  2. package/README.md +152 -150
  3. package/dist/bin/mcp.js +1 -1
  4. package/dist/{chunk-IWUGKLDX.js → chunk-WEGSITAH.js} +30 -14
  5. package/dist/index.js +1 -1
  6. package/package.json +2 -2
  7. package/src/__tests__/blob-upload.test.ts +93 -93
  8. package/src/__tests__/channel-e2ee.test.ts +62 -62
  9. package/src/__tests__/flota-jawnie.test.ts +2 -2
  10. package/src/__tests__/golden-path.test.ts +139 -139
  11. package/src/__tests__/integration.test.ts +217 -182
  12. package/src/__tests__/label-room-owner.test.ts +22 -0
  13. package/src/__tests__/mdm-e2ee.test.ts +212 -212
  14. package/src/__tests__/mdm-mcp-readable.test.ts +390 -390
  15. package/src/__tests__/mirc-invite.test.ts +112 -112
  16. package/src/__tests__/mtalk.test.ts +122 -122
  17. package/src/__tests__/presence.test.ts +199 -199
  18. package/src/__tests__/server.test.ts +71 -71
  19. package/src/__tests__/tool-count-consistency.test.ts +259 -199
  20. package/src/__tests__/voice-fields.test.ts +24 -0
  21. package/src/bin/login.ts +138 -138
  22. package/src/bin/mcp.ts +145 -145
  23. package/src/config.ts +66 -66
  24. package/src/crypto/channel-e2ee.ts +288 -288
  25. package/src/crypto/mdm-session.ts +842 -842
  26. package/src/index.ts +19 -19
  27. package/src/observability/sentry.ts +79 -79
  28. package/src/providers/blob-upload.ts +162 -162
  29. package/src/providers/memory-voice.ts +79 -79
  30. package/src/providers/supabase-dm.ts +212 -202
  31. package/src/providers/supabase-voice.ts +103 -91
  32. package/src/server.ts +195 -195
  33. package/src/tools/actions.ts +166 -166
  34. package/src/tools/attachments.ts +276 -276
  35. package/src/tools/capabilities.ts +70 -70
  36. package/src/tools/channel-payload.ts +2 -2
  37. package/src/tools/embed.ts +110 -110
  38. package/src/tools/index.ts +181 -181
  39. package/src/tools/knowledge.ts +344 -344
  40. package/src/tools/mail-aliases.ts +25 -25
  41. package/src/tools/mail-provenance.ts +137 -137
  42. package/src/tools/mail.ts +403 -403
  43. package/src/tools/mdm-as-agent.ts +138 -126
  44. package/src/tools/mdm.ts +6 -4
  45. package/src/tools/mirc-edge.ts +196 -196
  46. package/src/tools/mirc-members.ts +287 -287
  47. package/src/tools/mirc-messages.ts +1 -1
  48. package/src/tools/mirc.ts +308 -308
  49. package/src/tools/mroom.ts +221 -221
  50. package/src/tools/mtalk.ts +131 -131
  51. package/src/tools/presence.ts +442 -442
  52. package/src/tools/voice-format.ts +43 -28
  53. package/src/types.ts +121 -121
  54. package/src/voice/floor.ts +132 -132
@@ -1,182 +1,217 @@
1
- /**
2
- * Integration test — spawns the actual mcp binary as a child process,
3
- * sends JSON-RPC over stdin, validates JSON-RPC responses on stdout.
4
- *
5
- * Catches regressions like the ZodObject.shape vs ._def.shape() incident
6
- * (commit c237e86) that unit tests against allTools wouldn't have caught —
7
- * the bug only surfaces when the MCP SDK's `McpServer.tool(...)` rejects
8
- * the schema we pass.
9
- */
10
-
11
- import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";
12
- import { join } from "node:path";
13
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
14
-
15
- const MCP_BIN = join(__dirname, "..", "..", "dist", "bin", "mcp.js");
16
-
17
- interface JsonRpcMessage {
18
- jsonrpc: "2.0";
19
- id?: number | string;
20
- method?: string;
21
- params?: unknown;
22
- result?: unknown;
23
- error?: { code: number; message: string };
24
- }
25
-
26
- class McpClient {
27
- private proc!: ChildProcessWithoutNullStreams;
28
- private buffer = "";
29
- private resolvers = new Map<number | string, (msg: JsonRpcMessage) => void>();
30
- private nextId = 1;
31
-
32
- async start(): Promise<void> {
33
- this.proc = spawn("node", [MCP_BIN], { stdio: ["pipe", "pipe", "pipe"] });
34
-
35
- this.proc.stdout.on("data", (chunk: Buffer) => {
36
- this.buffer += chunk.toString("utf8");
37
- let nl = this.buffer.indexOf("\n");
38
- while (nl !== -1) {
39
- const line = this.buffer.slice(0, nl).trim();
40
- this.buffer = this.buffer.slice(nl + 1);
41
- if (line) {
42
- try {
43
- const msg = JSON.parse(line) as JsonRpcMessage;
44
- if (msg.id !== undefined) {
45
- const resolve = this.resolvers.get(msg.id);
46
- if (resolve) {
47
- this.resolvers.delete(msg.id);
48
- resolve(msg);
49
- }
50
- }
51
- } catch {
52
- // server log lines on stderr only; stdout is always JSON-RPC
53
- }
54
- }
55
- nl = this.buffer.indexOf("\n");
56
- }
57
- });
58
-
59
- // Wait briefly for the server to be ready (writes a single info log to stderr).
60
- await new Promise<void>((resolve) => {
61
- const onData = (chunk: Buffer) => {
62
- if (chunk.toString("utf8").includes("ready")) {
63
- this.proc.stderr.off("data", onData);
64
- resolve();
65
- }
66
- };
67
- this.proc.stderr.on("data", onData);
68
- setTimeout(resolve, 2000); // hard cap
69
- });
70
- }
71
-
72
- async stop(): Promise<void> {
73
- this.proc.kill();
74
- await new Promise<void>((resolve) => this.proc.on("close", () => resolve()));
75
- }
76
-
77
- async send(method: string, params?: unknown, timeoutMs = 5000): Promise<JsonRpcMessage> {
78
- const id = this.nextId++;
79
- const req: JsonRpcMessage = { jsonrpc: "2.0", id, method, params };
80
- return new Promise((resolve, reject) => {
81
- const timer = setTimeout(() => {
82
- this.resolvers.delete(id);
83
- reject(new Error(`MCP request ${method} (id=${id}) timed out after ${timeoutMs}ms`));
84
- }, timeoutMs);
85
- this.resolvers.set(id, (msg) => {
86
- clearTimeout(timer);
87
- resolve(msg);
88
- });
89
- this.proc.stdin.write(JSON.stringify(req) + "\n");
90
- });
91
- }
92
- }
93
-
94
- describe("@mosadd/mcp — integration (real stdio)", () => {
95
- let client: McpClient;
96
-
97
- beforeEach(async () => {
98
- client = new McpClient();
99
- await client.start();
100
- });
101
-
102
- afterEach(async () => {
103
- await client.stop();
104
- });
105
-
106
- it("responds to initialize handshake", async () => {
107
- const resp = await client.send("initialize", {
108
- protocolVersion: "2024-11-05",
109
- capabilities: {},
110
- clientInfo: { name: "vitest", version: "1.0" },
111
- });
112
-
113
- expect(resp.error).toBeUndefined();
114
- const result = resp.result as {
115
- protocolVersion?: string;
116
- capabilities?: { tools?: unknown };
117
- serverInfo?: { name?: string };
118
- };
119
- expect(result.protocolVersion).toBe("2024-11-05");
120
- expect(result.capabilities?.tools).toBeDefined();
121
- expect(result.serverInfo?.name).toBe("mosadd");
122
- });
123
-
124
- it("lists all channel tools on tools/list", async () => {
125
- await client.send("initialize", {
126
- protocolVersion: "2024-11-05",
127
- capabilities: {},
128
- clientInfo: { name: "vitest", version: "1.0" },
129
- });
130
-
131
- const resp = await client.send("tools/list");
132
-
133
- expect(resp.error).toBeUndefined();
134
- const result = resp.result as { tools?: Array<{ name: string }> };
135
- const names = result.tools?.map((t) => t.name) ?? [];
136
-
137
- // All live channels surface their tools
138
- expect(names).toContain("mDM_send");
139
- expect(names).toContain("mIRC_create");
140
- expect(names).toContain("mURL_post"); // mURL revived module (2026-06-27)
141
- expect(names).toContain("mAYL_send"); // mAYL = email 3.0 (was mp0st); threat_catalog/threat_classify ARE registered (LINEAR-3498)
142
- expect(names).not.toContain("mp0st_send"); // mp0st_* aliases RETIRED 2026-07-15 — mAYL only
143
- expect(names).toContain("mTALK_press"); // mTALK PTT now shipped
144
- expect(names).toContain("mRAG_search"); // mRAG RAG-for-devs now shipped
145
- expect(names).toContain("mIRC_post_message"); // channel messaging now shipped
146
-
147
- // Total tool count today (grows as modules ship)
148
- expect(names.length).toBeGreaterThanOrEqual(40);
149
-
150
- // Every tool has a valid JSON Schema
151
- for (const tool of result.tools ?? []) {
152
- const t = tool as { name: string; description: string; inputSchema: { type?: string } };
153
- expect(t.description).toBeTruthy();
154
- expect(t.inputSchema?.type).toBe("object");
155
- }
156
- });
157
-
158
- it("returns an error envelope (not crash) when a tool handler throws", async () => {
159
- await client.send("initialize", {
160
- protocolVersion: "2024-11-05",
161
- capabilities: {},
162
- clientInfo: { name: "vitest", version: "1.0" },
163
- });
164
-
165
- // mDM_send to a nonexistent peer MUST fail — but as a normal `isError: true`
166
- // content block, not a JSON-RPC error (that would crash the agent loop).
167
- // The exact message depends on the machine: without credentials it's
168
- // MissingSupabaseEnvError, with a logged-in `mosadd login` session the call
169
- // reaches the real server and fails on the peer's missing prekey bundle.
170
- // Both are the correct envelope; asserting one exact message made the test
171
- // red on any machine with a live session (audyt 2026-08-27).
172
- const resp = await client.send("tools/call", {
173
- name: "mDM_send",
174
- arguments: { to: "11111111-1111-1111-1111-111111111111", text: "hi" },
175
- });
176
-
177
- expect(resp.error).toBeUndefined(); // JSON-RPC level OK
178
- const result = resp.result as { isError?: boolean; content?: Array<{ text?: string }> };
179
- expect(result.isError).toBe(true);
180
- expect(result.content?.[0]?.text ?? "").toMatch(/Missing|error/i);
181
- });
182
- });
1
+ /**
2
+ * Integration test — spawns the actual mcp binary as a child process,
3
+ * sends JSON-RPC over stdin, validates JSON-RPC responses on stdout.
4
+ *
5
+ * Catches regressions like the ZodObject.shape vs ._def.shape() incident
6
+ * (commit c237e86) that unit tests against allTools wouldn't have caught —
7
+ * the bug only surfaces when the MCP SDK's `McpServer.tool(...)` rejects
8
+ * the schema we pass.
9
+ */
10
+
11
+ import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";
12
+ import { mkdtempSync } from "node:fs";
13
+ import { homedir, tmpdir } from "node:os";
14
+ import { join } from "node:path";
15
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
16
+
17
+ const MCP_BIN = join(__dirname, "..", "..", "dist", "bin", "mcp.js");
18
+
19
+ // Every test boots a fresh node process (dist/bin/mcp.js) and waits for it on stdout. On a busy machine (this package's
20
+ // other test files in parallel, the other packages' suites under `pnpm -r test`, antivirus scanning node's module loads)
21
+ // that boot took more than 7 s on 2026-11-14: two of the three tests timed out at 5 s in each of two full runs, and
22
+ // passed in about 2 s each when this file ran alone, and in about 14 s each in a full run that gave them the time.
23
+ // The assertions are unchanged; only how long they may wait is. A server that never answers still fails.
24
+ const REQUEST_TIMEOUT_MS = 45_000;
25
+ vi.setConfig({ testTimeout: 120_000, hookTimeout: 30_000 });
26
+
27
+ /**
28
+ * The child server runs with an EMPTY home and no MOSADD_* variables.
29
+ *
30
+ * Until 2026-09-29 it inherited the developer's environment: on a machine with a `mosadd login` session
31
+ * (~/.mosadd/session.json) the "tool handler throws" case below sent a REAL mDM_send through that account
32
+ * (to 11111111-…, failing only on the missing prekey bundle), so running the suite wrote to production.
33
+ * Sealed, the server finds no credentials and every networked tool stops at MissingSupabaseEnvError.
34
+ */
35
+ export function sealedEnv(parent: NodeJS.ProcessEnv = process.env): NodeJS.ProcessEnv {
36
+ const home = mkdtempSync(join(tmpdir(), "mosadd-mcp-it-"));
37
+ const env: NodeJS.ProcessEnv = {};
38
+ for (const [k, v] of Object.entries(parent)) if (!/^(MOSADD_|SUPABASE_)/i.test(k)) env[k] = v;
39
+ return { ...env, HOME: home, USERPROFILE: home, HOMEDRIVE: "", HOMEPATH: "" };
40
+ }
41
+
42
+ interface JsonRpcMessage {
43
+ jsonrpc: "2.0";
44
+ id?: number | string;
45
+ method?: string;
46
+ params?: unknown;
47
+ result?: unknown;
48
+ error?: { code: number; message: string };
49
+ }
50
+
51
+ class McpClient {
52
+ private proc!: ChildProcessWithoutNullStreams;
53
+ private buffer = "";
54
+ private resolvers = new Map<number | string, (msg: JsonRpcMessage) => void>();
55
+ private nextId = 1;
56
+
57
+ async start(): Promise<void> {
58
+ this.proc = spawn("node", [MCP_BIN], { stdio: ["pipe", "pipe", "pipe"], env: sealedEnv() });
59
+
60
+ this.proc.stdout.on("data", (chunk: Buffer) => {
61
+ this.buffer += chunk.toString("utf8");
62
+ let nl = this.buffer.indexOf("\n");
63
+ while (nl !== -1) {
64
+ const line = this.buffer.slice(0, nl).trim();
65
+ this.buffer = this.buffer.slice(nl + 1);
66
+ if (line) {
67
+ try {
68
+ const msg = JSON.parse(line) as JsonRpcMessage;
69
+ if (msg.id !== undefined) {
70
+ const resolve = this.resolvers.get(msg.id);
71
+ if (resolve) {
72
+ this.resolvers.delete(msg.id);
73
+ resolve(msg);
74
+ }
75
+ }
76
+ } catch {
77
+ // server log lines on stderr only; stdout is always JSON-RPC
78
+ }
79
+ }
80
+ nl = this.buffer.indexOf("\n");
81
+ }
82
+ });
83
+
84
+ // Wait briefly for the server to be ready (writes a single info log to stderr).
85
+ await new Promise<void>((resolve) => {
86
+ const onData = (chunk: Buffer) => {
87
+ if (chunk.toString("utf8").includes("ready")) {
88
+ this.proc.stderr.off("data", onData);
89
+ resolve();
90
+ }
91
+ };
92
+ this.proc.stderr.on("data", onData);
93
+ setTimeout(resolve, 2000); // hard cap
94
+ });
95
+ }
96
+
97
+ async stop(): Promise<void> {
98
+ this.proc.kill();
99
+ await new Promise<void>((resolve) => this.proc.on("close", () => resolve()));
100
+ }
101
+
102
+ async send(method: string, params?: unknown, timeoutMs = REQUEST_TIMEOUT_MS): Promise<JsonRpcMessage> {
103
+ const id = this.nextId++;
104
+ const req: JsonRpcMessage = { jsonrpc: "2.0", id, method, params };
105
+ return new Promise((resolve, reject) => {
106
+ const timer = setTimeout(() => {
107
+ this.resolvers.delete(id);
108
+ reject(new Error(`MCP request ${method} (id=${id}) timed out after ${timeoutMs}ms`));
109
+ }, timeoutMs);
110
+ this.resolvers.set(id, (msg) => {
111
+ clearTimeout(timer);
112
+ resolve(msg);
113
+ });
114
+ this.proc.stdin.write(JSON.stringify(req) + "\n");
115
+ });
116
+ }
117
+ }
118
+
119
+ describe("integration child environment (no real session, no real messages)", () => {
120
+ it("is sealed: no MOSADD_*/SUPABASE_* variable and a home that is not the developer's", () => {
121
+ const env = sealedEnv({ ...process.env, MOSADD_API_KEY: "mosadd_sk_live_x", MOSADD_USER_JWT: "jwt", SUPABASE_URL: "https://x", PATH: "p" });
122
+ expect(Object.keys(env).filter((k) => /^(MOSADD_|SUPABASE_)/i.test(k))).toEqual([]);
123
+ expect(env.PATH).toBe("p");
124
+ for (const k of ["HOME", "USERPROFILE"] as const) {
125
+ expect(env[k]).toBeTruthy();
126
+ expect(env[k]).not.toBe(homedir());
127
+ expect(env[k]!.startsWith(tmpdir())).toBe(true);
128
+ }
129
+ });
130
+ });
131
+
132
+ describe("@mosadd/mcp — integration (real stdio)", () => {
133
+ let client: McpClient;
134
+
135
+ beforeEach(async () => {
136
+ client = new McpClient();
137
+ await client.start();
138
+ });
139
+
140
+ afterEach(async () => {
141
+ await client.stop();
142
+ });
143
+
144
+ it("responds to initialize handshake", async () => {
145
+ const resp = await client.send("initialize", {
146
+ protocolVersion: "2024-11-05",
147
+ capabilities: {},
148
+ clientInfo: { name: "vitest", version: "1.0" },
149
+ });
150
+
151
+ expect(resp.error).toBeUndefined();
152
+ const result = resp.result as {
153
+ protocolVersion?: string;
154
+ capabilities?: { tools?: unknown };
155
+ serverInfo?: { name?: string };
156
+ };
157
+ expect(result.protocolVersion).toBe("2024-11-05");
158
+ expect(result.capabilities?.tools).toBeDefined();
159
+ expect(result.serverInfo?.name).toBe("mosadd");
160
+ });
161
+
162
+ it("lists all channel tools on tools/list", async () => {
163
+ await client.send("initialize", {
164
+ protocolVersion: "2024-11-05",
165
+ capabilities: {},
166
+ clientInfo: { name: "vitest", version: "1.0" },
167
+ });
168
+
169
+ const resp = await client.send("tools/list");
170
+
171
+ expect(resp.error).toBeUndefined();
172
+ const result = resp.result as { tools?: Array<{ name: string }> };
173
+ const names = result.tools?.map((t) => t.name) ?? [];
174
+
175
+ // All live channels surface their tools
176
+ expect(names).toContain("mDM_send");
177
+ expect(names).toContain("mIRC_create");
178
+ expect(names).toContain("mURL_post"); // mURL revived module (2026-06-27)
179
+ expect(names).toContain("mAYL_send"); // mAYL = email 3.0 (was mp0st); threat_catalog/threat_classify ARE registered (LINEAR-3498)
180
+ expect(names).not.toContain("mp0st_send"); // mp0st_* aliases RETIRED 2026-07-15 — mAYL only
181
+ expect(names).toContain("mTALK_press"); // mTALK PTT now shipped
182
+ expect(names).toContain("mRAG_search"); // mRAG RAG-for-devs now shipped
183
+ expect(names).toContain("mIRC_post_message"); // channel messaging now shipped
184
+
185
+ // Total tool count today (grows as modules ship)
186
+ expect(names.length).toBeGreaterThanOrEqual(40);
187
+
188
+ // Every tool has a valid JSON Schema
189
+ for (const tool of result.tools ?? []) {
190
+ const t = tool as { name: string; description: string; inputSchema: { type?: string } };
191
+ expect(t.description).toBeTruthy();
192
+ expect(t.inputSchema?.type).toBe("object");
193
+ }
194
+ });
195
+
196
+ it("returns an error envelope (not crash) when a tool handler throws", async () => {
197
+ await client.send("initialize", {
198
+ protocolVersion: "2024-11-05",
199
+ capabilities: {},
200
+ clientInfo: { name: "vitest", version: "1.0" },
201
+ });
202
+
203
+ // mDM_send to a nonexistent peer MUST fail — but as a normal `isError: true`
204
+ // content block, not a JSON-RPC error (that would crash the agent loop).
205
+ // The child runs sealed (sealedEnv), so it has no credentials on any machine and the
206
+ // call stops at MissingSupabaseEnvError before any network request.
207
+ const resp = await client.send("tools/call", {
208
+ name: "mDM_send",
209
+ arguments: { to: "11111111-1111-1111-1111-111111111111", text: "hi" },
210
+ });
211
+
212
+ expect(resp.error).toBeUndefined(); // JSON-RPC level OK
213
+ const result = resp.result as { isError?: boolean; content?: Array<{ text?: string }> };
214
+ expect(result.isError).toBe(true);
215
+ expect(result.content?.[0]?.text ?? "").toMatch(/Missing/i);
216
+ });
217
+ });
@@ -0,0 +1,22 @@
1
+ // 15.11.2026 — pokój PTT z etykietą ma właściciela w nazwie (bramka: mosADD livekit-token/labelRoom.ts).
2
+ // Było `mosadd-room-<etykieta>`: jedna nazwa dla wszystkich kont, bez właściciela → 403 dla każdego,
3
+ // a wersja „pierwszy wchodzący zajmuje” pozwalała obcemu przejąć pokój.
4
+ import { describe, expect, it } from "vitest";
5
+ import { labelRoomId } from "../providers/supabase-voice.js";
6
+
7
+ const G = "68f326ac-3e8b-468e-9bac-328a930de541";
8
+
9
+ describe("labelRoomId", () => {
10
+ it("etykieta → mosadd-room-<id otwierającego>-<slug>", () => {
11
+ expect(labelRoomId(G, "Field Team")).toBe(`mosadd-room-${G}-field-team`);
12
+ });
13
+ it("bez etykiety → pokój osobisty (goły id, jak dotąd)", () => {
14
+ expect(labelRoomId(G)).toBe(`mosadd-room-${G}`);
15
+ });
16
+ it("dwa konta z tą samą etykietą dostają RÓŻNE pokoje (koniec wspólnej nazwy dla wszystkich)", () => {
17
+ expect(labelRoomId(G, "ops")).not.toBe(labelRoomId("1acbb607-9f66-4074-8295-17c4fb84832c", "ops"));
18
+ });
19
+ it("etykieta z samych znaków specjalnych nie robi z pokoju osobistego", () => {
20
+ expect(labelRoomId(G, "!!!")).toBe(`mosadd-room-${G}-room`);
21
+ });
22
+ });