@mosadd/mcp 3.0.0-alpha.55 → 3.0.0-alpha.56
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 +5 -11
- package/LICENSE +21 -0
- package/README.md +151 -150
- package/dist/bin/mcp.js +1 -1
- package/dist/{chunk-IWUGKLDX.js → chunk-T3KDVUAT.js} +14 -10
- package/dist/index.js +1 -1
- package/package.json +10 -10
- package/src/__tests__/blob-upload.test.ts +93 -93
- package/src/__tests__/channel-e2ee.test.ts +62 -62
- package/src/__tests__/flota-jawnie.test.ts +2 -2
- package/src/__tests__/golden-path.test.ts +139 -139
- package/src/__tests__/integration.test.ts +209 -182
- package/src/__tests__/mdm-e2ee.test.ts +212 -212
- package/src/__tests__/mdm-mcp-readable.test.ts +390 -390
- package/src/__tests__/mirc-invite.test.ts +112 -112
- package/src/__tests__/mtalk.test.ts +122 -122
- package/src/__tests__/presence.test.ts +199 -199
- package/src/__tests__/server.test.ts +71 -71
- package/src/__tests__/tool-count-consistency.test.ts +255 -199
- package/src/bin/login.ts +138 -138
- package/src/bin/mcp.ts +145 -145
- package/src/config.ts +66 -66
- package/src/crypto/channel-e2ee.ts +288 -288
- package/src/crypto/mdm-session.ts +842 -842
- package/src/index.ts +19 -19
- package/src/observability/sentry.ts +79 -79
- package/src/providers/blob-upload.ts +162 -162
- package/src/providers/memory-voice.ts +79 -79
- package/src/providers/supabase-dm.ts +202 -202
- package/src/providers/supabase-voice.ts +91 -91
- package/src/server.ts +195 -195
- package/src/tools/actions.ts +166 -166
- package/src/tools/attachments.ts +276 -276
- package/src/tools/capabilities.ts +70 -70
- package/src/tools/channel-payload.ts +2 -2
- package/src/tools/embed.ts +110 -110
- package/src/tools/index.ts +181 -181
- package/src/tools/knowledge.ts +344 -344
- package/src/tools/mail-aliases.ts +25 -25
- package/src/tools/mail-provenance.ts +137 -137
- package/src/tools/mail.ts +403 -403
- package/src/tools/mdm-as-agent.ts +138 -126
- package/src/tools/mdm.ts +3 -3
- package/src/tools/mirc-edge.ts +196 -196
- package/src/tools/mirc-members.ts +287 -287
- package/src/tools/mirc-messages.ts +1 -1
- package/src/tools/mirc.ts +308 -308
- package/src/tools/mroom.ts +221 -221
- package/src/tools/mtalk.ts +131 -131
- package/src/tools/presence.ts +442 -442
- package/src/tools/voice-format.ts +28 -28
- package/src/types.ts +121 -121
- package/src/voice/floor.ts +132 -132
|
@@ -1,182 +1,209 @@
|
|
|
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 {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
expect(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
//
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
//
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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 } from "vitest";
|
|
16
|
+
|
|
17
|
+
const MCP_BIN = join(__dirname, "..", "..", "dist", "bin", "mcp.js");
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The child server runs with an EMPTY home and no MOSADD_* variables.
|
|
21
|
+
*
|
|
22
|
+
* Until 2026-09-29 it inherited the developer's environment: on a machine with a `mosadd login` session
|
|
23
|
+
* (~/.mosadd/session.json) the "tool handler throws" case below sent a REAL mDM_send through that account
|
|
24
|
+
* (to 11111111-…, failing only on the missing prekey bundle), so running the suite wrote to production.
|
|
25
|
+
* Sealed, the server finds no credentials and every networked tool stops at MissingSupabaseEnvError.
|
|
26
|
+
*/
|
|
27
|
+
export function sealedEnv(parent: NodeJS.ProcessEnv = process.env): NodeJS.ProcessEnv {
|
|
28
|
+
const home = mkdtempSync(join(tmpdir(), "mosadd-mcp-it-"));
|
|
29
|
+
const env: NodeJS.ProcessEnv = {};
|
|
30
|
+
for (const [k, v] of Object.entries(parent)) if (!/^(MOSADD_|SUPABASE_)/i.test(k)) env[k] = v;
|
|
31
|
+
return { ...env, HOME: home, USERPROFILE: home, HOMEDRIVE: "", HOMEPATH: "" };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface JsonRpcMessage {
|
|
35
|
+
jsonrpc: "2.0";
|
|
36
|
+
id?: number | string;
|
|
37
|
+
method?: string;
|
|
38
|
+
params?: unknown;
|
|
39
|
+
result?: unknown;
|
|
40
|
+
error?: { code: number; message: string };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
class McpClient {
|
|
44
|
+
private proc!: ChildProcessWithoutNullStreams;
|
|
45
|
+
private buffer = "";
|
|
46
|
+
private resolvers = new Map<number | string, (msg: JsonRpcMessage) => void>();
|
|
47
|
+
private nextId = 1;
|
|
48
|
+
|
|
49
|
+
async start(): Promise<void> {
|
|
50
|
+
this.proc = spawn("node", [MCP_BIN], { stdio: ["pipe", "pipe", "pipe"], env: sealedEnv() });
|
|
51
|
+
|
|
52
|
+
this.proc.stdout.on("data", (chunk: Buffer) => {
|
|
53
|
+
this.buffer += chunk.toString("utf8");
|
|
54
|
+
let nl = this.buffer.indexOf("\n");
|
|
55
|
+
while (nl !== -1) {
|
|
56
|
+
const line = this.buffer.slice(0, nl).trim();
|
|
57
|
+
this.buffer = this.buffer.slice(nl + 1);
|
|
58
|
+
if (line) {
|
|
59
|
+
try {
|
|
60
|
+
const msg = JSON.parse(line) as JsonRpcMessage;
|
|
61
|
+
if (msg.id !== undefined) {
|
|
62
|
+
const resolve = this.resolvers.get(msg.id);
|
|
63
|
+
if (resolve) {
|
|
64
|
+
this.resolvers.delete(msg.id);
|
|
65
|
+
resolve(msg);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
} catch {
|
|
69
|
+
// server log lines on stderr only; stdout is always JSON-RPC
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
nl = this.buffer.indexOf("\n");
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Wait briefly for the server to be ready (writes a single info log to stderr).
|
|
77
|
+
await new Promise<void>((resolve) => {
|
|
78
|
+
const onData = (chunk: Buffer) => {
|
|
79
|
+
if (chunk.toString("utf8").includes("ready")) {
|
|
80
|
+
this.proc.stderr.off("data", onData);
|
|
81
|
+
resolve();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
this.proc.stderr.on("data", onData);
|
|
85
|
+
setTimeout(resolve, 2000); // hard cap
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async stop(): Promise<void> {
|
|
90
|
+
this.proc.kill();
|
|
91
|
+
await new Promise<void>((resolve) => this.proc.on("close", () => resolve()));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async send(method: string, params?: unknown, timeoutMs = 5000): Promise<JsonRpcMessage> {
|
|
95
|
+
const id = this.nextId++;
|
|
96
|
+
const req: JsonRpcMessage = { jsonrpc: "2.0", id, method, params };
|
|
97
|
+
return new Promise((resolve, reject) => {
|
|
98
|
+
const timer = setTimeout(() => {
|
|
99
|
+
this.resolvers.delete(id);
|
|
100
|
+
reject(new Error(`MCP request ${method} (id=${id}) timed out after ${timeoutMs}ms`));
|
|
101
|
+
}, timeoutMs);
|
|
102
|
+
this.resolvers.set(id, (msg) => {
|
|
103
|
+
clearTimeout(timer);
|
|
104
|
+
resolve(msg);
|
|
105
|
+
});
|
|
106
|
+
this.proc.stdin.write(JSON.stringify(req) + "\n");
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
describe("integration child environment (no real session, no real messages)", () => {
|
|
112
|
+
it("is sealed: no MOSADD_*/SUPABASE_* variable and a home that is not the developer's", () => {
|
|
113
|
+
const env = sealedEnv({ ...process.env, MOSADD_API_KEY: "mosadd_sk_live_x", MOSADD_USER_JWT: "jwt", SUPABASE_URL: "https://x", PATH: "p" });
|
|
114
|
+
expect(Object.keys(env).filter((k) => /^(MOSADD_|SUPABASE_)/i.test(k))).toEqual([]);
|
|
115
|
+
expect(env.PATH).toBe("p");
|
|
116
|
+
for (const k of ["HOME", "USERPROFILE"] as const) {
|
|
117
|
+
expect(env[k]).toBeTruthy();
|
|
118
|
+
expect(env[k]).not.toBe(homedir());
|
|
119
|
+
expect(env[k]!.startsWith(tmpdir())).toBe(true);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe("@mosadd/mcp — integration (real stdio)", () => {
|
|
125
|
+
let client: McpClient;
|
|
126
|
+
|
|
127
|
+
beforeEach(async () => {
|
|
128
|
+
client = new McpClient();
|
|
129
|
+
await client.start();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
afterEach(async () => {
|
|
133
|
+
await client.stop();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("responds to initialize handshake", async () => {
|
|
137
|
+
const resp = await client.send("initialize", {
|
|
138
|
+
protocolVersion: "2024-11-05",
|
|
139
|
+
capabilities: {},
|
|
140
|
+
clientInfo: { name: "vitest", version: "1.0" },
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
expect(resp.error).toBeUndefined();
|
|
144
|
+
const result = resp.result as {
|
|
145
|
+
protocolVersion?: string;
|
|
146
|
+
capabilities?: { tools?: unknown };
|
|
147
|
+
serverInfo?: { name?: string };
|
|
148
|
+
};
|
|
149
|
+
expect(result.protocolVersion).toBe("2024-11-05");
|
|
150
|
+
expect(result.capabilities?.tools).toBeDefined();
|
|
151
|
+
expect(result.serverInfo?.name).toBe("mosadd");
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("lists all channel tools on tools/list", async () => {
|
|
155
|
+
await client.send("initialize", {
|
|
156
|
+
protocolVersion: "2024-11-05",
|
|
157
|
+
capabilities: {},
|
|
158
|
+
clientInfo: { name: "vitest", version: "1.0" },
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const resp = await client.send("tools/list");
|
|
162
|
+
|
|
163
|
+
expect(resp.error).toBeUndefined();
|
|
164
|
+
const result = resp.result as { tools?: Array<{ name: string }> };
|
|
165
|
+
const names = result.tools?.map((t) => t.name) ?? [];
|
|
166
|
+
|
|
167
|
+
// All live channels surface their tools
|
|
168
|
+
expect(names).toContain("mDM_send");
|
|
169
|
+
expect(names).toContain("mIRC_create");
|
|
170
|
+
expect(names).toContain("mURL_post"); // mURL revived module (2026-06-27)
|
|
171
|
+
expect(names).toContain("mAYL_send"); // mAYL = email 3.0 (was mp0st); threat_catalog/threat_classify ARE registered (LINEAR-3498)
|
|
172
|
+
expect(names).not.toContain("mp0st_send"); // mp0st_* aliases RETIRED 2026-07-15 — mAYL only
|
|
173
|
+
expect(names).toContain("mTALK_press"); // mTALK PTT now shipped
|
|
174
|
+
expect(names).toContain("mRAG_search"); // mRAG RAG-for-devs now shipped
|
|
175
|
+
expect(names).toContain("mIRC_post_message"); // channel messaging now shipped
|
|
176
|
+
|
|
177
|
+
// Total tool count today (grows as modules ship)
|
|
178
|
+
expect(names.length).toBeGreaterThanOrEqual(40);
|
|
179
|
+
|
|
180
|
+
// Every tool has a valid JSON Schema
|
|
181
|
+
for (const tool of result.tools ?? []) {
|
|
182
|
+
const t = tool as { name: string; description: string; inputSchema: { type?: string } };
|
|
183
|
+
expect(t.description).toBeTruthy();
|
|
184
|
+
expect(t.inputSchema?.type).toBe("object");
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("returns an error envelope (not crash) when a tool handler throws", async () => {
|
|
189
|
+
await client.send("initialize", {
|
|
190
|
+
protocolVersion: "2024-11-05",
|
|
191
|
+
capabilities: {},
|
|
192
|
+
clientInfo: { name: "vitest", version: "1.0" },
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// mDM_send to a nonexistent peer MUST fail — but as a normal `isError: true`
|
|
196
|
+
// content block, not a JSON-RPC error (that would crash the agent loop).
|
|
197
|
+
// The child runs sealed (sealedEnv), so it has no credentials on any machine and the
|
|
198
|
+
// call stops at MissingSupabaseEnvError before any network request.
|
|
199
|
+
const resp = await client.send("tools/call", {
|
|
200
|
+
name: "mDM_send",
|
|
201
|
+
arguments: { to: "11111111-1111-1111-1111-111111111111", text: "hi" },
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
expect(resp.error).toBeUndefined(); // JSON-RPC level OK
|
|
205
|
+
const result = resp.result as { isError?: boolean; content?: Array<{ text?: string }> };
|
|
206
|
+
expect(result.isError).toBe(true);
|
|
207
|
+
expect(result.content?.[0]?.text ?? "").toMatch(/Missing/i);
|
|
208
|
+
});
|
|
209
|
+
});
|